Skip to content

Commit f5e3105

Browse files
committed
Refactor 'ReadForMatch' into 'FakeRead' and add the cause of the fake read
1 parent 52b5362 commit f5e3105

File tree

19 files changed

+41
-28
lines changed

19 files changed

+41
-28
lines changed

src/librustc/ich/impls_mir.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ for mir::StatementKind<'gcx> {
238238
place.hash_stable(hcx, hasher);
239239
rvalue.hash_stable(hcx, hasher);
240240
}
241-
mir::StatementKind::ReadForMatch(ref place) => {
241+
mir::StatementKind::FakeRead(ref cause, ref place) => {
242+
cause.hash_stable(hcx, hasher);
242243
place.hash_stable(hcx, hasher);
243244
}
244245
mir::StatementKind::SetDiscriminant { ref place, variant_index } => {
@@ -271,6 +272,8 @@ for mir::StatementKind<'gcx> {
271272
}
272273
}
273274

275+
impl_stable_hash_for!(enum mir::FakeReadCause { ForMatch, ForLet });
276+
274277
impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
275278
for mir::ValidationOperand<'gcx, T>
276279
where T: HashStable<StableHashingContext<'a>>

src/librustc/mir/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,8 +1613,10 @@ pub enum StatementKind<'tcx> {
16131613
Assign(Place<'tcx>, Rvalue<'tcx>),
16141614

16151615
/// This represents all the reading that a pattern match may do
1616-
/// (e.g. inspecting constants and discriminant values).
1617-
ReadForMatch(Place<'tcx>),
1616+
/// (e.g. inspecting constants and discriminant values), and the
1617+
/// kind of pattern it comes from. This is in order to adapt potential
1618+
/// error messages to these specific patterns.
1619+
FakeRead(FakeReadCause, Place<'tcx>),
16181620

16191621
/// Write the discriminant for a variant to the enum Place.
16201622
SetDiscriminant {
@@ -1662,6 +1664,13 @@ pub enum StatementKind<'tcx> {
16621664
Nop,
16631665
}
16641666

1667+
/// The `FakeReadCause` describes the type of pattern why a `FakeRead` statement exists.
1668+
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)]
1669+
pub enum FakeReadCause {
1670+
ForMatch,
1671+
ForLet,
1672+
}
1673+
16651674
/// The `ValidationOp` describes what happens with each of the operands of a
16661675
/// `Validate` statement.
16671676
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, PartialEq, Eq)]
@@ -1718,7 +1727,7 @@ impl<'tcx> Debug for Statement<'tcx> {
17181727
use self::StatementKind::*;
17191728
match self.kind {
17201729
Assign(ref place, ref rv) => write!(fmt, "{:?} = {:?}", place, rv),
1721-
ReadForMatch(ref place) => write!(fmt, "ReadForMatch({:?})", place),
1730+
FakeRead(ref cause, ref place) => write!(fmt, "FakeRead({:?}, {:?})", cause, place),
17221731
// (reuse lifetime rendering policy from ppaux.)
17231732
EndRegion(ref ce) => write!(fmt, "EndRegion({})", ty::ReScope(*ce)),
17241733
Validate(ref op, ref places) => write!(fmt, "Validate({:?}, {:?})", op, places),
@@ -2585,6 +2594,7 @@ CloneTypeFoldableAndLiftImpls! {
25852594
Mutability,
25862595
SourceInfo,
25872596
UpvarDecl,
2597+
FakeReadCause,
25882598
ValidationOp,
25892599
SourceScope,
25902600
SourceScopeData,
@@ -2651,7 +2661,7 @@ BraceStructTypeFoldableImpl! {
26512661
EnumTypeFoldableImpl! {
26522662
impl<'tcx> TypeFoldable<'tcx> for StatementKind<'tcx> {
26532663
(StatementKind::Assign)(a, b),
2654-
(StatementKind::ReadForMatch)(place),
2664+
(StatementKind::FakeRead)(cause, place),
26552665
(StatementKind::SetDiscriminant) { place, variant_index },
26562666
(StatementKind::StorageLive)(a),
26572667
(StatementKind::StorageDead)(a),

src/librustc/mir/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ macro_rules! make_mir_visitor {
354354
ref $($mutability)* rvalue) => {
355355
self.visit_assign(block, place, rvalue, location);
356356
}
357-
StatementKind::ReadForMatch(ref $($mutability)* place) => {
357+
StatementKind::FakeRead(_, ref $($mutability)* place) => {
358358
self.visit_place(place,
359359
PlaceContext::Inspect,
360360
location);

src/librustc/session/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
13301330
disable_nll_user_type_assert: bool = (false, parse_bool, [UNTRACKED],
13311331
"disable user provided type assertion in NLL"),
13321332
nll_dont_emit_read_for_match: bool = (false, parse_bool, [UNTRACKED],
1333-
"in match codegen, do not include ReadForMatch statements (used by mir-borrowck)"),
1333+
"in match codegen, do not include FakeRead statements (used by mir-borrowck)"),
13341334
dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED],
13351335
"emit diagnostics rather than buffering (breaks NLL error downgrading, sorting)."),
13361336
polonius: bool = (false, parse_bool, [UNTRACKED],

src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
14781478
self.emit_read_for_match()
14791479
}
14801480

1481-
/// If true, make MIR codegen for `match` emit ReadForMatch
1481+
/// If true, make MIR codegen for `match` emit FakeRead
14821482
/// statements (which simulate the maximal effect of executing the
14831483
/// patterns in a match arm).
14841484
pub fn emit_read_for_match(&self) -> bool {

src/librustc_codegen_llvm/mir/statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
8989
asm::codegen_inline_asm(&bx, asm, outputs, input_vals);
9090
bx
9191
}
92-
mir::StatementKind::ReadForMatch(_) |
92+
mir::StatementKind::FakeRead(..) |
9393
mir::StatementKind::EndRegion(_) |
9494
mir::StatementKind::Validate(..) |
9595
mir::StatementKind::AscribeUserType(..) |

src/librustc_mir/borrow_check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,9 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
478478
flow_state,
479479
);
480480
}
481-
StatementKind::ReadForMatch(ref place) => {
481+
StatementKind::FakeRead(_, ref place) => {
482482
self.access_place(
483-
ContextKind::ReadForMatch.new(location),
483+
ContextKind::FakeRead.new(location),
484484
(place, span),
485485
(Deep, Read(ReadKind::Borrow(BorrowKind::Shared))),
486486
LocalMutationIsAllowed::No,
@@ -2206,7 +2206,7 @@ enum ContextKind {
22062206
CallDest,
22072207
Assert,
22082208
Yield,
2209-
ReadForMatch,
2209+
FakeRead,
22102210
StorageDead,
22112211
}
22122212

src/librustc_mir/borrow_check/nll/invalidation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ impl<'cg, 'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cg, 'cx, 'tc
9393
JustWrite
9494
);
9595
}
96-
StatementKind::ReadForMatch(ref place) => {
96+
StatementKind::FakeRead(_, ref place) => {
9797
self.access_place(
98-
ContextKind::ReadForMatch.new(location),
98+
ContextKind::FakeRead.new(location),
9999
place,
100100
(Deep, Read(ReadKind::Borrow(BorrowKind::Shared))),
101101
LocalMutationIsAllowed::No,

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
995995
);
996996
}
997997
}
998-
StatementKind::ReadForMatch(_)
998+
StatementKind::FakeRead(..)
999999
| StatementKind::StorageLive(_)
10001000
| StatementKind::StorageDead(_)
10011001
| StatementKind::InlineAsm { .. }

src/librustc_mir/build/matches/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
157157
*pre_binding_block,
158158
Statement {
159159
source_info: pattern_source_info,
160-
kind: StatementKind::ReadForMatch(borrow_temp.clone()),
160+
kind: StatementKind::FakeRead(FakeReadCause::ForMatch, borrow_temp.clone()),
161161
},
162162
);
163163
}
@@ -284,7 +284,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
284284
block,
285285
Statement {
286286
source_info,
287-
kind: StatementKind::ReadForMatch(place.clone()),
287+
kind: StatementKind::FakeRead(FakeReadCause::ForLet, place.clone()),
288288
},
289289
);
290290

@@ -336,7 +336,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
336336
block,
337337
Statement {
338338
source_info,
339-
kind: StatementKind::ReadForMatch(place.clone()),
339+
kind: StatementKind::FakeRead(FakeReadCause::ForLet, place.clone()),
340340
},
341341
);
342342

0 commit comments

Comments
 (0)