diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index b1a3fe1cb8b..9dbe717e503 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs @@ -32,7 +32,7 @@ nameres::DefMap, path::{ModPath, Path}, src::HasSource, - AsMacroCall, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleId, + AsMacroCall, BlockId, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleId, }; /// A subset of Expander that only deals with cfg attributes. We only need it to @@ -226,6 +226,8 @@ pub struct Body { pub params: Vec, /// The `ExprId` of the actual body expression. pub body_expr: ExprId, + /// Block expressions in this body that may contain inner items. + pub block_scopes: Vec, pub item_scope: ItemScope, _c: Count, } diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index d4abe819d37..c3aa1dc37cd 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -76,6 +76,7 @@ pub(super) fn lower( labels: Arena::default(), params: Vec::new(), body_expr: dummy_expr_id(), + block_scopes: Vec::new(), item_scope: Default::default(), _c: Count::new(), }, @@ -700,6 +701,8 @@ fn collect_block(&mut self, block: ast::BlockExpr) -> ExprId { let block_loc = BlockLoc { ast_id, module: self.expander.def_map.module_id(self.expander.module) }; let block_id = self.db.intern_block(block_loc); + self.body.block_scopes.push(block_id); + let opt_def_map = self.db.block_def_map(block_id); let has_def_map = opt_def_map.is_some(); let def_map = opt_def_map.unwrap_or_else(|| self.expander.def_map.clone());