diff --git a/src/librustc_mir/build/cfg.rs b/src/librustc_mir/build/cfg.rs index 3ed6b4ff34678..6bd8d2f7c0792 100644 --- a/src/librustc_mir/build/cfg.rs +++ b/src/librustc_mir/build/cfg.rs @@ -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, diff --git a/src/librustc_mir/build/expr/as_place.rs b/src/librustc_mir/build/expr/as_place.rs index f66f1cb73666a..ddacda72e1e65 100644 --- a/src/librustc_mir/build/expr/as_place.rs +++ b/src/librustc_mir/build/expr/as_place.rs @@ -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, 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)); } } } diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 718e8bd4e936d..bf0b2439c00b5 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -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. @@ -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() @@ -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( @@ -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( @@ -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,