aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-29 23:23:03 +0100
committerAleksey Kladov <[email protected]>2020-07-29 23:23:03 +0100
commit6636f56e79b55f22b88094b7edaed6ec88880500 (patch)
treed042009ea61be66aee1710070c09893447847c9d /crates/ra_hir_def
parent16caadb404de465d8ea1cb6a107740ef004f232b (diff)
Rename ModuleItem -> Item
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/body/lower.rs28
-rw-r--r--crates/ra_hir_def/src/item_tree.rs6
-rw-r--r--crates/ra_hir_def/src/item_tree/lower.rs72
-rw-r--r--crates/ra_hir_def/src/item_tree/tests.rs8
-rw-r--r--crates/ra_hir_def/src/lib.rs2
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs4
6 files changed, 58 insertions, 62 deletions
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<'_> {
627 .items() 627 .items()
628 .filter_map(|item| { 628 .filter_map(|item| {
629 let (def, name): (ModuleDefId, Option<ast::Name>) = match item { 629 let (def, name): (ModuleDefId, Option<ast::Name>) = match item {
630 ast::ModuleItem::FnDef(def) => { 630 ast::Item::FnDef(def) => {
631 let id = self.find_inner_item(&def)?; 631 let id = self.find_inner_item(&def)?;
632 ( 632 (
633 FunctionLoc { container: container.into(), id }.intern(self.db).into(), 633 FunctionLoc { container: container.into(), id }.intern(self.db).into(),
634 def.name(), 634 def.name(),
635 ) 635 )
636 } 636 }
637 ast::ModuleItem::TypeAliasDef(def) => { 637 ast::Item::TypeAliasDef(def) => {
638 let id = self.find_inner_item(&def)?; 638 let id = self.find_inner_item(&def)?;
639 ( 639 (
640 TypeAliasLoc { container: container.into(), id }.intern(self.db).into(), 640 TypeAliasLoc { container: container.into(), id }.intern(self.db).into(),
641 def.name(), 641 def.name(),
642 ) 642 )
643 } 643 }
644 ast::ModuleItem::ConstDef(def) => { 644 ast::Item::ConstDef(def) => {
645 let id = self.find_inner_item(&def)?; 645 let id = self.find_inner_item(&def)?;
646 ( 646 (
647 ConstLoc { container: container.into(), id }.intern(self.db).into(), 647 ConstLoc { container: container.into(), id }.intern(self.db).into(),
648 def.name(), 648 def.name(),
649 ) 649 )
650 } 650 }
651 ast::ModuleItem::StaticDef(def) => { 651 ast::Item::StaticDef(def) => {
652 let id = self.find_inner_item(&def)?; 652 let id = self.find_inner_item(&def)?;
653 (StaticLoc { container, id }.intern(self.db).into(), def.name()) 653 (StaticLoc { container, id }.intern(self.db).into(), def.name())
654 } 654 }
655 ast::ModuleItem::StructDef(def) => { 655 ast::Item::StructDef(def) => {
656 let id = self.find_inner_item(&def)?; 656 let id = self.find_inner_item(&def)?;
657 (StructLoc { container, id }.intern(self.db).into(), def.name()) 657 (StructLoc { container, id }.intern(self.db).into(), def.name())
658 } 658 }
659 ast::ModuleItem::EnumDef(def) => { 659 ast::Item::EnumDef(def) => {
660 let id = self.find_inner_item(&def)?; 660 let id = self.find_inner_item(&def)?;
661 (EnumLoc { container, id }.intern(self.db).into(), def.name()) 661 (EnumLoc { container, id }.intern(self.db).into(), def.name())
662 } 662 }
663 ast::ModuleItem::UnionDef(def) => { 663 ast::Item::UnionDef(def) => {
664 let id = self.find_inner_item(&def)?; 664 let id = self.find_inner_item(&def)?;
665 (UnionLoc { container, id }.intern(self.db).into(), def.name()) 665 (UnionLoc { container, id }.intern(self.db).into(), def.name())
666 } 666 }
667 ast::ModuleItem::TraitDef(def) => { 667 ast::Item::TraitDef(def) => {
668 let id = self.find_inner_item(&def)?; 668 let id = self.find_inner_item(&def)?;
669 (TraitLoc { container, id }.intern(self.db).into(), def.name()) 669 (TraitLoc { container, id }.intern(self.db).into(), def.name())
670 } 670 }
671 ast::ModuleItem::ExternBlock(_) => return None, // FIXME: collect from extern blocks 671 ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks
672 ast::ModuleItem::ImplDef(_) 672 ast::Item::ImplDef(_)
673 | ast::ModuleItem::UseItem(_) 673 | ast::Item::UseItem(_)
674 | ast::ModuleItem::ExternCrateItem(_) 674 | ast::Item::ExternCrateItem(_)
675 | ast::ModuleItem::Module(_) 675 | ast::Item::Module(_)
676 | ast::ModuleItem::MacroCall(_) => return None, 676 | ast::Item::MacroCall(_) => return None,
677 }; 677 };
678 678
679 Some((def, name)) 679 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 {
70pub struct ItemTree { 70pub struct ItemTree {
71 top_level: SmallVec<[ModItem; 1]>, 71 top_level: SmallVec<[ModItem; 1]>,
72 attrs: FxHashMap<AttrOwner, Attrs>, 72 attrs: FxHashMap<AttrOwner, Attrs>,
73 inner_items: FxHashMap<FileAstId<ast::ModuleItem>, SmallVec<[ModItem; 1]>>, 73 inner_items: FxHashMap<FileAstId<ast::Item>, SmallVec<[ModItem; 1]>>,
74 74
75 data: Option<Box<ItemTreeData>>, 75 data: Option<Box<ItemTreeData>>,
76} 76}
@@ -187,7 +187,7 @@ impl ItemTree {
187 /// 187 ///
188 /// Most AST items are lowered to a single `ModItem`, but some (eg. `use` items) may be lowered 188 /// Most AST items are lowered to a single `ModItem`, but some (eg. `use` items) may be lowered
189 /// to multiple items in the `ItemTree`. 189 /// to multiple items in the `ItemTree`.
190 pub fn inner_items(&self, ast: FileAstId<ast::ModuleItem>) -> &[ModItem] { 190 pub fn inner_items(&self, ast: FileAstId<ast::Item>) -> &[ModItem] {
191 &self.inner_items[&ast] 191 &self.inner_items[&ast]
192 } 192 }
193 193
@@ -310,7 +310,7 @@ from_attrs!(ModItem(ModItem), Variant(Idx<Variant>), Field(Idx<Field>));
310 310
311/// Trait implemented by all item nodes in the item tree. 311/// Trait implemented by all item nodes in the item tree.
312pub trait ItemTreeNode: Clone { 312pub trait ItemTreeNode: Clone {
313 type Source: AstNode + Into<ast::ModuleItem>; 313 type Source: AstNode + Into<ast::Item>;
314 314
315 fn ast_id(&self) -> FileAstId<Self::Source>; 315 fn ast_id(&self) -> FileAstId<Self::Source>;
316 316
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 {
70 self.tree.data_mut() 70 self.tree.data_mut()
71 } 71 }
72 72
73 fn lower_mod_item(&mut self, item: &ast::ModuleItem, inner: bool) -> Option<ModItems> { 73 fn lower_mod_item(&mut self, item: &ast::Item, inner: bool) -> Option<ModItems> {
74 assert!(inner || self.inner_items.is_empty()); 74 assert!(inner || self.inner_items.is_empty());
75 75
76 // Collect inner items for 1-to-1-lowered items. 76 // Collect inner items for 1-to-1-lowered items.
77 match item { 77 match item {
78 ast::ModuleItem::StructDef(_) 78 ast::Item::StructDef(_)
79 | ast::ModuleItem::UnionDef(_) 79 | ast::Item::UnionDef(_)
80 | ast::ModuleItem::EnumDef(_) 80 | ast::Item::EnumDef(_)
81 | ast::ModuleItem::FnDef(_) 81 | ast::Item::FnDef(_)
82 | ast::ModuleItem::TypeAliasDef(_) 82 | ast::Item::TypeAliasDef(_)
83 | ast::ModuleItem::ConstDef(_) 83 | ast::Item::ConstDef(_)
84 | ast::ModuleItem::StaticDef(_) 84 | ast::Item::StaticDef(_)
85 | ast::ModuleItem::MacroCall(_) => { 85 | ast::Item::MacroCall(_) => {
86 // Skip this if we're already collecting inner items. We'll descend into all nodes 86 // Skip this if we're already collecting inner items. We'll descend into all nodes
87 // already. 87 // already.
88 if !inner { 88 if !inner {
@@ -92,34 +92,30 @@ impl Ctx {
92 92
93 // These are handled in their respective `lower_X` method (since we can't just blindly 93 // These are handled in their respective `lower_X` method (since we can't just blindly
94 // walk them). 94 // walk them).
95 ast::ModuleItem::TraitDef(_) 95 ast::Item::TraitDef(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {}
96 | ast::ModuleItem::ImplDef(_)
97 | ast::ModuleItem::ExternBlock(_) => {}
98 96
99 // These don't have inner items. 97 // These don't have inner items.
100 ast::ModuleItem::Module(_) 98 ast::Item::Module(_) | ast::Item::ExternCrateItem(_) | ast::Item::UseItem(_) => {}
101 | ast::ModuleItem::ExternCrateItem(_)
102 | ast::ModuleItem::UseItem(_) => {}
103 }; 99 };
104 100
105 let attrs = Attrs::new(item, &self.hygiene); 101 let attrs = Attrs::new(item, &self.hygiene);
106 let items = match item { 102 let items = match item {
107 ast::ModuleItem::StructDef(ast) => self.lower_struct(ast).map(Into::into), 103 ast::Item::StructDef(ast) => self.lower_struct(ast).map(Into::into),
108 ast::ModuleItem::UnionDef(ast) => self.lower_union(ast).map(Into::into), 104 ast::Item::UnionDef(ast) => self.lower_union(ast).map(Into::into),
109 ast::ModuleItem::EnumDef(ast) => self.lower_enum(ast).map(Into::into), 105 ast::Item::EnumDef(ast) => self.lower_enum(ast).map(Into::into),
110 ast::ModuleItem::FnDef(ast) => self.lower_function(ast).map(Into::into), 106 ast::Item::FnDef(ast) => self.lower_function(ast).map(Into::into),
111 ast::ModuleItem::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into), 107 ast::Item::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into),
112 ast::ModuleItem::StaticDef(ast) => self.lower_static(ast).map(Into::into), 108 ast::Item::StaticDef(ast) => self.lower_static(ast).map(Into::into),
113 ast::ModuleItem::ConstDef(ast) => Some(self.lower_const(ast).into()), 109 ast::Item::ConstDef(ast) => Some(self.lower_const(ast).into()),
114 ast::ModuleItem::Module(ast) => self.lower_module(ast).map(Into::into), 110 ast::Item::Module(ast) => self.lower_module(ast).map(Into::into),
115 ast::ModuleItem::TraitDef(ast) => self.lower_trait(ast).map(Into::into), 111 ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into),
116 ast::ModuleItem::ImplDef(ast) => self.lower_impl(ast).map(Into::into), 112 ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into),
117 ast::ModuleItem::UseItem(ast) => Some(ModItems( 113 ast::Item::UseItem(ast) => Some(ModItems(
118 self.lower_use(ast).into_iter().map(Into::into).collect::<SmallVec<_>>(), 114 self.lower_use(ast).into_iter().map(Into::into).collect::<SmallVec<_>>(),
119 )), 115 )),
120 ast::ModuleItem::ExternCrateItem(ast) => self.lower_extern_crate(ast).map(Into::into), 116 ast::Item::ExternCrateItem(ast) => self.lower_extern_crate(ast).map(Into::into),
121 ast::ModuleItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), 117 ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
122 ast::ModuleItem::ExternBlock(ast) => { 118 ast::Item::ExternBlock(ast) => {
123 Some(ModItems(self.lower_extern_block(ast).into_iter().collect::<SmallVec<_>>())) 119 Some(ModItems(self.lower_extern_block(ast).into_iter().collect::<SmallVec<_>>()))
124 } 120 }
125 }; 121 };
@@ -147,22 +143,22 @@ impl Ctx {
147 fn collect_inner_items(&mut self, container: &SyntaxNode) { 143 fn collect_inner_items(&mut self, container: &SyntaxNode) {
148 let forced_vis = self.forced_visibility.take(); 144 let forced_vis = self.forced_visibility.take();
149 let mut inner_items = mem::take(&mut self.tree.inner_items); 145 let mut inner_items = mem::take(&mut self.tree.inner_items);
150 inner_items.extend( 146 inner_items.extend(container.descendants().skip(1).filter_map(ast::Item::cast).filter_map(
151 container.descendants().skip(1).filter_map(ast::ModuleItem::cast).filter_map(|item| { 147 |item| {
152 let ast_id = self.source_ast_id_map.ast_id(&item); 148 let ast_id = self.source_ast_id_map.ast_id(&item);
153 Some((ast_id, self.lower_mod_item(&item, true)?.0)) 149 Some((ast_id, self.lower_mod_item(&item, true)?.0))
154 }), 150 },
155 ); 151 ));
156 self.tree.inner_items = inner_items; 152 self.tree.inner_items = inner_items;
157 self.forced_visibility = forced_vis; 153 self.forced_visibility = forced_vis;
158 } 154 }
159 155
160 fn lower_assoc_item(&mut self, item: &ast::ModuleItem) -> Option<AssocItem> { 156 fn lower_assoc_item(&mut self, item: &ast::Item) -> Option<AssocItem> {
161 match item { 157 match item {
162 ast::ModuleItem::FnDef(ast) => self.lower_function(ast).map(Into::into), 158 ast::Item::FnDef(ast) => self.lower_function(ast).map(Into::into),
163 ast::ModuleItem::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into), 159 ast::Item::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into),
164 ast::ModuleItem::ConstDef(ast) => Some(self.lower_const(ast).into()), 160 ast::Item::ConstDef(ast) => Some(self.lower_const(ast).into()),
165 ast::ModuleItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), 161 ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
166 _ => None, 162 _ => None,
167 } 163 }
168 } 164 }
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) {
21 let mut outer_items = FxHashSet::default(); 21 let mut outer_items = FxHashSet::default();
22 let mut worklist = tree.top_level_items().to_vec(); 22 let mut worklist = tree.top_level_items().to_vec();
23 while let Some(item) = worklist.pop() { 23 while let Some(item) = worklist.pop() {
24 let node: ast::ModuleItem = match item { 24 let node: ast::Item = match item {
25 ModItem::Import(it) => tree.source(&db, InFile::new(file_id, it)).into(), 25 ModItem::Import(it) => tree.source(&db, InFile::new(file_id, it)).into(),
26 ModItem::ExternCrate(it) => tree.source(&db, InFile::new(file_id, it)).into(), 26 ModItem::ExternCrate(it) => tree.source(&db, InFile::new(file_id, it)).into(),
27 ModItem::Function(it) => tree.source(&db, InFile::new(file_id, it)).into(), 27 ModItem::Function(it) => tree.source(&db, InFile::new(file_id, it)).into(),
@@ -53,7 +53,7 @@ fn test_inner_items(ra_fixture: &str) {
53 53
54 // Now descend the root node and check that all `ast::ModuleItem`s are either recorded above, or 54 // Now descend the root node and check that all `ast::ModuleItem`s are either recorded above, or
55 // registered as inner items. 55 // registered as inner items.
56 for item in root.descendants().skip(1).filter_map(ast::ModuleItem::cast) { 56 for item in root.descendants().skip(1).filter_map(ast::Item::cast) {
57 if outer_items.contains(&item) { 57 if outer_items.contains(&item) {
58 continue; 58 continue;
59 } 59 }
@@ -279,7 +279,7 @@ fn simple_inner_items() {
279 279
280 inner items: 280 inner items:
281 281
282 for AST FileAstId::<ra_syntax::ast::generated::nodes::ModuleItem>(2): 282 for AST FileAstId::<ra_syntax::ast::generated::nodes::Item>(2):
283 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::<ra_syntax::ast::generated::nodes::FnDef>(2) } 283 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::<ra_syntax::ast::generated::nodes::FnDef>(2) }
284 284
285 "#]], 285 "#]],
@@ -412,7 +412,7 @@ fn inner_item_attrs() {
412 412
413 inner items: 413 inner items:
414 414
415 for AST FileAstId::<ra_syntax::ast::generated::nodes::ModuleItem>(1): 415 for AST FileAstId::<ra_syntax::ast::generated::nodes::Item>(1):
416 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_inner"))] }, input: None }]) }] 416 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_inner"))] }, input: None }]) }]
417 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::<ra_syntax::ast::generated::nodes::FnDef>(1) } 417 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::<ra_syntax::ast::generated::nodes::FnDef>(1) }
418 418
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<ast::MacroCall> {
521 } 521 }
522} 522}
523 523
524impl AsMacroCall for AstIdWithPath<ast::ModuleItem> { 524impl AsMacroCall for AstIdWithPath<ast::Item> {
525 fn as_call_id( 525 fn as_call_id(
526 &self, 526 &self,
527 db: &dyn db::DefDatabase, 527 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 {
170#[derive(Clone, Debug, Eq, PartialEq)] 170#[derive(Clone, Debug, Eq, PartialEq)]
171struct DeriveDirective { 171struct DeriveDirective {
172 module_id: LocalModuleId, 172 module_id: LocalModuleId,
173 ast_id: AstIdWithPath<ast::ModuleItem>, 173 ast_id: AstIdWithPath<ast::Item>,
174} 174}
175 175
176struct DefData<'a> { 176struct DefData<'a> {
@@ -1100,7 +1100,7 @@ impl ModCollector<'_, '_> {
1100 res 1100 res
1101 } 1101 }
1102 1102
1103 fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId<ast::ModuleItem>) { 1103 fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId<ast::Item>) {
1104 for derive_subtree in attrs.by_key("derive").tt_values() { 1104 for derive_subtree in attrs.by_key("derive").tt_values() {
1105 // for #[derive(Copy, Clone)], `derive_subtree` is the `(Copy, Clone)` subtree 1105 // for #[derive(Copy, Clone)], `derive_subtree` is the `(Copy, Clone)` subtree
1106 for tt in &derive_subtree.token_trees { 1106 for tt in &derive_subtree.token_trees {