mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Introduce dedicated AST node for union
Although structs and unions have the same syntax and differ only in the keyword, re-using the single syntax node for both of them leads to confusion in practice, and propagates further down the hir in an upleasent way. Moreover, static and consts also share syntax, but we use different nodes for them.
This commit is contained in:
parent
be00d74c7b
commit
e1c0bdaf75
7 changed files with 63 additions and 15 deletions
|
@ -3789,6 +3789,34 @@ impl AstNode for TypeRef {
|
|||
}
|
||||
impl TypeRef {}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct UnionDef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl AstNode for UnionDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
UNION_DEF => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
}
|
||||
impl ast::VisibilityOwner for UnionDef {}
|
||||
impl ast::NameOwner for UnionDef {}
|
||||
impl ast::TypeParamsOwner for UnionDef {}
|
||||
impl ast::AttrsOwner for UnionDef {}
|
||||
impl ast::DocCommentsOwner for UnionDef {}
|
||||
impl UnionDef {}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct UseItem {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue