Skip to content

Commit cd8eedf

Browse files
committed
Simplify terminating_scopes
1 parent a404da8 commit cd8eedf

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

compiler/rustc_passes/src/region.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct RegionResolutionVisitor<'tcx> {
6767
/// arbitrary amounts of stack space. Terminating scopes end
6868
/// up being contained in a DestructionScope that contains the
6969
/// destructor's execution.
70-
terminating_scopes: FxHashSet<(hir::ItemLocalId, bool)>,
70+
terminating_scopes: FxHashSet<hir::ItemLocalId>,
7171
}
7272

7373
/// Records the lifetime of a local variable as `cx.var_parent`
@@ -116,7 +116,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
116116
// `other_argument()` has run and also the call to `quux(..)`
117117
// itself has returned.
118118

119-
visitor.enter_node_scope_with_dtor(blk.hir_id.local_id, false);
119+
visitor.enter_node_scope_with_dtor(blk.hir_id.local_id);
120120
visitor.cx.var_parent = visitor.cx.parent;
121121

122122
{
@@ -157,10 +157,10 @@ fn resolve_arm<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, arm: &'tcx hir
157157
visitor.enter_scope(Scope { id: arm.hir_id.local_id, data: ScopeData::Node, for_stmt: false });
158158
visitor.cx.var_parent = visitor.cx.parent;
159159

160-
visitor.terminating_scopes.insert((arm.body.hir_id.local_id, false));
160+
visitor.terminating_scopes.insert(arm.body.hir_id.local_id);
161161

162162
if let Some(hir::Guard::If(ref expr)) = arm.guard {
163-
visitor.terminating_scopes.insert((expr.hir_id.local_id, false));
163+
visitor.terminating_scopes.insert(expr.hir_id.local_id);
164164
}
165165

166166
intravisit::walk_arm(visitor, arm);
@@ -203,9 +203,9 @@ fn resolve_stmt<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, stmt: &'tcx h
203203

204204
match &stmt.kind {
205205
kind @ (hir::StmtKind::Local(_) | hir::StmtKind::Expr(_) | hir::StmtKind::Semi(_)) => {
206-
let local_id = kind.hir_id().local_id;
207-
visitor.terminating_scopes.insert((local_id, true));
208-
visitor.enter_node_scope_with_dtor(local_id, true);
206+
let id = kind.hir_id().local_id;
207+
visitor.enter_scope(Scope { id, data: ScopeData::Destruction, for_stmt: true });
208+
visitor.enter_scope(Scope { id, data: ScopeData::Node, for_stmt: true });
209209
}
210210
hir::StmtKind::Item(_) => {}
211211
}
@@ -219,12 +219,12 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
219219
debug!("resolve_expr - pre-increment {} expr = {:?}", visitor.expr_and_pat_count, expr);
220220

221221
let prev_cx = visitor.cx;
222-
visitor.enter_node_scope_with_dtor(expr.hir_id.local_id, false);
222+
visitor.enter_node_scope_with_dtor(expr.hir_id.local_id);
223223

224224
{
225225
let terminating_scopes = &mut visitor.terminating_scopes;
226226
let mut terminating = |id: hir::ItemLocalId| {
227-
terminating_scopes.insert((id, false));
227+
terminating_scopes.insert(id);
228228
};
229229
match expr.kind {
230230
// Conditional or repeating scopes are always terminating
@@ -699,15 +699,15 @@ impl<'tcx> RegionResolutionVisitor<'tcx> {
699699
self.cx.parent = Some((child_scope, child_depth));
700700
}
701701

702-
fn enter_node_scope_with_dtor(&mut self, id: hir::ItemLocalId, for_stmt: bool) {
702+
fn enter_node_scope_with_dtor(&mut self, id: hir::ItemLocalId) {
703703
// If node was previously marked as a terminating scope during the
704704
// recursive visit of its parent node in the AST, then we need to
705705
// account for the destruction scope representing the scope of
706706
// the destructors that run immediately after it completes.
707-
if self.terminating_scopes.contains(&(id, for_stmt)) {
708-
self.enter_scope(Scope { id, data: ScopeData::Destruction, for_stmt });
707+
if self.terminating_scopes.contains(&id) {
708+
self.enter_scope(Scope { id, data: ScopeData::Destruction, for_stmt: false });
709709
}
710-
self.enter_scope(Scope { id, data: ScopeData::Node, for_stmt });
710+
self.enter_scope(Scope { id, data: ScopeData::Node, for_stmt: false });
711711
}
712712
}
713713

@@ -745,7 +745,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
745745
// control flow assumptions. This doesn't apply to nested
746746
// bodies within the `+=` statements. See #69307.
747747
let outer_pessimistic_yield = mem::replace(&mut self.pessimistic_yield, false);
748-
self.terminating_scopes.insert((body.value.hir_id.local_id, false));
748+
self.terminating_scopes.insert(body.value.hir_id.local_id);
749749

750750
self.enter_scope(Scope {
751751
id: body.value.hir_id.local_id,

0 commit comments

Comments
 (0)