Skip to content

Commit

Permalink
Rollup merge of rust-lang#67325 - Centril:push-fake-read, r=matthewja…
Browse files Browse the repository at this point in the history
…sper

cleanup with push_fake_read

...and make things a bit more readable.

r? @matthewjasper
  • Loading branch information
Centril authored Dec 16, 2019
2 parents 9f0cb17 + 2d96f20 commit 71a9a99
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 48 deletions.
12 changes: 12 additions & 0 deletions src/librustc_mir/build/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 2 additions & 11 deletions src/librustc_mir/build/expr/as_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,24 +484,15 @@ 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,
) {
// All indexes have been evaluated now, read all of the
// 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));
}
}
}
46 changes: 9 additions & 37 deletions src/librustc_mir/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,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.

Expand Down Expand Up @@ -313,16 +308,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()
Expand Down Expand Up @@ -358,13 +346,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(
Expand Down Expand Up @@ -1515,13 +1498,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(
Expand Down Expand Up @@ -1564,14 +1542,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,
Expand Down

0 comments on commit 71a9a99

Please sign in to comment.