From 9b13e1bb918888af0c456c554235e9a981d2ba0c Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 4 Apr 2021 03:16:26 +0200 Subject: Only remember blocks that have a DefMap --- crates/hir_def/src/body.rs | 2 +- crates/hir_def/src/body/lower.rs | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'crates/hir_def/src') diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index ad3d5afbe..99d98b17e 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs @@ -317,7 +317,7 @@ impl Body { ) -> impl Iterator)> + '_ { self.block_scopes .iter() - .filter_map(move |block| db.block_def_map(*block).map(|map| (*block, map))) + .map(move |block| (*block, db.block_def_map(*block).expect("block ID without DefMap"))) } fn new( diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 229e81dd4..63e89a1f4 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -673,12 +673,14 @@ 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()); - let module = if has_def_map { def_map.root() } else { self.expander.module }; + let (module, def_map) = match self.db.block_def_map(block_id) { + Some(def_map) => { + self.body.block_scopes.push(block_id); + (def_map.root(), def_map) + } + None => (self.expander.module, self.expander.def_map.clone()), + }; let prev_def_map = mem::replace(&mut self.expander.def_map, def_map); let prev_local_module = mem::replace(&mut self.expander.module, module); let prev_statements = std::mem::take(&mut self.statements_in_scope); -- cgit v1.2.3