aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/item_tree/lower.rs
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/src/item_tree/lower.rs
parent16caadb404de465d8ea1cb6a107740ef004f232b (diff)
Rename ModuleItem -> Item
Diffstat (limited to 'crates/ra_hir_def/src/item_tree/lower.rs')
-rw-r--r--crates/ra_hir_def/src/item_tree/lower.rs72
1 files changed, 34 insertions, 38 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 }