diff options
author | Jonas Schievink <[email protected]> | 2021-01-20 13:49:04 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-01-20 14:00:28 +0000 |
commit | c5ed2284b5733dcaf8b57b1771c441afc39fa5e7 (patch) | |
tree | 598c6447f36c827a61fa89df4300946c0e213d32 /crates/hir_def/src/item_tree | |
parent | 52fe50a97b702f3e72600b19936f5f355d897d1e (diff) |
Create a mapping from blocks to inner items
Diffstat (limited to 'crates/hir_def/src/item_tree')
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 5e71ca42c..56fe569ff 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -6,7 +6,7 @@ use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, name::known, HirFileId} | |||
6 | use smallvec::SmallVec; | 6 | use smallvec::SmallVec; |
7 | use syntax::{ | 7 | use syntax::{ |
8 | ast::{self, ModuleItemOwner}, | 8 | ast::{self, ModuleItemOwner}, |
9 | SyntaxNode, | 9 | SyntaxNode, WalkEvent, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
@@ -150,14 +150,29 @@ impl Ctx { | |||
150 | 150 | ||
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 | let mut inner_items = mem::take(&mut self.tree.inner_items); | 153 | |
154 | inner_items.extend(container.descendants().skip(1).filter_map(ast::Item::cast).filter_map( | 154 | let mut current_block = None; |
155 | |item| { | 155 | for event in container.preorder().skip(1) { |
156 | let ast_id = self.source_ast_id_map.ast_id(&item); | 156 | if let WalkEvent::Enter(node) = event { |
157 | Some((ast_id, self.lower_mod_item(&item, true)?.0)) | 157 | match_ast! { |
158 | }, | 158 | match node { |
159 | )); | 159 | ast::BlockExpr(block) => { |
160 | self.tree.inner_items = inner_items; | 160 | current_block = Some(self.source_ast_id_map.ast_id(&block)); |
161 | }, | ||
162 | ast::Item(item) => { | ||
163 | let mod_items = self.lower_mod_item(&item, true); | ||
164 | if let (Some(mod_items), Some(block)) = (mod_items, current_block) { | ||
165 | if !mod_items.0.is_empty() { | ||
166 | self.data().inner_items.entry(block).or_default().extend(mod_items.0.iter().copied()); | ||
167 | } | ||
168 | } | ||
169 | }, | ||
170 | _ => {} | ||
171 | } | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | |||
161 | self.forced_visibility = forced_vis; | 176 | self.forced_visibility = forced_vis; |
162 | } | 177 | } |
163 | 178 | ||