diff --git a/compiler/rustc_middle/src/middle/region.rs b/compiler/rustc_middle/src/middle/region.rs index 7abf70e43a146..45978ae19d452 100644 --- a/compiler/rustc_middle/src/middle/region.rs +++ b/compiler/rustc_middle/src/middle/region.rs @@ -228,7 +228,7 @@ pub struct ScopeTree { var_map: FxHashMap, /// Maps from a `NodeId` to the associated destruction scope (if any). - destruction_scopes: FxHashMap<(hir::ItemLocalId, bool), Scope>, + destruction_scopes: FxHashMap, /// `rvalue_scopes` includes entries for those expressions whose /// cleanup scope is larger than the default. The map goes from the @@ -341,15 +341,12 @@ impl ScopeTree { // Record the destruction scopes for later so we can query them. if let ScopeData::Destruction = child.data { - assert_eq!( - self.destruction_scopes.insert((child.item_local_id(), child.for_stmt), child), - None - ); + assert_eq!(self.destruction_scopes.insert(child.item_local_id(), child), None); } } - pub fn opt_destruction_scope(&self, n: hir::ItemLocalId, for_stmt: bool) -> Option { - self.destruction_scopes.get(&(n, for_stmt)).cloned() + pub fn opt_destruction_scope(&self, n: hir::ItemLocalId) -> Option { + self.destruction_scopes.get(&n).cloned() } pub fn record_var_scope(&mut self, var: hir::ItemLocalId, lifetime: Scope) { diff --git a/compiler/rustc_mir_build/src/thir/cx/block.rs b/compiler/rustc_mir_build/src/thir/cx/block.rs index b27406ea0467f..31a54263ff8ca 100644 --- a/compiler/rustc_mir_build/src/thir/cx/block.rs +++ b/compiler/rustc_mir_build/src/thir/cx/block.rs @@ -13,7 +13,7 @@ impl<'tcx> Cx<'tcx> { // in order to get the lexical scoping correctly. let stmts = self.mirror_stmts(block.hir_id.local_id, block.stmts); let opt_destruction_scope = - self.region_scope_tree.opt_destruction_scope(block.hir_id.local_id, false); + self.region_scope_tree.opt_destruction_scope(block.hir_id.local_id); Block { targeted_by_break: block.targeted_by_break, region_scope: region::Scope { @@ -47,8 +47,11 @@ impl<'tcx> Cx<'tcx> { .enumerate() .filter_map(|(index, stmt)| { let hir_id = stmt.kind.hir_id(); - let opt_dxn_ext = - self.region_scope_tree.opt_destruction_scope(hir_id.local_id, true); + let dxn_scope = region::Scope { + id: hir_id.local_id, + data: region::ScopeData::Destruction, + for_stmt: true, + }; match stmt.kind { hir::StmtKind::Expr(ref expr) | hir::StmtKind::Semi(ref expr) => { let stmt = Stmt { @@ -60,7 +63,7 @@ impl<'tcx> Cx<'tcx> { }, expr: self.mirror_expr(expr), }, - opt_destruction_scope: opt_dxn_ext, + opt_destruction_scope: Some(dxn_scope), }; Some(self.thir.stmts.push(stmt)) } @@ -111,7 +114,7 @@ impl<'tcx> Cx<'tcx> { initializer: local.init.map(|init| self.mirror_expr(init)), lint_level: LintLevel::Explicit(local.hir_id), }, - opt_destruction_scope: opt_dxn_ext, + opt_destruction_scope: Some(dxn_scope), }; Some(self.thir.stmts.push(stmt)) } diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 4627ba36670fc..033555d1c477d 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -62,7 +62,7 @@ impl<'tcx> Cx<'tcx> { // Finally, create a destruction scope, if any. if let Some(region_scope) = - self.region_scope_tree.opt_destruction_scope(hir_expr.hir_id.local_id, false) + self.region_scope_tree.opt_destruction_scope(hir_expr.hir_id.local_id) { expr = Expr { temp_lifetime,