Skip to content

Commit 2d96f20

Browse files
committed
cleanup with push_fake_read
1 parent a605441 commit 2d96f20

File tree

3 files changed

+23
-48
lines changed

3 files changed

+23
-48
lines changed

src/librustc_mir/build/cfg.rs

+12
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ impl<'tcx> CFG<'tcx> {
5959
));
6060
}
6161

62+
pub fn push_fake_read(
63+
&mut self,
64+
block: BasicBlock,
65+
source_info: SourceInfo,
66+
cause: FakeReadCause,
67+
place: Place<'tcx>,
68+
) {
69+
let kind = StatementKind::FakeRead(cause, box place);
70+
let stmt = Statement { source_info, kind };
71+
self.push(block, stmt);
72+
}
73+
6274
pub fn terminate(&mut self,
6375
block: BasicBlock,
6476
source_info: SourceInfo,

src/librustc_mir/build/expr/as_place.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -484,24 +484,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
484484

485485
fn read_fake_borrows(
486486
&mut self,
487-
block: BasicBlock,
487+
bb: BasicBlock,
488488
fake_borrow_temps: &mut Vec<Local>,
489489
source_info: SourceInfo,
490490
) {
491491
// All indexes have been evaluated now, read all of the
492492
// fake borrows so that they are live across those index
493493
// expressions.
494494
for temp in fake_borrow_temps {
495-
self.cfg.push(
496-
block,
497-
Statement {
498-
source_info,
499-
kind: StatementKind::FakeRead(
500-
FakeReadCause::ForIndex,
501-
Box::new(Place::from(*temp)),
502-
)
503-
}
504-
);
495+
self.cfg.push_fake_read(bb, source_info, FakeReadCause::ForIndex, Place::from(*temp));
505496
}
506497
}
507498
}

src/librustc_mir/build/matches/mod.rs

+9-37
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
132132
// check safety.
133133

134134
let source_info = self.source_info(scrutinee_span);
135-
self.cfg.push(block, Statement {
136-
source_info,
137-
kind: StatementKind::FakeRead(
138-
FakeReadCause::ForMatchedPlace,
139-
box(scrutinee_place.clone()),
140-
),
141-
});
135+
let cause_matched_place = FakeReadCause::ForMatchedPlace;
136+
self.cfg.push_fake_read(block, source_info, cause_matched_place, scrutinee_place.clone());
142137

143138
// Step 2. Create the otherwise and prebinding blocks.
144139

@@ -314,16 +309,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
314309
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard);
315310
unpack!(block = self.into(&place, block, initializer));
316311

317-
318312
// Inject a fake read, see comments on `FakeReadCause::ForLet`.
319313
let source_info = self.source_info(irrefutable_pat.span);
320-
self.cfg.push(
321-
block,
322-
Statement {
323-
source_info,
324-
kind: StatementKind::FakeRead(FakeReadCause::ForLet, box(place)),
325-
},
326-
);
314+
self.cfg.push_fake_read(block, source_info, FakeReadCause::ForLet, place);
327315

328316
self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard);
329317
block.unit()
@@ -359,13 +347,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
359347

360348
// Inject a fake read, see comments on `FakeReadCause::ForLet`.
361349
let pattern_source_info = self.source_info(irrefutable_pat.span);
362-
self.cfg.push(
363-
block,
364-
Statement {
365-
source_info: pattern_source_info,
366-
kind: StatementKind::FakeRead(FakeReadCause::ForLet, box(place.clone())),
367-
},
368-
);
350+
let cause_let = FakeReadCause::ForLet;
351+
self.cfg.push_fake_read(block, pattern_source_info, cause_let, place.clone());
369352

370353
let ty_source_info = self.source_info(user_ty_span);
371354
let user_ty = pat_ascription_ty.user_ty(
@@ -1516,13 +1499,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15161499
);
15171500

15181501
for &(_, temp) in fake_borrows {
1519-
self.cfg.push(post_guard_block, Statement {
1520-
source_info: guard_end,
1521-
kind: StatementKind::FakeRead(
1522-
FakeReadCause::ForMatchGuard,
1523-
box(Place::from(temp)),
1524-
),
1525-
});
1502+
let cause = FakeReadCause::ForMatchGuard;
1503+
self.cfg.push_fake_read(post_guard_block, guard_end, cause, Place::from(temp));
15261504
}
15271505

15281506
self.exit_scope(
@@ -1565,14 +1543,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15651543
// place they refer to can't be modified by the guard.
15661544
for binding in by_value_bindings.clone() {
15671545
let local_id = self.var_local_id(binding.var_id, RefWithinGuard);
1568-
let place = Place::from(local_id);
1569-
self.cfg.push(
1570-
post_guard_block,
1571-
Statement {
1572-
source_info: guard_end,
1573-
kind: StatementKind::FakeRead(FakeReadCause::ForGuardBinding, box(place)),
1574-
},
1575-
);
1546+
let cause = FakeReadCause::ForGuardBinding;
1547+
self.cfg.push_fake_read(post_guard_block, guard_end, cause, Place::from(local_id));
15761548
}
15771549
self.bind_matched_candidate_for_arm_body(
15781550
post_guard_block,

0 commit comments

Comments
 (0)