From 6636f56e79b55f22b88094b7edaed6ec88880500 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 00:23:03 +0200 Subject: Rename ModuleItem -> Item --- crates/ra_syntax/src/ast/generated/nodes.rs | 788 ++++++++++++++-------------- crates/ra_syntax/src/ast/traits.rs | 2 +- crates/ra_syntax/src/lib.rs | 4 +- crates/ra_syntax/src/tests.rs | 2 +- 4 files changed, 398 insertions(+), 398 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 04a4d354c..3c8bdfcad 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -26,6 +26,57 @@ impl Attr { pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ConstDef { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for ConstDef {} +impl ast::NameOwner for ConstDef {} +impl ast::VisibilityOwner for ConstDef {} +impl ast::TypeAscriptionOwner for ConstDef {} +impl ConstDef { + pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } + pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } + pub fn colon_token(&self) -> Option { support::token(&self.syntax, T![:]) } + pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } + pub fn body(&self) -> Option { support::child(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct EnumDef { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for EnumDef {} +impl ast::NameOwner for EnumDef {} +impl ast::VisibilityOwner for EnumDef {} +impl ast::TypeParamsOwner for EnumDef {} +impl EnumDef { + pub fn enum_token(&self) -> Option { support::token(&self.syntax, T![enum]) } + pub fn variant_list(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ExternBlock { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for ExternBlock {} +impl ExternBlock { + pub fn abi(&self) -> Option { support::child(&self.syntax) } + pub fn extern_item_list(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ExternCrateItem { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for ExternCrateItem {} +impl ast::VisibilityOwner for ExternCrateItem {} +impl ExternCrateItem { + pub fn extern_token(&self) -> Option { support::token(&self.syntax, T![extern]) } + pub fn crate_token(&self) -> Option { support::token(&self.syntax, T![crate]) } + pub fn name_ref(&self) -> Option { support::child(&self.syntax) } + pub fn self_token(&self) -> Option { support::token(&self.syntax, T![self]) } + pub fn alias(&self) -> Option { support::child(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FnDef { pub(crate) syntax: SyntaxNode, } @@ -46,6 +97,131 @@ impl FnDef { pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ImplDef { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for ImplDef {} +impl ast::VisibilityOwner for ImplDef {} +impl ast::TypeParamsOwner for ImplDef {} +impl ImplDef { + pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } + pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } + pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } + pub fn impl_token(&self) -> Option { support::token(&self.syntax, T![impl]) } + pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } + pub fn for_token(&self) -> Option { support::token(&self.syntax, T![for]) } + pub fn item_list(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MacroCall { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for MacroCall {} +impl ast::NameOwner for MacroCall {} +impl MacroCall { + pub fn path(&self) -> Option { support::child(&self.syntax) } + pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } + pub fn token_tree(&self) -> Option { support::child(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Module { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for Module {} +impl ast::NameOwner for Module {} +impl ast::VisibilityOwner for Module {} +impl Module { + pub fn mod_token(&self) -> Option { support::token(&self.syntax, T![mod]) } + pub fn item_list(&self) -> Option { support::child(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct StaticDef { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for StaticDef {} +impl ast::NameOwner for StaticDef {} +impl ast::VisibilityOwner for StaticDef {} +impl ast::TypeAscriptionOwner for StaticDef {} +impl StaticDef { + pub fn static_token(&self) -> Option { support::token(&self.syntax, T![static]) } + pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } + pub fn colon_token(&self) -> Option { support::token(&self.syntax, T![:]) } + pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } + pub fn body(&self) -> Option { support::child(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct StructDef { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for StructDef {} +impl ast::NameOwner for StructDef {} +impl ast::VisibilityOwner for StructDef {} +impl ast::TypeParamsOwner for StructDef {} +impl StructDef { + pub fn struct_token(&self) -> Option { support::token(&self.syntax, T![struct]) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } + pub fn field_def_list(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TraitDef { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for TraitDef {} +impl ast::NameOwner for TraitDef {} +impl ast::VisibilityOwner for TraitDef {} +impl ast::TypeParamsOwner for TraitDef {} +impl ast::TypeBoundsOwner for TraitDef {} +impl TraitDef { + pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } + pub fn auto_token(&self) -> Option { support::token(&self.syntax, T![auto]) } + pub fn trait_token(&self) -> Option { support::token(&self.syntax, T![trait]) } + pub fn item_list(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TypeAliasDef { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for TypeAliasDef {} +impl ast::NameOwner for TypeAliasDef {} +impl ast::VisibilityOwner for TypeAliasDef {} +impl ast::TypeParamsOwner for TypeAliasDef {} +impl ast::TypeBoundsOwner for TypeAliasDef {} +impl TypeAliasDef { + pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } + pub fn type_token(&self) -> Option { support::token(&self.syntax, T![type]) } + pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } + pub fn type_ref(&self) -> Option { support::child(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct UnionDef { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for UnionDef {} +impl ast::NameOwner for UnionDef {} +impl ast::VisibilityOwner for UnionDef {} +impl ast::TypeParamsOwner for UnionDef {} +impl UnionDef { + pub fn union_token(&self) -> Option { support::token(&self.syntax, T![union]) } + pub fn record_field_def_list(&self) -> Option { + support::child(&self.syntax) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct UseItem { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for UseItem {} +impl ast::VisibilityOwner for UseItem {} +impl UseItem { + pub fn use_token(&self) -> Option { support::token(&self.syntax, T![use]) } + pub fn use_tree(&self) -> Option { support::child(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Visibility { pub(crate) syntax: SyntaxNode, } @@ -122,19 +298,6 @@ impl BlockExpr { pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct StructDef { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for StructDef {} -impl ast::NameOwner for StructDef {} -impl ast::VisibilityOwner for StructDef {} -impl ast::TypeParamsOwner for StructDef {} -impl StructDef { - pub fn struct_token(&self) -> Option { support::token(&self.syntax, T![struct]) } - pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } - pub fn field_def_list(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RecordFieldDefList { pub(crate) syntax: SyntaxNode, } @@ -153,20 +316,6 @@ impl TupleFieldDefList { pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct UnionDef { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for UnionDef {} -impl ast::NameOwner for UnionDef {} -impl ast::VisibilityOwner for UnionDef {} -impl ast::TypeParamsOwner for UnionDef {} -impl UnionDef { - pub fn union_token(&self) -> Option { support::token(&self.syntax, T![union]) } - pub fn record_field_def_list(&self) -> Option { - support::child(&self.syntax) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RecordFieldDef { pub(crate) syntax: SyntaxNode, } @@ -188,18 +337,6 @@ impl TupleFieldDef { pub fn type_ref(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct EnumDef { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for EnumDef {} -impl ast::NameOwner for EnumDef {} -impl ast::VisibilityOwner for EnumDef {} -impl ast::TypeParamsOwner for EnumDef {} -impl EnumDef { - pub fn enum_token(&self) -> Option { support::token(&self.syntax, T![enum]) } - pub fn variant_list(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct EnumVariantList { pub(crate) syntax: SyntaxNode, } @@ -221,21 +358,6 @@ impl EnumVariant { pub fn expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TraitDef { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for TraitDef {} -impl ast::NameOwner for TraitDef {} -impl ast::VisibilityOwner for TraitDef {} -impl ast::TypeParamsOwner for TraitDef {} -impl ast::TypeBoundsOwner for TraitDef {} -impl TraitDef { - pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } - pub fn auto_token(&self) -> Option { support::token(&self.syntax, T![auto]) } - pub fn trait_token(&self) -> Option { support::token(&self.syntax, T![trait]) } - pub fn item_list(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TypeBoundList { pub(crate) syntax: SyntaxNode, } @@ -253,82 +375,6 @@ impl ItemList { pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Module { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for Module {} -impl ast::NameOwner for Module {} -impl ast::VisibilityOwner for Module {} -impl Module { - pub fn mod_token(&self) -> Option { support::token(&self.syntax, T![mod]) } - pub fn item_list(&self) -> Option { support::child(&self.syntax) } - pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ConstDef { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for ConstDef {} -impl ast::NameOwner for ConstDef {} -impl ast::VisibilityOwner for ConstDef {} -impl ast::TypeAscriptionOwner for ConstDef {} -impl ConstDef { - pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } - pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } - pub fn colon_token(&self) -> Option { support::token(&self.syntax, T![:]) } - pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } - pub fn body(&self) -> Option { support::child(&self.syntax) } - pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct StaticDef { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for StaticDef {} -impl ast::NameOwner for StaticDef {} -impl ast::VisibilityOwner for StaticDef {} -impl ast::TypeAscriptionOwner for StaticDef {} -impl StaticDef { - pub fn static_token(&self) -> Option { support::token(&self.syntax, T![static]) } - pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } - pub fn colon_token(&self) -> Option { support::token(&self.syntax, T![:]) } - pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } - pub fn body(&self) -> Option { support::child(&self.syntax) } - pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TypeAliasDef { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for TypeAliasDef {} -impl ast::NameOwner for TypeAliasDef {} -impl ast::VisibilityOwner for TypeAliasDef {} -impl ast::TypeParamsOwner for TypeAliasDef {} -impl ast::TypeBoundsOwner for TypeAliasDef {} -impl TypeAliasDef { - pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } - pub fn type_token(&self) -> Option { support::token(&self.syntax, T![type]) } - pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } - pub fn type_ref(&self) -> Option { support::child(&self.syntax) } - pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ImplDef { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for ImplDef {} -impl ast::VisibilityOwner for ImplDef {} -impl ast::TypeParamsOwner for ImplDef {} -impl ImplDef { - pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } - pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } - pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } - pub fn impl_token(&self) -> Option { support::token(&self.syntax, T![impl]) } - pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } - pub fn for_token(&self) -> Option { support::token(&self.syntax, T![for]) } - pub fn item_list(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ParenType { pub(crate) syntax: SyntaxNode, } @@ -920,18 +966,6 @@ impl MacroPat { pub fn macro_call(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MacroCall { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for MacroCall {} -impl ast::NameOwner for MacroCall {} -impl MacroCall { - pub fn path(&self) -> Option { support::child(&self.syntax) } - pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } - pub fn token_tree(&self) -> Option { support::child(&self.syntax) } - pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RecordPat { pub(crate) syntax: SyntaxNode, } @@ -1125,17 +1159,6 @@ impl Param { pub fn dotdotdot_token(&self) -> Option { support::token(&self.syntax, T![...]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct UseItem { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for UseItem {} -impl ast::VisibilityOwner for UseItem {} -impl UseItem { - pub fn use_token(&self) -> Option { support::token(&self.syntax, T![use]) } - pub fn use_tree(&self) -> Option { support::child(&self.syntax) } - pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct UseTree { pub(crate) syntax: SyntaxNode, } @@ -1164,20 +1187,6 @@ impl Alias { pub fn as_token(&self) -> Option { support::token(&self.syntax, T![as]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ExternCrateItem { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for ExternCrateItem {} -impl ast::VisibilityOwner for ExternCrateItem {} -impl ExternCrateItem { - pub fn extern_token(&self) -> Option { support::token(&self.syntax, T![extern]) } - pub fn crate_token(&self) -> Option { support::token(&self.syntax, T![crate]) } - pub fn name_ref(&self) -> Option { support::child(&self.syntax) } - pub fn self_token(&self) -> Option { support::token(&self.syntax, T![self]) } - pub fn alias(&self) -> Option { support::child(&self.syntax) } - pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PathSegment { pub(crate) syntax: SyntaxNode, } @@ -1229,15 +1238,6 @@ impl ConstArg { pub fn block_expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ExternBlock { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for ExternBlock {} -impl ExternBlock { - pub fn abi(&self) -> Option { support::child(&self.syntax) } - pub fn extern_item_list(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ExternItemList { pub(crate) syntax: SyntaxNode, } @@ -1257,23 +1257,23 @@ impl MetaItem { pub fn nested_meta_items(&self) -> AstChildren { support::children(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum ModuleItem { - StructDef(StructDef), - UnionDef(UnionDef), +pub enum Item { + ConstDef(ConstDef), EnumDef(EnumDef), + ExternBlock(ExternBlock), + ExternCrateItem(ExternCrateItem), FnDef(FnDef), + ImplDef(ImplDef), + MacroCall(MacroCall), + Module(Module), + StaticDef(StaticDef), + StructDef(StructDef), TraitDef(TraitDef), TypeAliasDef(TypeAliasDef), - ImplDef(ImplDef), + UnionDef(UnionDef), UseItem(UseItem), - ExternCrateItem(ExternCrateItem), - ConstDef(ConstDef), - StaticDef(StaticDef), - Module(Module), - MacroCall(MacroCall), - ExternBlock(ExternBlock), } -impl ast::AttrsOwner for ModuleItem {} +impl ast::AttrsOwner for Item {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum TypeRef { ParenType(ParenType), @@ -1381,12 +1381,45 @@ pub enum AdtDef { EnumDef(EnumDef), UnionDef(UnionDef), } -impl ast::AttrsOwner for AdtDef {} -impl ast::NameOwner for AdtDef {} -impl ast::TypeParamsOwner for AdtDef {} -impl ast::VisibilityOwner for AdtDef {} -impl AstNode for SourceFile { - fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } +impl ast::AttrsOwner for AdtDef {} +impl ast::NameOwner for AdtDef {} +impl ast::TypeParamsOwner for AdtDef {} +impl ast::VisibilityOwner for AdtDef {} +impl AstNode for SourceFile { + fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for Attr { + fn can_cast(kind: SyntaxKind) -> bool { kind == ATTR } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for ConstDef { + fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_DEF } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for EnumDef { + fn can_cast(kind: SyntaxKind) -> bool { kind == ENUM_DEF } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1396,8 +1429,19 @@ impl AstNode for SourceFile { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Attr { - fn can_cast(kind: SyntaxKind) -> bool { kind == ATTR } +impl AstNode for ExternBlock { + fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_BLOCK } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for ExternCrateItem { + fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_CRATE_ITEM } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1418,8 +1462,8 @@ impl AstNode for FnDef { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Visibility { - fn can_cast(kind: SyntaxKind) -> bool { kind == VISIBILITY } +impl AstNode for ImplDef { + fn can_cast(kind: SyntaxKind) -> bool { kind == IMPL_DEF } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1429,8 +1473,8 @@ impl AstNode for Visibility { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Abi { - fn can_cast(kind: SyntaxKind) -> bool { kind == ABI } +impl AstNode for MacroCall { + fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1440,8 +1484,8 @@ impl AstNode for Abi { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Name { - fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } +impl AstNode for Module { + fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1451,8 +1495,8 @@ impl AstNode for Name { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TypeParamList { - fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_PARAM_LIST } +impl AstNode for StaticDef { + fn can_cast(kind: SyntaxKind) -> bool { kind == STATIC_DEF } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1462,8 +1506,8 @@ impl AstNode for TypeParamList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for ParamList { - fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST } +impl AstNode for StructDef { + fn can_cast(kind: SyntaxKind) -> bool { kind == STRUCT_DEF } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1473,8 +1517,8 @@ impl AstNode for ParamList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for RetType { - fn can_cast(kind: SyntaxKind) -> bool { kind == RET_TYPE } +impl AstNode for TraitDef { + fn can_cast(kind: SyntaxKind) -> bool { kind == TRAIT_DEF } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1484,8 +1528,8 @@ impl AstNode for RetType { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for WhereClause { - fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_CLAUSE } +impl AstNode for TypeAliasDef { + fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ALIAS_DEF } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1495,8 +1539,8 @@ impl AstNode for WhereClause { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for BlockExpr { - fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR } +impl AstNode for UnionDef { + fn can_cast(kind: SyntaxKind) -> bool { kind == UNION_DEF } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1506,8 +1550,8 @@ impl AstNode for BlockExpr { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for StructDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == STRUCT_DEF } +impl AstNode for UseItem { + fn can_cast(kind: SyntaxKind) -> bool { kind == USE_ITEM } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1517,8 +1561,8 @@ impl AstNode for StructDef { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for RecordFieldDefList { - fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST } +impl AstNode for Visibility { + fn can_cast(kind: SyntaxKind) -> bool { kind == VISIBILITY } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1528,8 +1572,8 @@ impl AstNode for RecordFieldDefList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TupleFieldDefList { - fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_DEF_LIST } +impl AstNode for Abi { + fn can_cast(kind: SyntaxKind) -> bool { kind == ABI } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1539,8 +1583,8 @@ impl AstNode for TupleFieldDefList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for UnionDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == UNION_DEF } +impl AstNode for Name { + fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1550,8 +1594,8 @@ impl AstNode for UnionDef { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for RecordFieldDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF } +impl AstNode for TypeParamList { + fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_PARAM_LIST } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1561,8 +1605,8 @@ impl AstNode for RecordFieldDef { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TupleFieldDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_DEF } +impl AstNode for ParamList { + fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1572,8 +1616,8 @@ impl AstNode for TupleFieldDef { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for EnumDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == ENUM_DEF } +impl AstNode for RetType { + fn can_cast(kind: SyntaxKind) -> bool { kind == RET_TYPE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1583,8 +1627,8 @@ impl AstNode for EnumDef { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for EnumVariantList { - fn can_cast(kind: SyntaxKind) -> bool { kind == ENUM_VARIANT_LIST } +impl AstNode for WhereClause { + fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_CLAUSE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1594,8 +1638,8 @@ impl AstNode for EnumVariantList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for EnumVariant { - fn can_cast(kind: SyntaxKind) -> bool { kind == ENUM_VARIANT } +impl AstNode for BlockExpr { + fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1605,8 +1649,8 @@ impl AstNode for EnumVariant { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TraitDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == TRAIT_DEF } +impl AstNode for RecordFieldDefList { + fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1616,8 +1660,8 @@ impl AstNode for TraitDef { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TypeBoundList { - fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST } +impl AstNode for TupleFieldDefList { + fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_DEF_LIST } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1627,8 +1671,8 @@ impl AstNode for TypeBoundList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for ItemList { - fn can_cast(kind: SyntaxKind) -> bool { kind == ITEM_LIST } +impl AstNode for RecordFieldDef { + fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1638,8 +1682,8 @@ impl AstNode for ItemList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Module { - fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } +impl AstNode for TupleFieldDef { + fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_DEF } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1649,8 +1693,8 @@ impl AstNode for Module { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for ConstDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_DEF } +impl AstNode for EnumVariantList { + fn can_cast(kind: SyntaxKind) -> bool { kind == ENUM_VARIANT_LIST } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1660,8 +1704,8 @@ impl AstNode for ConstDef { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for StaticDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == STATIC_DEF } +impl AstNode for EnumVariant { + fn can_cast(kind: SyntaxKind) -> bool { kind == ENUM_VARIANT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1671,8 +1715,8 @@ impl AstNode for StaticDef { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TypeAliasDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ALIAS_DEF } +impl AstNode for TypeBoundList { + fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1682,8 +1726,8 @@ impl AstNode for TypeAliasDef { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for ImplDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == IMPL_DEF } +impl AstNode for ItemList { + fn can_cast(kind: SyntaxKind) -> bool { kind == ITEM_LIST } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2397,17 +2441,6 @@ impl AstNode for MacroPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for MacroCall { - fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for RecordPat { fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT } fn cast(syntax: SyntaxNode) -> Option { @@ -2606,17 +2639,6 @@ impl AstNode for Param { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for UseItem { - fn can_cast(kind: SyntaxKind) -> bool { kind == USE_ITEM } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for UseTree { fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE } fn cast(syntax: SyntaxNode) -> Option { @@ -2650,17 +2672,6 @@ impl AstNode for Alias { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for ExternCrateItem { - fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_CRATE_ITEM } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for PathSegment { fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT } fn cast(syntax: SyntaxNode) -> Option { @@ -2716,17 +2727,6 @@ impl AstNode for ConstArg { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for ExternBlock { - fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_BLOCK } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for ExternItemList { fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_LIST } fn cast(syntax: SyntaxNode) -> Option { @@ -2749,93 +2749,93 @@ impl AstNode for MetaItem { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl From for ModuleItem { - fn from(node: StructDef) -> ModuleItem { ModuleItem::StructDef(node) } +impl From for Item { + fn from(node: ConstDef) -> Item { Item::ConstDef(node) } } -impl From for ModuleItem { - fn from(node: UnionDef) -> ModuleItem { ModuleItem::UnionDef(node) } +impl From for Item { + fn from(node: EnumDef) -> Item { Item::EnumDef(node) } } -impl From for ModuleItem { - fn from(node: EnumDef) -> ModuleItem { ModuleItem::EnumDef(node) } +impl From for Item { + fn from(node: ExternBlock) -> Item { Item::ExternBlock(node) } } -impl From for ModuleItem { - fn from(node: FnDef) -> ModuleItem { ModuleItem::FnDef(node) } +impl From for Item { + fn from(node: ExternCrateItem) -> Item { Item::ExternCrateItem(node) } } -impl From for ModuleItem { - fn from(node: TraitDef) -> ModuleItem { ModuleItem::TraitDef(node) } +impl From for Item { + fn from(node: FnDef) -> Item { Item::FnDef(node) } } -impl From for ModuleItem { - fn from(node: TypeAliasDef) -> ModuleItem { ModuleItem::TypeAliasDef(node) } +impl From for Item { + fn from(node: ImplDef) -> Item { Item::ImplDef(node) } } -impl From for ModuleItem { - fn from(node: ImplDef) -> ModuleItem { ModuleItem::ImplDef(node) } +impl From for Item { + fn from(node: MacroCall) -> Item { Item::MacroCall(node) } } -impl From for ModuleItem { - fn from(node: UseItem) -> ModuleItem { ModuleItem::UseItem(node) } +impl From for Item { + fn from(node: Module) -> Item { Item::Module(node) } } -impl From for ModuleItem { - fn from(node: ExternCrateItem) -> ModuleItem { ModuleItem::ExternCrateItem(node) } +impl From for Item { + fn from(node: StaticDef) -> Item { Item::StaticDef(node) } } -impl From for ModuleItem { - fn from(node: ConstDef) -> ModuleItem { ModuleItem::ConstDef(node) } +impl From for Item { + fn from(node: StructDef) -> Item { Item::StructDef(node) } } -impl From for ModuleItem { - fn from(node: StaticDef) -> ModuleItem { ModuleItem::StaticDef(node) } +impl From for Item { + fn from(node: TraitDef) -> Item { Item::TraitDef(node) } } -impl From for ModuleItem { - fn from(node: Module) -> ModuleItem { ModuleItem::Module(node) } +impl From for Item { + fn from(node: TypeAliasDef) -> Item { Item::TypeAliasDef(node) } } -impl From for ModuleItem { - fn from(node: MacroCall) -> ModuleItem { ModuleItem::MacroCall(node) } +impl From for Item { + fn from(node: UnionDef) -> Item { Item::UnionDef(node) } } -impl From for ModuleItem { - fn from(node: ExternBlock) -> ModuleItem { ModuleItem::ExternBlock(node) } +impl From for Item { + fn from(node: UseItem) -> Item { Item::UseItem(node) } } -impl AstNode for ModuleItem { +impl AstNode for Item { fn can_cast(kind: SyntaxKind) -> bool { match kind { - STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF - | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE | MACRO_CALL - | EXTERN_BLOCK => true, + CONST_DEF | ENUM_DEF | EXTERN_BLOCK | EXTERN_CRATE_ITEM | FN_DEF | IMPL_DEF + | MACRO_CALL | MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS_DEF + | UNION_DEF | USE_ITEM => true, _ => false, } } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }), - UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }), - ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }), - FN_DEF => ModuleItem::FnDef(FnDef { syntax }), - TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }), - TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }), - IMPL_DEF => ModuleItem::ImplDef(ImplDef { syntax }), - USE_ITEM => ModuleItem::UseItem(UseItem { syntax }), - EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }), - CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }), - STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }), - MODULE => ModuleItem::Module(Module { syntax }), - MACRO_CALL => ModuleItem::MacroCall(MacroCall { syntax }), - EXTERN_BLOCK => ModuleItem::ExternBlock(ExternBlock { syntax }), + CONST_DEF => Item::ConstDef(ConstDef { syntax }), + ENUM_DEF => Item::EnumDef(EnumDef { syntax }), + EXTERN_BLOCK => Item::ExternBlock(ExternBlock { syntax }), + EXTERN_CRATE_ITEM => Item::ExternCrateItem(ExternCrateItem { syntax }), + FN_DEF => Item::FnDef(FnDef { syntax }), + IMPL_DEF => Item::ImplDef(ImplDef { syntax }), + MACRO_CALL => Item::MacroCall(MacroCall { syntax }), + MODULE => Item::Module(Module { syntax }), + STATIC_DEF => Item::StaticDef(StaticDef { syntax }), + STRUCT_DEF => Item::StructDef(StructDef { syntax }), + TRAIT_DEF => Item::TraitDef(TraitDef { syntax }), + TYPE_ALIAS_DEF => Item::TypeAliasDef(TypeAliasDef { syntax }), + UNION_DEF => Item::UnionDef(UnionDef { syntax }), + USE_ITEM => Item::UseItem(UseItem { syntax }), _ => return None, }; Some(res) } fn syntax(&self) -> &SyntaxNode { match self { - ModuleItem::StructDef(it) => &it.syntax, - ModuleItem::UnionDef(it) => &it.syntax, - ModuleItem::EnumDef(it) => &it.syntax, - ModuleItem::FnDef(it) => &it.syntax, - ModuleItem::TraitDef(it) => &it.syntax, - ModuleItem::TypeAliasDef(it) => &it.syntax, - ModuleItem::ImplDef(it) => &it.syntax, - ModuleItem::UseItem(it) => &it.syntax, - ModuleItem::ExternCrateItem(it) => &it.syntax, - ModuleItem::ConstDef(it) => &it.syntax, - ModuleItem::StaticDef(it) => &it.syntax, - ModuleItem::Module(it) => &it.syntax, - ModuleItem::MacroCall(it) => &it.syntax, - ModuleItem::ExternBlock(it) => &it.syntax, + Item::ConstDef(it) => &it.syntax, + Item::EnumDef(it) => &it.syntax, + Item::ExternBlock(it) => &it.syntax, + Item::ExternCrateItem(it) => &it.syntax, + Item::FnDef(it) => &it.syntax, + Item::ImplDef(it) => &it.syntax, + Item::MacroCall(it) => &it.syntax, + Item::Module(it) => &it.syntax, + Item::StaticDef(it) => &it.syntax, + Item::StructDef(it) => &it.syntax, + Item::TraitDef(it) => &it.syntax, + Item::TypeAliasDef(it) => &it.syntax, + Item::UnionDef(it) => &it.syntax, + Item::UseItem(it) => &it.syntax, } } } @@ -3378,7 +3378,7 @@ impl AstNode for AdtDef { } } } -impl std::fmt::Display for ModuleItem { +impl std::fmt::Display for Item { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3438,47 +3438,47 @@ impl std::fmt::Display for Attr { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for FnDef { +impl std::fmt::Display for ConstDef { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Visibility { +impl std::fmt::Display for EnumDef { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Abi { +impl std::fmt::Display for ExternBlock { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Name { +impl std::fmt::Display for ExternCrateItem { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for TypeParamList { +impl std::fmt::Display for FnDef { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ParamList { +impl std::fmt::Display for ImplDef { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for RetType { +impl std::fmt::Display for MacroCall { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for WhereClause { +impl std::fmt::Display for Module { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for BlockExpr { +impl std::fmt::Display for StaticDef { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3488,12 +3488,12 @@ impl std::fmt::Display for StructDef { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for RecordFieldDefList { +impl std::fmt::Display for TraitDef { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for TupleFieldDefList { +impl std::fmt::Display for TypeAliasDef { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3503,67 +3503,87 @@ impl std::fmt::Display for UnionDef { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for RecordFieldDef { +impl std::fmt::Display for UseItem { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for TupleFieldDef { +impl std::fmt::Display for Visibility { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for EnumDef { +impl std::fmt::Display for Abi { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for EnumVariantList { +impl std::fmt::Display for Name { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for EnumVariant { +impl std::fmt::Display for TypeParamList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for TraitDef { +impl std::fmt::Display for ParamList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for TypeBoundList { +impl std::fmt::Display for RetType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ItemList { +impl std::fmt::Display for WhereClause { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Module { +impl std::fmt::Display for BlockExpr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ConstDef { +impl std::fmt::Display for RecordFieldDefList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for StaticDef { +impl std::fmt::Display for TupleFieldDefList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for TypeAliasDef { +impl std::fmt::Display for RecordFieldDef { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ImplDef { +impl std::fmt::Display for TupleFieldDef { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for EnumVariantList { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for EnumVariant { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for TypeBoundList { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for ItemList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3888,11 +3908,6 @@ impl std::fmt::Display for MacroPat { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for MacroCall { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for RecordPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3983,11 +3998,6 @@ impl std::fmt::Display for Param { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for UseItem { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for UseTree { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -4003,11 +4013,6 @@ impl std::fmt::Display for Alias { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ExternCrateItem { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for PathSegment { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -4033,11 +4038,6 @@ impl std::fmt::Display for ConstArg { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ExternBlock { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for ExternItemList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index a8f2454fd..9fe0b93c1 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -44,7 +44,7 @@ pub trait ArgListOwner: AstNode { } pub trait ModuleItemOwner: AstNode { - fn items(&self) -> AstChildren { + fn items(&self) -> AstChildren { support::children(self.syntax()) } } diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index ac59455e7..219dd0b07 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -187,7 +187,7 @@ impl ast::Expr { } } -impl ast::ModuleItem { +impl ast::Item { /// Returns `text`, parsed as an item, but only if it has no errors. pub fn parse(text: &str) -> Result { parsing::parse_text_fragment(text, ra_parser::FragmentKind::Item) @@ -255,7 +255,7 @@ fn api_walkthrough() { let mut func = None; for item in file.items() { match item { - ast::ModuleItem::FnDef(f) => func = Some(f), + ast::Item::FnDef(f) => func = Some(f), _ => unreachable!(), } } diff --git a/crates/ra_syntax/src/tests.rs b/crates/ra_syntax/src/tests.rs index 8447dcad7..68cee8914 100644 --- a/crates/ra_syntax/src/tests.rs +++ b/crates/ra_syntax/src/tests.rs @@ -89,7 +89,7 @@ fn item_parser_tests() { fragment_parser_dir_test( &["parser/fragments/item/ok"], &["parser/fragments/item/err"], - crate::ast::ModuleItem::parse, + crate::ast::Item::parse, ); } -- cgit v1.2.3 From ede5d17b0409f9d5a209aaf16508262dbd2a4489 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 00:27:00 +0200 Subject: Finish SourceFile grammar --- crates/ra_syntax/src/ast/generated/nodes.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 3c8bdfcad..dfda79550 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -11,7 +11,9 @@ pub struct SourceFile { } impl ast::AttrsOwner for SourceFile {} impl ast::ModuleItemOwner for SourceFile {} -impl SourceFile {} +impl SourceFile { + pub fn shebang_token(&self) -> Option { support::token(&self.syntax, T![shebang]) } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Attr { pub(crate) syntax: SyntaxNode, -- cgit v1.2.3