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 +- 6 files changed, 58 insertions(+), 62 deletions(-) (limited to 'crates/ra_hir_def/src') 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 { -- cgit v1.2.3