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_hir_def/src/body/lower.rs | 28 +- crates/ra_hir_def/src/item_tree.rs | 6 +- crates/ra_hir_def/src/item_tree/lower.rs | 72 +- crates/ra_hir_def/src/item_tree/tests.rs | 8 +- crates/ra_hir_def/src/lib.rs | 2 +- crates/ra_hir_def/src/nameres/collector.rs | 4 +- crates/ra_hir_expand/src/ast_id_map.rs | 2 +- crates/ra_hir_expand/src/builtin_derive.rs | 2 +- crates/ra_hir_expand/src/lib.rs | 6 +- crates/ra_ide/src/completion/complete_fn_param.rs | 2 +- crates/ra_ide/src/runnables.rs | 4 +- crates/ra_ssr/src/parsing.rs | 5 +- 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 +- 16 files changed, 465 insertions(+), 472 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index c6bc85e2f..c33b645f3 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -627,53 +627,53 @@ impl ExprCollector<'_> { .items() .filter_map(|item| { let (def, name): (ModuleDefId, Option) = match item { - ast::ModuleItem::FnDef(def) => { + ast::Item::FnDef(def) => { let id = self.find_inner_item(&def)?; ( FunctionLoc { container: container.into(), id }.intern(self.db).into(), def.name(), ) } - ast::ModuleItem::TypeAliasDef(def) => { + ast::Item::TypeAliasDef(def) => { let id = self.find_inner_item(&def)?; ( TypeAliasLoc { container: container.into(), id }.intern(self.db).into(), def.name(), ) } - ast::ModuleItem::ConstDef(def) => { + ast::Item::ConstDef(def) => { let id = self.find_inner_item(&def)?; ( ConstLoc { container: container.into(), id }.intern(self.db).into(), def.name(), ) } - ast::ModuleItem::StaticDef(def) => { + ast::Item::StaticDef(def) => { let id = self.find_inner_item(&def)?; (StaticLoc { container, id }.intern(self.db).into(), def.name()) } - ast::ModuleItem::StructDef(def) => { + ast::Item::StructDef(def) => { let id = self.find_inner_item(&def)?; (StructLoc { container, id }.intern(self.db).into(), def.name()) } - ast::ModuleItem::EnumDef(def) => { + ast::Item::EnumDef(def) => { let id = self.find_inner_item(&def)?; (EnumLoc { container, id }.intern(self.db).into(), def.name()) } - ast::ModuleItem::UnionDef(def) => { + ast::Item::UnionDef(def) => { let id = self.find_inner_item(&def)?; (UnionLoc { container, id }.intern(self.db).into(), def.name()) } - ast::ModuleItem::TraitDef(def) => { + ast::Item::TraitDef(def) => { let id = self.find_inner_item(&def)?; (TraitLoc { container, id }.intern(self.db).into(), def.name()) } - ast::ModuleItem::ExternBlock(_) => return None, // FIXME: collect from extern blocks - ast::ModuleItem::ImplDef(_) - | ast::ModuleItem::UseItem(_) - | ast::ModuleItem::ExternCrateItem(_) - | ast::ModuleItem::Module(_) - | ast::ModuleItem::MacroCall(_) => return None, + ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks + ast::Item::ImplDef(_) + | ast::Item::UseItem(_) + | ast::Item::ExternCrateItem(_) + | ast::Item::Module(_) + | ast::Item::MacroCall(_) => return None, }; Some((def, name)) diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index da79d8ffd..615c1e14c 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs @@ -70,7 +70,7 @@ impl GenericParamsId { pub struct ItemTree { top_level: SmallVec<[ModItem; 1]>, attrs: FxHashMap, - inner_items: FxHashMap, SmallVec<[ModItem; 1]>>, + inner_items: FxHashMap, SmallVec<[ModItem; 1]>>, data: Option>, } @@ -187,7 +187,7 @@ impl ItemTree { /// /// Most AST items are lowered to a single `ModItem`, but some (eg. `use` items) may be lowered /// to multiple items in the `ItemTree`. - pub fn inner_items(&self, ast: FileAstId) -> &[ModItem] { + pub fn inner_items(&self, ast: FileAstId) -> &[ModItem] { &self.inner_items[&ast] } @@ -310,7 +310,7 @@ from_attrs!(ModItem(ModItem), Variant(Idx), Field(Idx)); /// Trait implemented by all item nodes in the item tree. pub trait ItemTreeNode: Clone { - type Source: AstNode + Into; + type Source: AstNode + Into; fn ast_id(&self) -> FileAstId; diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index f79b8fca3..eb1da4632 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs @@ -70,19 +70,19 @@ impl Ctx { self.tree.data_mut() } - fn lower_mod_item(&mut self, item: &ast::ModuleItem, inner: bool) -> Option { + fn lower_mod_item(&mut self, item: &ast::Item, inner: bool) -> Option { assert!(inner || self.inner_items.is_empty()); // Collect inner items for 1-to-1-lowered items. match item { - ast::ModuleItem::StructDef(_) - | ast::ModuleItem::UnionDef(_) - | ast::ModuleItem::EnumDef(_) - | ast::ModuleItem::FnDef(_) - | ast::ModuleItem::TypeAliasDef(_) - | ast::ModuleItem::ConstDef(_) - | ast::ModuleItem::StaticDef(_) - | ast::ModuleItem::MacroCall(_) => { + ast::Item::StructDef(_) + | ast::Item::UnionDef(_) + | ast::Item::EnumDef(_) + | ast::Item::FnDef(_) + | ast::Item::TypeAliasDef(_) + | ast::Item::ConstDef(_) + | ast::Item::StaticDef(_) + | ast::Item::MacroCall(_) => { // Skip this if we're already collecting inner items. We'll descend into all nodes // already. if !inner { @@ -92,34 +92,30 @@ impl Ctx { // These are handled in their respective `lower_X` method (since we can't just blindly // walk them). - ast::ModuleItem::TraitDef(_) - | ast::ModuleItem::ImplDef(_) - | ast::ModuleItem::ExternBlock(_) => {} + ast::Item::TraitDef(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {} // These don't have inner items. - ast::ModuleItem::Module(_) - | ast::ModuleItem::ExternCrateItem(_) - | ast::ModuleItem::UseItem(_) => {} + ast::Item::Module(_) | ast::Item::ExternCrateItem(_) | ast::Item::UseItem(_) => {} }; let attrs = Attrs::new(item, &self.hygiene); let items = match item { - ast::ModuleItem::StructDef(ast) => self.lower_struct(ast).map(Into::into), - ast::ModuleItem::UnionDef(ast) => self.lower_union(ast).map(Into::into), - ast::ModuleItem::EnumDef(ast) => self.lower_enum(ast).map(Into::into), - ast::ModuleItem::FnDef(ast) => self.lower_function(ast).map(Into::into), - ast::ModuleItem::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into), - ast::ModuleItem::StaticDef(ast) => self.lower_static(ast).map(Into::into), - ast::ModuleItem::ConstDef(ast) => Some(self.lower_const(ast).into()), - ast::ModuleItem::Module(ast) => self.lower_module(ast).map(Into::into), - ast::ModuleItem::TraitDef(ast) => self.lower_trait(ast).map(Into::into), - ast::ModuleItem::ImplDef(ast) => self.lower_impl(ast).map(Into::into), - ast::ModuleItem::UseItem(ast) => Some(ModItems( + ast::Item::StructDef(ast) => self.lower_struct(ast).map(Into::into), + ast::Item::UnionDef(ast) => self.lower_union(ast).map(Into::into), + ast::Item::EnumDef(ast) => self.lower_enum(ast).map(Into::into), + ast::Item::FnDef(ast) => self.lower_function(ast).map(Into::into), + ast::Item::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into), + ast::Item::StaticDef(ast) => self.lower_static(ast).map(Into::into), + ast::Item::ConstDef(ast) => Some(self.lower_const(ast).into()), + ast::Item::Module(ast) => self.lower_module(ast).map(Into::into), + ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into), + ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into), + ast::Item::UseItem(ast) => Some(ModItems( self.lower_use(ast).into_iter().map(Into::into).collect::>(), )), - ast::ModuleItem::ExternCrateItem(ast) => self.lower_extern_crate(ast).map(Into::into), - ast::ModuleItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), - ast::ModuleItem::ExternBlock(ast) => { + ast::Item::ExternCrateItem(ast) => self.lower_extern_crate(ast).map(Into::into), + ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), + ast::Item::ExternBlock(ast) => { Some(ModItems(self.lower_extern_block(ast).into_iter().collect::>())) } }; @@ -147,22 +143,22 @@ impl Ctx { fn collect_inner_items(&mut self, container: &SyntaxNode) { let forced_vis = self.forced_visibility.take(); let mut inner_items = mem::take(&mut self.tree.inner_items); - inner_items.extend( - container.descendants().skip(1).filter_map(ast::ModuleItem::cast).filter_map(|item| { + inner_items.extend(container.descendants().skip(1).filter_map(ast::Item::cast).filter_map( + |item| { let ast_id = self.source_ast_id_map.ast_id(&item); Some((ast_id, self.lower_mod_item(&item, true)?.0)) - }), - ); + }, + )); self.tree.inner_items = inner_items; self.forced_visibility = forced_vis; } - fn lower_assoc_item(&mut self, item: &ast::ModuleItem) -> Option { + fn lower_assoc_item(&mut self, item: &ast::Item) -> Option { match item { - ast::ModuleItem::FnDef(ast) => self.lower_function(ast).map(Into::into), - ast::ModuleItem::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into), - ast::ModuleItem::ConstDef(ast) => Some(self.lower_const(ast).into()), - ast::ModuleItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), + ast::Item::FnDef(ast) => self.lower_function(ast).map(Into::into), + ast::Item::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into), + ast::Item::ConstDef(ast) => Some(self.lower_const(ast).into()), + ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), _ => None, } } diff --git a/crates/ra_hir_def/src/item_tree/tests.rs b/crates/ra_hir_def/src/item_tree/tests.rs index f26982985..a6057ceab 100644 --- a/crates/ra_hir_def/src/item_tree/tests.rs +++ b/crates/ra_hir_def/src/item_tree/tests.rs @@ -21,7 +21,7 @@ fn test_inner_items(ra_fixture: &str) { let mut outer_items = FxHashSet::default(); let mut worklist = tree.top_level_items().to_vec(); while let Some(item) = worklist.pop() { - let node: ast::ModuleItem = match item { + let node: ast::Item = match item { ModItem::Import(it) => tree.source(&db, InFile::new(file_id, it)).into(), ModItem::ExternCrate(it) => tree.source(&db, InFile::new(file_id, it)).into(), ModItem::Function(it) => tree.source(&db, InFile::new(file_id, it)).into(), @@ -53,7 +53,7 @@ fn test_inner_items(ra_fixture: &str) { // Now descend the root node and check that all `ast::ModuleItem`s are either recorded above, or // registered as inner items. - for item in root.descendants().skip(1).filter_map(ast::ModuleItem::cast) { + for item in root.descendants().skip(1).filter_map(ast::Item::cast) { if outer_items.contains(&item) { continue; } @@ -279,7 +279,7 @@ fn simple_inner_items() { inner items: - for AST FileAstId::(2): + for AST FileAstId::(2): Function { name: Name(Text("end")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(2) } "#]], @@ -412,7 +412,7 @@ fn inner_item_attrs() { inner items: - for AST FileAstId::(1): + for AST FileAstId::(1): #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_inner"))] }, input: None }]) }] Function { name: Name(Text("inner")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(1) } diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 87000fe98..237b1038a 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -521,7 +521,7 @@ impl AsMacroCall for AstIdWithPath { } } -impl AsMacroCall for AstIdWithPath { +impl AsMacroCall for AstIdWithPath { fn as_call_id( &self, db: &dyn db::DefDatabase, diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index a030cab47..28b7a20c5 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -170,7 +170,7 @@ struct MacroDirective { #[derive(Clone, Debug, Eq, PartialEq)] struct DeriveDirective { module_id: LocalModuleId, - ast_id: AstIdWithPath, + ast_id: AstIdWithPath, } struct DefData<'a> { @@ -1100,7 +1100,7 @@ impl ModCollector<'_, '_> { res } - fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId) { + fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId) { for derive_subtree in attrs.by_key("derive").tt_values() { // for #[derive(Copy, Clone)], `derive_subtree` is the `(Copy, Clone)` subtree for tt in &derive_subtree.token_trees { diff --git a/crates/ra_hir_expand/src/ast_id_map.rs b/crates/ra_hir_expand/src/ast_id_map.rs index f4d31526a..8bfe1b4ba 100644 --- a/crates/ra_hir_expand/src/ast_id_map.rs +++ b/crates/ra_hir_expand/src/ast_id_map.rs @@ -73,7 +73,7 @@ impl AstIdMap { // change parent's id. This means that, say, adding a new function to a // trait does not change ids of top-level items, which helps caching. bfs(node, |it| { - if let Some(module_item) = ast::ModuleItem::cast(it) { + if let Some(module_item) = ast::Item::cast(it) { res.alloc(module_item.syntax()); } }); diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs index f2d664863..8f70a3567 100644 --- a/crates/ra_hir_expand/src/builtin_derive.rs +++ b/crates/ra_hir_expand/src/builtin_derive.rs @@ -276,7 +276,7 @@ mod tests { let file_id = file_pos.file_id; let parsed = db.parse(file_id); let items: Vec<_> = - parsed.syntax_node().descendants().filter_map(ast::ModuleItem::cast).collect(); + parsed.syntax_node().descendants().filter_map(ast::Item::cast).collect(); let ast_id_map = db.ast_id_map(file_id.into()); diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index d9e31ac20..2e8d63691 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -159,7 +159,7 @@ impl HirFileId { } /// Indicate it is macro file generated for builtin derive - pub fn is_builtin_derive(&self, db: &dyn db::AstDatabase) -> Option> { + pub fn is_builtin_derive(&self, db: &dyn db::AstDatabase) -> Option> { match self.0 { HirFileIdRepr::FileId(_) => None, HirFileIdRepr::MacroFile(macro_file) => { @@ -174,7 +174,7 @@ impl HirFileId { MacroDefKind::BuiltInDerive(_) => loc.kind.node(db), _ => return None, }; - Some(item.with_value(ast::ModuleItem::cast(item.value.clone())?)) + Some(item.with_value(ast::Item::cast(item.value.clone())?)) } } } @@ -258,7 +258,7 @@ pub struct MacroCallLoc { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum MacroCallKind { FnLike(AstId), - Attr(AstId, String), + Attr(AstId, String), } impl MacroCallKind { diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index db2abb4f1..7a53083f5 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs @@ -28,7 +28,7 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) } }; for item in items { - if let ast::ModuleItem::FnDef(func) = item { + if let ast::Item::FnDef(func) = item { if Some(&func) == me.as_ref() { continue; } diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 45e0a7d85..f612835c2 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -246,12 +246,12 @@ fn has_test_function_or_multiple_test_submodules(module: &ast::Module) -> bool { for item in item_list.items() { match item { - ast::ModuleItem::FnDef(f) => { + ast::Item::FnDef(f) => { if has_test_related_attribute(&f) { return true; } } - ast::ModuleItem::Module(submodule) => { + ast::Item::Module(submodule) => { if has_test_function_or_multiple_test_submodules(&submodule) { number_of_test_submodules += 1; } diff --git a/crates/ra_ssr/src/parsing.rs b/crates/ra_ssr/src/parsing.rs index 769720bef..78e03f394 100644 --- a/crates/ra_ssr/src/parsing.rs +++ b/crates/ra_ssr/src/parsing.rs @@ -71,10 +71,7 @@ impl ParsedRule { }; builder.try_add(ast::Expr::parse(&raw_pattern), raw_template.map(ast::Expr::parse)); builder.try_add(ast::TypeRef::parse(&raw_pattern), raw_template.map(ast::TypeRef::parse)); - builder.try_add( - ast::ModuleItem::parse(&raw_pattern), - raw_template.map(ast::ModuleItem::parse), - ); + builder.try_add(ast::Item::parse(&raw_pattern), raw_template.map(ast::Item::parse)); builder.try_add(ast::Path::parse(&raw_pattern), raw_template.map(ast::Path::parse)); builder.try_add(ast::Pat::parse(&raw_pattern), raw_template.map(ast::Pat::parse)); builder.build() 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_parser/src/syntax_kind/generated.rs | 2 +- crates/ra_syntax/src/ast/generated/nodes.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index e7404492a..625f0c822 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -362,4 +362,4 @@ impl SyntaxKind { } } #[macro_export] -macro_rules ! T { [ ; ] => { $ crate :: SyntaxKind :: SEMICOLON } ; [ , ] => { $ crate :: SyntaxKind :: COMMA } ; [ '(' ] => { $ crate :: SyntaxKind :: L_PAREN } ; [ ')' ] => { $ crate :: SyntaxKind :: R_PAREN } ; [ '{' ] => { $ crate :: SyntaxKind :: L_CURLY } ; [ '}' ] => { $ crate :: SyntaxKind :: R_CURLY } ; [ '[' ] => { $ crate :: SyntaxKind :: L_BRACK } ; [ ']' ] => { $ crate :: SyntaxKind :: R_BRACK } ; [ < ] => { $ crate :: SyntaxKind :: L_ANGLE } ; [ > ] => { $ crate :: SyntaxKind :: R_ANGLE } ; [ @ ] => { $ crate :: SyntaxKind :: AT } ; [ # ] => { $ crate :: SyntaxKind :: POUND } ; [ ~ ] => { $ crate :: SyntaxKind :: TILDE } ; [ ? ] => { $ crate :: SyntaxKind :: QUESTION } ; [ $ ] => { $ crate :: SyntaxKind :: DOLLAR } ; [ & ] => { $ crate :: SyntaxKind :: AMP } ; [ | ] => { $ crate :: SyntaxKind :: PIPE } ; [ + ] => { $ crate :: SyntaxKind :: PLUS } ; [ * ] => { $ crate :: SyntaxKind :: STAR } ; [ / ] => { $ crate :: SyntaxKind :: SLASH } ; [ ^ ] => { $ crate :: SyntaxKind :: CARET } ; [ % ] => { $ crate :: SyntaxKind :: PERCENT } ; [ _ ] => { $ crate :: SyntaxKind :: UNDERSCORE } ; [ . ] => { $ crate :: SyntaxKind :: DOT } ; [ .. ] => { $ crate :: SyntaxKind :: DOT2 } ; [ ... ] => { $ crate :: SyntaxKind :: DOT3 } ; [ ..= ] => { $ crate :: SyntaxKind :: DOT2EQ } ; [ : ] => { $ crate :: SyntaxKind :: COLON } ; [ :: ] => { $ crate :: SyntaxKind :: COLON2 } ; [ = ] => { $ crate :: SyntaxKind :: EQ } ; [ == ] => { $ crate :: SyntaxKind :: EQ2 } ; [ => ] => { $ crate :: SyntaxKind :: FAT_ARROW } ; [ ! ] => { $ crate :: SyntaxKind :: BANG } ; [ != ] => { $ crate :: SyntaxKind :: NEQ } ; [ - ] => { $ crate :: SyntaxKind :: MINUS } ; [ -> ] => { $ crate :: SyntaxKind :: THIN_ARROW } ; [ <= ] => { $ crate :: SyntaxKind :: LTEQ } ; [ >= ] => { $ crate :: SyntaxKind :: GTEQ } ; [ += ] => { $ crate :: SyntaxKind :: PLUSEQ } ; [ -= ] => { $ crate :: SyntaxKind :: MINUSEQ } ; [ |= ] => { $ crate :: SyntaxKind :: PIPEEQ } ; [ &= ] => { $ crate :: SyntaxKind :: AMPEQ } ; [ ^= ] => { $ crate :: SyntaxKind :: CARETEQ } ; [ /= ] => { $ crate :: SyntaxKind :: SLASHEQ } ; [ *= ] => { $ crate :: SyntaxKind :: STAREQ } ; [ %= ] => { $ crate :: SyntaxKind :: PERCENTEQ } ; [ && ] => { $ crate :: SyntaxKind :: AMP2 } ; [ || ] => { $ crate :: SyntaxKind :: PIPE2 } ; [ << ] => { $ crate :: SyntaxKind :: SHL } ; [ >> ] => { $ crate :: SyntaxKind :: SHR } ; [ <<= ] => { $ crate :: SyntaxKind :: SHLEQ } ; [ >>= ] => { $ crate :: SyntaxKind :: SHREQ } ; [ as ] => { $ crate :: SyntaxKind :: AS_KW } ; [ async ] => { $ crate :: SyntaxKind :: ASYNC_KW } ; [ await ] => { $ crate :: SyntaxKind :: AWAIT_KW } ; [ box ] => { $ crate :: SyntaxKind :: BOX_KW } ; [ break ] => { $ crate :: SyntaxKind :: BREAK_KW } ; [ const ] => { $ crate :: SyntaxKind :: CONST_KW } ; [ continue ] => { $ crate :: SyntaxKind :: CONTINUE_KW } ; [ crate ] => { $ crate :: SyntaxKind :: CRATE_KW } ; [ dyn ] => { $ crate :: SyntaxKind :: DYN_KW } ; [ else ] => { $ crate :: SyntaxKind :: ELSE_KW } ; [ enum ] => { $ crate :: SyntaxKind :: ENUM_KW } ; [ extern ] => { $ crate :: SyntaxKind :: EXTERN_KW } ; [ false ] => { $ crate :: SyntaxKind :: FALSE_KW } ; [ fn ] => { $ crate :: SyntaxKind :: FN_KW } ; [ for ] => { $ crate :: SyntaxKind :: FOR_KW } ; [ if ] => { $ crate :: SyntaxKind :: IF_KW } ; [ impl ] => { $ crate :: SyntaxKind :: IMPL_KW } ; [ in ] => { $ crate :: SyntaxKind :: IN_KW } ; [ let ] => { $ crate :: SyntaxKind :: LET_KW } ; [ loop ] => { $ crate :: SyntaxKind :: LOOP_KW } ; [ macro ] => { $ crate :: SyntaxKind :: MACRO_KW } ; [ match ] => { $ crate :: SyntaxKind :: MATCH_KW } ; [ mod ] => { $ crate :: SyntaxKind :: MOD_KW } ; [ move ] => { $ crate :: SyntaxKind :: MOVE_KW } ; [ mut ] => { $ crate :: SyntaxKind :: MUT_KW } ; [ pub ] => { $ crate :: SyntaxKind :: PUB_KW } ; [ ref ] => { $ crate :: SyntaxKind :: REF_KW } ; [ return ] => { $ crate :: SyntaxKind :: RETURN_KW } ; [ self ] => { $ crate :: SyntaxKind :: SELF_KW } ; [ static ] => { $ crate :: SyntaxKind :: STATIC_KW } ; [ struct ] => { $ crate :: SyntaxKind :: STRUCT_KW } ; [ super ] => { $ crate :: SyntaxKind :: SUPER_KW } ; [ trait ] => { $ crate :: SyntaxKind :: TRAIT_KW } ; [ true ] => { $ crate :: SyntaxKind :: TRUE_KW } ; [ try ] => { $ crate :: SyntaxKind :: TRY_KW } ; [ type ] => { $ crate :: SyntaxKind :: TYPE_KW } ; [ unsafe ] => { $ crate :: SyntaxKind :: UNSAFE_KW } ; [ use ] => { $ crate :: SyntaxKind :: USE_KW } ; [ where ] => { $ crate :: SyntaxKind :: WHERE_KW } ; [ while ] => { $ crate :: SyntaxKind :: WHILE_KW } ; [ auto ] => { $ crate :: SyntaxKind :: AUTO_KW } ; [ default ] => { $ crate :: SyntaxKind :: DEFAULT_KW } ; [ existential ] => { $ crate :: SyntaxKind :: EXISTENTIAL_KW } ; [ union ] => { $ crate :: SyntaxKind :: UNION_KW } ; [ raw ] => { $ crate :: SyntaxKind :: RAW_KW } ; [ lifetime ] => { $ crate :: SyntaxKind :: LIFETIME } ; [ ident ] => { $ crate :: SyntaxKind :: IDENT } ; } +macro_rules ! T { [ ; ] => { $ crate :: SyntaxKind :: SEMICOLON } ; [ , ] => { $ crate :: SyntaxKind :: COMMA } ; [ '(' ] => { $ crate :: SyntaxKind :: L_PAREN } ; [ ')' ] => { $ crate :: SyntaxKind :: R_PAREN } ; [ '{' ] => { $ crate :: SyntaxKind :: L_CURLY } ; [ '}' ] => { $ crate :: SyntaxKind :: R_CURLY } ; [ '[' ] => { $ crate :: SyntaxKind :: L_BRACK } ; [ ']' ] => { $ crate :: SyntaxKind :: R_BRACK } ; [ < ] => { $ crate :: SyntaxKind :: L_ANGLE } ; [ > ] => { $ crate :: SyntaxKind :: R_ANGLE } ; [ @ ] => { $ crate :: SyntaxKind :: AT } ; [ # ] => { $ crate :: SyntaxKind :: POUND } ; [ ~ ] => { $ crate :: SyntaxKind :: TILDE } ; [ ? ] => { $ crate :: SyntaxKind :: QUESTION } ; [ $ ] => { $ crate :: SyntaxKind :: DOLLAR } ; [ & ] => { $ crate :: SyntaxKind :: AMP } ; [ | ] => { $ crate :: SyntaxKind :: PIPE } ; [ + ] => { $ crate :: SyntaxKind :: PLUS } ; [ * ] => { $ crate :: SyntaxKind :: STAR } ; [ / ] => { $ crate :: SyntaxKind :: SLASH } ; [ ^ ] => { $ crate :: SyntaxKind :: CARET } ; [ % ] => { $ crate :: SyntaxKind :: PERCENT } ; [ _ ] => { $ crate :: SyntaxKind :: UNDERSCORE } ; [ . ] => { $ crate :: SyntaxKind :: DOT } ; [ .. ] => { $ crate :: SyntaxKind :: DOT2 } ; [ ... ] => { $ crate :: SyntaxKind :: DOT3 } ; [ ..= ] => { $ crate :: SyntaxKind :: DOT2EQ } ; [ : ] => { $ crate :: SyntaxKind :: COLON } ; [ :: ] => { $ crate :: SyntaxKind :: COLON2 } ; [ = ] => { $ crate :: SyntaxKind :: EQ } ; [ == ] => { $ crate :: SyntaxKind :: EQ2 } ; [ => ] => { $ crate :: SyntaxKind :: FAT_ARROW } ; [ ! ] => { $ crate :: SyntaxKind :: BANG } ; [ != ] => { $ crate :: SyntaxKind :: NEQ } ; [ - ] => { $ crate :: SyntaxKind :: MINUS } ; [ -> ] => { $ crate :: SyntaxKind :: THIN_ARROW } ; [ <= ] => { $ crate :: SyntaxKind :: LTEQ } ; [ >= ] => { $ crate :: SyntaxKind :: GTEQ } ; [ += ] => { $ crate :: SyntaxKind :: PLUSEQ } ; [ -= ] => { $ crate :: SyntaxKind :: MINUSEQ } ; [ |= ] => { $ crate :: SyntaxKind :: PIPEEQ } ; [ &= ] => { $ crate :: SyntaxKind :: AMPEQ } ; [ ^= ] => { $ crate :: SyntaxKind :: CARETEQ } ; [ /= ] => { $ crate :: SyntaxKind :: SLASHEQ } ; [ *= ] => { $ crate :: SyntaxKind :: STAREQ } ; [ %= ] => { $ crate :: SyntaxKind :: PERCENTEQ } ; [ && ] => { $ crate :: SyntaxKind :: AMP2 } ; [ || ] => { $ crate :: SyntaxKind :: PIPE2 } ; [ << ] => { $ crate :: SyntaxKind :: SHL } ; [ >> ] => { $ crate :: SyntaxKind :: SHR } ; [ <<= ] => { $ crate :: SyntaxKind :: SHLEQ } ; [ >>= ] => { $ crate :: SyntaxKind :: SHREQ } ; [ as ] => { $ crate :: SyntaxKind :: AS_KW } ; [ async ] => { $ crate :: SyntaxKind :: ASYNC_KW } ; [ await ] => { $ crate :: SyntaxKind :: AWAIT_KW } ; [ box ] => { $ crate :: SyntaxKind :: BOX_KW } ; [ break ] => { $ crate :: SyntaxKind :: BREAK_KW } ; [ const ] => { $ crate :: SyntaxKind :: CONST_KW } ; [ continue ] => { $ crate :: SyntaxKind :: CONTINUE_KW } ; [ crate ] => { $ crate :: SyntaxKind :: CRATE_KW } ; [ dyn ] => { $ crate :: SyntaxKind :: DYN_KW } ; [ else ] => { $ crate :: SyntaxKind :: ELSE_KW } ; [ enum ] => { $ crate :: SyntaxKind :: ENUM_KW } ; [ extern ] => { $ crate :: SyntaxKind :: EXTERN_KW } ; [ false ] => { $ crate :: SyntaxKind :: FALSE_KW } ; [ fn ] => { $ crate :: SyntaxKind :: FN_KW } ; [ for ] => { $ crate :: SyntaxKind :: FOR_KW } ; [ if ] => { $ crate :: SyntaxKind :: IF_KW } ; [ impl ] => { $ crate :: SyntaxKind :: IMPL_KW } ; [ in ] => { $ crate :: SyntaxKind :: IN_KW } ; [ let ] => { $ crate :: SyntaxKind :: LET_KW } ; [ loop ] => { $ crate :: SyntaxKind :: LOOP_KW } ; [ macro ] => { $ crate :: SyntaxKind :: MACRO_KW } ; [ match ] => { $ crate :: SyntaxKind :: MATCH_KW } ; [ mod ] => { $ crate :: SyntaxKind :: MOD_KW } ; [ move ] => { $ crate :: SyntaxKind :: MOVE_KW } ; [ mut ] => { $ crate :: SyntaxKind :: MUT_KW } ; [ pub ] => { $ crate :: SyntaxKind :: PUB_KW } ; [ ref ] => { $ crate :: SyntaxKind :: REF_KW } ; [ return ] => { $ crate :: SyntaxKind :: RETURN_KW } ; [ self ] => { $ crate :: SyntaxKind :: SELF_KW } ; [ static ] => { $ crate :: SyntaxKind :: STATIC_KW } ; [ struct ] => { $ crate :: SyntaxKind :: STRUCT_KW } ; [ super ] => { $ crate :: SyntaxKind :: SUPER_KW } ; [ trait ] => { $ crate :: SyntaxKind :: TRAIT_KW } ; [ true ] => { $ crate :: SyntaxKind :: TRUE_KW } ; [ try ] => { $ crate :: SyntaxKind :: TRY_KW } ; [ type ] => { $ crate :: SyntaxKind :: TYPE_KW } ; [ unsafe ] => { $ crate :: SyntaxKind :: UNSAFE_KW } ; [ use ] => { $ crate :: SyntaxKind :: USE_KW } ; [ where ] => { $ crate :: SyntaxKind :: WHERE_KW } ; [ while ] => { $ crate :: SyntaxKind :: WHILE_KW } ; [ auto ] => { $ crate :: SyntaxKind :: AUTO_KW } ; [ default ] => { $ crate :: SyntaxKind :: DEFAULT_KW } ; [ existential ] => { $ crate :: SyntaxKind :: EXISTENTIAL_KW } ; [ union ] => { $ crate :: SyntaxKind :: UNION_KW } ; [ raw ] => { $ crate :: SyntaxKind :: RAW_KW } ; [ lifetime ] => { $ crate :: SyntaxKind :: LIFETIME } ; [ ident ] => { $ crate :: SyntaxKind :: IDENT } ; [ shebang ] => { $ crate :: SyntaxKind :: SHEBANG } ; } 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