mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Parse trait alias as a distinct AST type
This commit is contained in:
parent
9b441b9c67
commit
2e7d2c2d04
11 changed files with 103 additions and 10 deletions
|
@ -407,7 +407,21 @@ impl Trait {
|
|||
pub fn auto_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![auto]) }
|
||||
pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) }
|
||||
pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TraitAlias {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::HasAttrs for TraitAlias {}
|
||||
impl ast::HasName for TraitAlias {}
|
||||
impl ast::HasVisibility for TraitAlias {}
|
||||
impl ast::HasGenericParams for TraitAlias {}
|
||||
impl ast::HasDocComments for TraitAlias {}
|
||||
impl TraitAlias {
|
||||
pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) }
|
||||
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
|
||||
pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) }
|
||||
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
|
||||
}
|
||||
|
||||
|
@ -1573,6 +1587,7 @@ pub enum Item {
|
|||
Static(Static),
|
||||
Struct(Struct),
|
||||
Trait(Trait),
|
||||
TraitAlias(TraitAlias),
|
||||
TypeAlias(TypeAlias),
|
||||
Union(Union),
|
||||
Use(Use),
|
||||
|
@ -2058,6 +2073,17 @@ impl AstNode for Trait {
|
|||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for TraitAlias {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == TRAIT_ALIAS }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for TypeAlias {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ALIAS }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -3570,6 +3596,9 @@ impl From<Struct> for Item {
|
|||
impl From<Trait> for Item {
|
||||
fn from(node: Trait) -> Item { Item::Trait(node) }
|
||||
}
|
||||
impl From<TraitAlias> for Item {
|
||||
fn from(node: TraitAlias) -> Item { Item::TraitAlias(node) }
|
||||
}
|
||||
impl From<TypeAlias> for Item {
|
||||
fn from(node: TypeAlias) -> Item { Item::TypeAlias(node) }
|
||||
}
|
||||
|
@ -3596,6 +3625,7 @@ impl AstNode for Item {
|
|||
| STATIC
|
||||
| STRUCT
|
||||
| TRAIT
|
||||
| TRAIT_ALIAS
|
||||
| TYPE_ALIAS
|
||||
| UNION
|
||||
| USE
|
||||
|
@ -3616,6 +3646,7 @@ impl AstNode for Item {
|
|||
STATIC => Item::Static(Static { syntax }),
|
||||
STRUCT => Item::Struct(Struct { syntax }),
|
||||
TRAIT => Item::Trait(Trait { syntax }),
|
||||
TRAIT_ALIAS => Item::TraitAlias(TraitAlias { syntax }),
|
||||
TYPE_ALIAS => Item::TypeAlias(TypeAlias { syntax }),
|
||||
UNION => Item::Union(Union { syntax }),
|
||||
USE => Item::Use(Use { syntax }),
|
||||
|
@ -3638,6 +3669,7 @@ impl AstNode for Item {
|
|||
Item::Static(it) => &it.syntax,
|
||||
Item::Struct(it) => &it.syntax,
|
||||
Item::Trait(it) => &it.syntax,
|
||||
Item::TraitAlias(it) => &it.syntax,
|
||||
Item::TypeAlias(it) => &it.syntax,
|
||||
Item::Union(it) => &it.syntax,
|
||||
Item::Use(it) => &it.syntax,
|
||||
|
@ -3950,6 +3982,7 @@ impl AstNode for AnyHasAttrs {
|
|||
| STATIC
|
||||
| STRUCT
|
||||
| TRAIT
|
||||
| TRAIT_ALIAS
|
||||
| TYPE_ALIAS
|
||||
| UNION
|
||||
| USE
|
||||
|
@ -4035,6 +4068,7 @@ impl AstNode for AnyHasDocComments {
|
|||
| STATIC
|
||||
| STRUCT
|
||||
| TRAIT
|
||||
| TRAIT_ALIAS
|
||||
| TYPE_ALIAS
|
||||
| UNION
|
||||
| USE
|
||||
|
@ -4056,7 +4090,7 @@ impl AnyHasGenericParams {
|
|||
}
|
||||
impl AstNode for AnyHasGenericParams {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
matches!(kind, ENUM | FN | IMPL | STRUCT | TRAIT | TYPE_ALIAS | UNION)
|
||||
matches!(kind, ENUM | FN | IMPL | STRUCT | TRAIT | TRAIT_ALIAS | TYPE_ALIAS | UNION)
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
Self::can_cast(syntax.kind()).then_some(AnyHasGenericParams { syntax })
|
||||
|
@ -4108,6 +4142,7 @@ impl AstNode for AnyHasName {
|
|||
| STATIC
|
||||
| STRUCT
|
||||
| TRAIT
|
||||
| TRAIT_ALIAS
|
||||
| TYPE_ALIAS
|
||||
| UNION
|
||||
| RENAME
|
||||
|
@ -4163,6 +4198,7 @@ impl AstNode for AnyHasVisibility {
|
|||
| STATIC
|
||||
| STRUCT
|
||||
| TRAIT
|
||||
| TRAIT_ALIAS
|
||||
| TYPE_ALIAS
|
||||
| UNION
|
||||
| USE
|
||||
|
@ -4391,6 +4427,11 @@ impl std::fmt::Display for Trait {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for TraitAlias {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for TypeAlias {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue