Skip to content

Commit

Permalink
Generate StorageLive after DropAndReplace for locals
Browse files Browse the repository at this point in the history
  • Loading branch information
tmandry committed May 22, 2019
1 parent 26c37d7 commit 201b464
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/librustc_mir/transform/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc::mir::*;
use rustc::util::nodemap::FxHashMap;
use rustc_data_structures::bit_set::BitSet;
use std::fmt;
use std::iter;
use syntax_pos::Span;

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

let storage_live = match location {
Place::Base(PlaceBase::Local(local)) => Some(Statement {
kind: StatementKind::StorageLive(*local),
source_info: terminator.source_info
}),
_ => None,
};
let assign = Statement {
kind: StatementKind::Assign(location.clone(), box Rvalue::Use(value.clone())),
source_info: terminator.source_info
};
let statements = storage_live.into_iter().chain(iter::once(assign)).collect::<Vec<_>>();

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

let target = self.patch.new_block(BasicBlockData {
statements: vec![assign],
statements,
terminator: Some(Terminator {
kind: TerminatorKind::Goto { target },
..*terminator
Expand Down

0 comments on commit 201b464

Please sign in to comment.