1
Fork 0

cleanup with push_fake_read

This commit is contained in:
Mazdak Farrokhzad 2019-12-15 16:11:01 +01:00
parent a605441e04
commit 2d96f2097f
3 changed files with 23 additions and 48 deletions

View file

@ -59,6 +59,18 @@ impl<'tcx> CFG<'tcx> {
));
}
pub fn push_fake_read(
&mut self,
block: BasicBlock,
source_info: SourceInfo,
cause: FakeReadCause,
place: Place<'tcx>,
) {
let kind = StatementKind::FakeRead(cause, box place);
let stmt = Statement { source_info, kind };
self.push(block, stmt);
}
pub fn terminate(&mut self,
block: BasicBlock,
source_info: SourceInfo,

View file

@ -484,7 +484,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn read_fake_borrows(
&mut self,
block: BasicBlock,
bb: BasicBlock,
fake_borrow_temps: &mut Vec<Local>,
source_info: SourceInfo,
) {
@ -492,16 +492,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// fake borrows so that they are live across those index
// expressions.
for temp in fake_borrow_temps {
self.cfg.push(
block,
Statement {
source_info,
kind: StatementKind::FakeRead(
FakeReadCause::ForIndex,
Box::new(Place::from(*temp)),
)
}
);
self.cfg.push_fake_read(bb, source_info, FakeReadCause::ForIndex, Place::from(*temp));
}
}
}

View file

@ -132,13 +132,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// check safety.
let source_info = self.source_info(scrutinee_span);
self.cfg.push(block, Statement {
source_info,
kind: StatementKind::FakeRead(
FakeReadCause::ForMatchedPlace,
box(scrutinee_place.clone()),
),
});
let cause_matched_place = FakeReadCause::ForMatchedPlace;
self.cfg.push_fake_read(block, source_info, cause_matched_place, scrutinee_place.clone());
// Step 2. Create the otherwise and prebinding blocks.
@ -314,16 +309,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard);
unpack!(block = self.into(&place, block, initializer));
// Inject a fake read, see comments on `FakeReadCause::ForLet`.
let source_info = self.source_info(irrefutable_pat.span);
self.cfg.push(
block,
Statement {
source_info,
kind: StatementKind::FakeRead(FakeReadCause::ForLet, box(place)),
},
);
self.cfg.push_fake_read(block, source_info, FakeReadCause::ForLet, place);
self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard);
block.unit()
@ -359,13 +347,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Inject a fake read, see comments on `FakeReadCause::ForLet`.
let pattern_source_info = self.source_info(irrefutable_pat.span);
self.cfg.push(
block,
Statement {
source_info: pattern_source_info,
kind: StatementKind::FakeRead(FakeReadCause::ForLet, box(place.clone())),
},
);
let cause_let = FakeReadCause::ForLet;
self.cfg.push_fake_read(block, pattern_source_info, cause_let, place.clone());
let ty_source_info = self.source_info(user_ty_span);
let user_ty = pat_ascription_ty.user_ty(
@ -1516,13 +1499,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
);
for &(_, temp) in fake_borrows {
self.cfg.push(post_guard_block, Statement {
source_info: guard_end,
kind: StatementKind::FakeRead(
FakeReadCause::ForMatchGuard,
box(Place::from(temp)),
),
});
let cause = FakeReadCause::ForMatchGuard;
self.cfg.push_fake_read(post_guard_block, guard_end, cause, Place::from(temp));
}
self.exit_scope(
@ -1565,14 +1543,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// place they refer to can't be modified by the guard.
for binding in by_value_bindings.clone() {
let local_id = self.var_local_id(binding.var_id, RefWithinGuard);
let place = Place::from(local_id);
self.cfg.push(
post_guard_block,
Statement {
source_info: guard_end,
kind: StatementKind::FakeRead(FakeReadCause::ForGuardBinding, box(place)),
},
);
let cause = FakeReadCause::ForGuardBinding;
self.cfg.push_fake_read(post_guard_block, guard_end, cause, Place::from(local_id));
}
self.bind_matched_candidate_for_arm_body(
post_guard_block,