From b4aa860cac98d69fe4e38602904a6e9e6569e5a6 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 1 Feb 2021 13:32:43 +0100 Subject: Shortcut `block_def_map` if there's no inner items This previously didn't work, but apparently only because of the wonky test setup --- crates/hir_def/src/nameres.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 6169b3bbc..9839761d1 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs @@ -201,8 +201,10 @@ impl DefMap { let block: BlockLoc = db.lookup_intern_block(block_id); let parent = block.module.def_map(db); - // FIXME: It would be good to just return the parent map when the block has no items, but - // we rely on `def_map.block` in a few places, which is `Some` for the inner `DefMap`. + let item_tree = db.item_tree(block.ast_id.file_id); + if item_tree.inner_items_of_block(block.ast_id.value).is_empty() { + return parent.clone(); + } let block_info = BlockInfo { block: block_id, parent, parent_module: block.module.local_id }; -- cgit v1.2.3