Skip to content

Commit 71a9a99

Browse files
authored
Rollup merge of #67325 - Centril:push-fake-read, r=matthewjasper
cleanup with push_fake_read ...and make things a bit more readable. r? @matthewjasper
2 parents 9f0cb17 + 2d96f20 commit 71a9a99

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
@@ -131,13 +131,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
131131
// check safety.
132132

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

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

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

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

327315
self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard);
328316
block.unit()
@@ -358,13 +346,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
358346

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

369352
let ty_source_info = self.source_info(user_ty_span);
370353
let user_ty = pat_ascription_ty.user_ty(
@@ -1515,13 +1498,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15151498
);
15161499

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

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

0 commit comments

Comments
 (0)