Skip to content

Commit 201b464

Browse files
committed
Generate StorageLive after DropAndReplace for locals
1 parent 26c37d7 commit 201b464

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Diff for: src/librustc_mir/transform/elaborate_drops.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc::mir::*;
1616
use rustc::util::nodemap::FxHashMap;
1717
use rustc_data_structures::bit_set::BitSet;
1818
use std::fmt;
19+
use std::iter;
1920
use syntax_pos::Span;
2021

2122
pub struct ElaborateDrops;
@@ -468,14 +469,22 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
468469
let terminator = data.terminator();
469470
assert!(!data.is_cleanup, "DropAndReplace in unwind path not supported");
470471

472+
let storage_live = match location {
473+
Place::Base(PlaceBase::Local(local)) => Some(Statement {
474+
kind: StatementKind::StorageLive(*local),
475+
source_info: terminator.source_info
476+
}),
477+
_ => None,
478+
};
471479
let assign = Statement {
472480
kind: StatementKind::Assign(location.clone(), box Rvalue::Use(value.clone())),
473481
source_info: terminator.source_info
474482
};
483+
let statements = storage_live.into_iter().chain(iter::once(assign)).collect::<Vec<_>>();
475484

476485
let unwind = unwind.unwrap_or_else(|| self.patch.resume_block());
477486
let unwind = self.patch.new_block(BasicBlockData {
478-
statements: vec![assign.clone()],
487+
statements: statements.clone(),
479488
terminator: Some(Terminator {
480489
kind: TerminatorKind::Goto { target: unwind },
481490
..*terminator
@@ -484,7 +493,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
484493
});
485494

486495
let target = self.patch.new_block(BasicBlockData {
487-
statements: vec![assign],
496+
statements,
488497
terminator: Some(Terminator {
489498
kind: TerminatorKind::Goto { target },
490499
..*terminator

0 commit comments

Comments
 (0)