aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-03 14:41:13 +0000
committerGitHub <[email protected]>2021-02-03 14:41:13 +0000
commitfd84df9e1bb231f7aa4bcf760e0aff0a6bd10e9f (patch)
tree57fbfe241dcd571b9376b23260299160e0312246 /crates/hir_def/src/nameres.rs
parent93ecef53a370703a67f87b90c4640d3e8bf73934 (diff)
parent63744fe128193464eb0ce63fbe6c30c4f98b6135 (diff)
Merge #7541
7541: Use block_def_map in body lowering (third time's the charm) r=jonas-schievink a=jonas-schievink After https://github.com/rust-analyzer/rust-analyzer/pull/7380 and https://github.com/rust-analyzer/rust-analyzer/pull/7506 both had to be reverted, this should have finally resolved all remaining bugs. Most importantly, the optimization to skip `block_def_map` computation when the block contains no inner items was fixed (which fortunately was simpler than expected). I've ran `analysis-stats` on libstd locally, which works fine, and also ran this PR locally for a short while without issues. Note that this *still* has no (or almost no) user-facing impact, because the rest of r-a still relies on some local item support hacks. bors r+ Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/nameres.rs')
-rw-r--r--crates/hir_def/src/nameres.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index 0a15fc470..ece5958f4 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -197,12 +197,17 @@ impl DefMap {
197 Arc::new(def_map) 197 Arc::new(def_map)
198 } 198 }
199 199
200 pub(crate) fn block_def_map_query(db: &dyn DefDatabase, block_id: BlockId) -> Arc<DefMap> { 200 pub(crate) fn block_def_map_query(
201 db: &dyn DefDatabase,
202 block_id: BlockId,
203 ) -> Option<Arc<DefMap>> {
201 let block: BlockLoc = db.lookup_intern_block(block_id); 204 let block: BlockLoc = db.lookup_intern_block(block_id);
202 let parent = block.module.def_map(db); 205 let parent = block.module.def_map(db);
203 206
204 // FIXME: It would be good to just return the parent map when the block has no items, but 207 let item_tree = db.item_tree(block.ast_id.file_id);
205 // we rely on `def_map.block` in a few places, which is `Some` for the inner `DefMap`. 208 if item_tree.inner_items_of_block(block.ast_id.value).is_empty() {
209 return None;
210 }
206 211
207 let block_info = 212 let block_info =
208 BlockInfo { block: block_id, parent, parent_module: block.module.local_id }; 213 BlockInfo { block: block_id, parent, parent_module: block.module.local_id };
@@ -211,7 +216,7 @@ impl DefMap {
211 def_map.block = Some(block_info); 216 def_map.block = Some(block_info);
212 217
213 let def_map = collector::collect_defs(db, def_map, Some(block.ast_id)); 218 let def_map = collector::collect_defs(db, def_map, Some(block.ast_id));
214 Arc::new(def_map) 219 Some(Arc::new(def_map))
215 } 220 }
216 221
217 fn empty(krate: CrateId, edition: Edition) -> DefMap { 222 fn empty(krate: CrateId, edition: Edition) -> DefMap {