Skip to content

Commit a404da8

Browse files
committed
Store less information for destruction scopes
1 parent 85afbb0 commit a404da8

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

compiler/rustc_middle/src/middle/region.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ pub struct ScopeTree {
228228
var_map: FxHashMap<hir::ItemLocalId, Scope>,
229229

230230
/// Maps from a `NodeId` to the associated destruction scope (if any).
231-
destruction_scopes: FxHashMap<(hir::ItemLocalId, bool), Scope>,
231+
destruction_scopes: FxHashMap<hir::ItemLocalId, Scope>,
232232

233233
/// `rvalue_scopes` includes entries for those expressions whose
234234
/// cleanup scope is larger than the default. The map goes from the
@@ -341,15 +341,12 @@ impl ScopeTree {
341341

342342
// Record the destruction scopes for later so we can query them.
343343
if let ScopeData::Destruction = child.data {
344-
assert_eq!(
345-
self.destruction_scopes.insert((child.item_local_id(), child.for_stmt), child),
346-
None
347-
);
344+
assert_eq!(self.destruction_scopes.insert(child.item_local_id(), child), None);
348345
}
349346
}
350347

351-
pub fn opt_destruction_scope(&self, n: hir::ItemLocalId, for_stmt: bool) -> Option<Scope> {
352-
self.destruction_scopes.get(&(n, for_stmt)).cloned()
348+
pub fn opt_destruction_scope(&self, n: hir::ItemLocalId) -> Option<Scope> {
349+
self.destruction_scopes.get(&n).cloned()
353350
}
354351

355352
pub fn record_var_scope(&mut self, var: hir::ItemLocalId, lifetime: Scope) {

compiler/rustc_mir_build/src/thir/cx/block.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl<'tcx> Cx<'tcx> {
1313
// in order to get the lexical scoping correctly.
1414
let stmts = self.mirror_stmts(block.hir_id.local_id, block.stmts);
1515
let opt_destruction_scope =
16-
self.region_scope_tree.opt_destruction_scope(block.hir_id.local_id, false);
16+
self.region_scope_tree.opt_destruction_scope(block.hir_id.local_id);
1717
Block {
1818
targeted_by_break: block.targeted_by_break,
1919
region_scope: region::Scope {
@@ -47,8 +47,11 @@ impl<'tcx> Cx<'tcx> {
4747
.enumerate()
4848
.filter_map(|(index, stmt)| {
4949
let hir_id = stmt.kind.hir_id();
50-
let opt_dxn_ext =
51-
self.region_scope_tree.opt_destruction_scope(hir_id.local_id, true);
50+
let dxn_scope = region::Scope {
51+
id: hir_id.local_id,
52+
data: region::ScopeData::Destruction,
53+
for_stmt: true,
54+
};
5255
match stmt.kind {
5356
hir::StmtKind::Expr(ref expr) | hir::StmtKind::Semi(ref expr) => {
5457
let stmt = Stmt {
@@ -60,7 +63,7 @@ impl<'tcx> Cx<'tcx> {
6063
},
6164
expr: self.mirror_expr(expr),
6265
},
63-
opt_destruction_scope: opt_dxn_ext,
66+
opt_destruction_scope: Some(dxn_scope),
6467
};
6568
Some(self.thir.stmts.push(stmt))
6669
}
@@ -111,7 +114,7 @@ impl<'tcx> Cx<'tcx> {
111114
initializer: local.init.map(|init| self.mirror_expr(init)),
112115
lint_level: LintLevel::Explicit(local.hir_id),
113116
},
114-
opt_destruction_scope: opt_dxn_ext,
117+
opt_destruction_scope: Some(dxn_scope),
115118
};
116119
Some(self.thir.stmts.push(stmt))
117120
}

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'tcx> Cx<'tcx> {
6262

6363
// Finally, create a destruction scope, if any.
6464
if let Some(region_scope) =
65-
self.region_scope_tree.opt_destruction_scope(hir_expr.hir_id.local_id, false)
65+
self.region_scope_tree.opt_destruction_scope(hir_expr.hir_id.local_id)
6666
{
6767
expr = Expr {
6868
temp_lifetime,

0 commit comments

Comments
 (0)