From 13f4356d2f05c79a01e55b1bdd91d9a2dcf9c6f2 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 5 Mar 2021 14:08:23 +0100 Subject: Store inner `BlockId`s in `Body` --- crates/hir_def/src/body.rs | 4 +++- crates/hir_def/src/body/lower.rs | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index b1a3fe1cb..9dbe717e5 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs @@ -32,7 +32,7 @@ use crate::{ 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 d4abe819d..c3aa1dc37 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 @@ impl ExprCollector<'_> { 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()); -- cgit v1.2.3