Skip to content

Commit ea0b13c

Browse files
committed
Create dtor scope for locals
1 parent 0534576 commit ea0b13c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

compiler/rustc_passes/src/region.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashSet;
1111
use rustc_hir as hir;
1212
use rustc_hir::def_id::DefId;
1313
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
14-
use rustc_hir::{Arm, Block, Expr, Local, Node, Pat, PatKind, Stmt};
14+
use rustc_hir::{Arm, Block, Expr, Local, Node, Pat, PatKind, Stmt, HirId};
1515
use rustc_index::vec::Idx;
1616
use rustc_middle::middle::region::*;
1717
use rustc_middle::ty::query::Providers;
@@ -432,6 +432,7 @@ fn resolve_local<'tcx>(
432432
visitor: &mut RegionResolutionVisitor<'tcx>,
433433
pat: Option<&'tcx hir::Pat<'tcx>>,
434434
init: Option<&'tcx hir::Expr<'tcx>>,
435+
local_hir_id: Option<HirId>,
435436
) {
436437
debug!("resolve_local(pat={:?}, init={:?})", pat, init);
437438

@@ -493,6 +494,10 @@ fn resolve_local<'tcx>(
493494
// A, but the inner rvalues `a()` and `b()` have an extended lifetime
494495
// due to rule C.
495496

497+
if let Some(hir_id) = local_hir_id {
498+
visitor.enter_node_scope_with_dtor(hir_id.local_id);
499+
}
500+
496501
if let Some(expr) = init {
497502
record_rvalue_scope_if_borrow_expr(visitor, &expr, blk_scope);
498503

@@ -767,7 +772,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
767772
// (i.e., `'static`), which means that after `g` returns, it drops,
768773
// and all the associated destruction scope rules apply.
769774
self.cx.var_parent = None;
770-
resolve_local(self, None, Some(&body.value));
775+
resolve_local(self, None, Some(&body.value), None);
771776
}
772777

773778
if body.generator_kind.is_some() {
@@ -794,7 +799,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
794799
resolve_expr(self, ex);
795800
}
796801
fn visit_local(&mut self, l: &'tcx Local<'tcx>) {
797-
resolve_local(self, Some(&l.pat), l.init.as_deref());
802+
resolve_local(self, Some(&l.pat), l.init.as_deref(), Some(l.hir_id));
798803
}
799804
}
800805

0 commit comments

Comments
 (0)