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:
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user