aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/item_tree/lower.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/item_tree/lower.rs')
-rw-r--r--crates/hir_def/src/item_tree/lower.rs38
1 files changed, 23 insertions, 15 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index 56fe569ff..61cbbbc8f 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -151,23 +151,31 @@ impl Ctx {
151 fn collect_inner_items(&mut self, container: &SyntaxNode) { 151 fn collect_inner_items(&mut self, container: &SyntaxNode) {
152 let forced_vis = self.forced_visibility.take(); 152 let forced_vis = self.forced_visibility.take();
153 153
154 let mut current_block = None; 154 let mut block_stack = Vec::new();
155 for event in container.preorder().skip(1) { 155 for event in container.preorder().skip(1) {
156 if let WalkEvent::Enter(node) = event { 156 match event {
157 match_ast! { 157 WalkEvent::Enter(node) => {
158 match node { 158 match_ast! {
159 ast::BlockExpr(block) => { 159 match node {
160 current_block = Some(self.source_ast_id_map.ast_id(&block)); 160 ast::BlockExpr(block) => {
161 }, 161 block_stack.push(self.source_ast_id_map.ast_id(&block));
162 ast::Item(item) => { 162 },
163 let mod_items = self.lower_mod_item(&item, true); 163 ast::Item(item) => {
164 if let (Some(mod_items), Some(block)) = (mod_items, current_block) { 164 let mod_items = self.lower_mod_item(&item, true);
165 if !mod_items.0.is_empty() { 165 let current_block = block_stack.last();
166 self.data().inner_items.entry(block).or_default().extend(mod_items.0.iter().copied()); 166 if let (Some(mod_items), Some(block)) = (mod_items, current_block) {
167 if !mod_items.0.is_empty() {
168 self.data().inner_items.entry(*block).or_default().extend(mod_items.0.iter().copied());
169 }
167 } 170 }
168 } 171 },
169 }, 172 _ => {}
170 _ => {} 173 }
174 }
175 }
176 WalkEvent::Leave(node) => {
177 if ast::BlockExpr::cast(node).is_some() {
178 block_stack.pop();
171 } 179 }
172 } 180 }
173 } 181 }