diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-20 16:09:22 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-20 16:09:22 +0000 |
commit | e62533c3ec74358d3488e8e4b7967c78459b238f (patch) | |
tree | cd1fe4ad8f6a19b44678e1389c0c7553a6d11036 /crates/hir_def/src/item_tree | |
parent | 9d10aa09726f38d184d499c0a04f8ba4bc1c2bba (diff) | |
parent | c5ed2284b5733dcaf8b57b1771c441afc39fa5e7 (diff) |
Merge #7359
7359: ItemTree: store a mapping from blocks to inner items r=jonas-schievink a=jonas-schievink
To do name resolution within block expressions, we need to know which inner items are located inside each block expression. This adds such a mapping to `ItemTree`, replacing the previous one, which was seemingly unused other than to access all the inner items.
This also assigns `AstId`s to block expressions, which is needed to store the mapping in salsa.
Co-authored-by: Jonas Schievink <[email protected]>
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 | ||