diff options
author | Aleksey Kladov <[email protected]> | 2020-07-29 23:23:03 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-07-29 23:23:03 +0100 |
commit | 6636f56e79b55f22b88094b7edaed6ec88880500 (patch) | |
tree | d042009ea61be66aee1710070c09893447847c9d /crates/ra_hir_def/src/item_tree | |
parent | 16caadb404de465d8ea1cb6a107740ef004f232b (diff) |
Rename ModuleItem -> Item
Diffstat (limited to 'crates/ra_hir_def/src/item_tree')
-rw-r--r-- | crates/ra_hir_def/src/item_tree/lower.rs | 72 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree/tests.rs | 8 |
2 files changed, 38 insertions, 42 deletions
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 | ||