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

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
336336
}
337337
}
338338

339-
mir::StatementKind::ReadForMatch(..) |
339+
mir::StatementKind::FakeRead(..) |
340340
mir::StatementKind::SetDiscriminant { .. } |
341341
mir::StatementKind::StorageLive(..) |
342342
mir::StatementKind::Validate(..) |

src/librustc_mir/dataflow/move_paths/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
281281
}
282282
self.gather_rvalue(rval);
283283
}
284-
StatementKind::ReadForMatch(ref place) => {
284+
StatementKind::FakeRead(_, ref place) => {
285285
self.create_move_path(place);
286286
}
287287
StatementKind::InlineAsm { ref outputs, ref inputs, ref asm } => {

src/librustc_mir/interpret/step.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
150150
self.deallocate_local(old_val)?;
151151
}
152152

153-
// No dynamic semantics attached to `ReadForMatch`; MIR
153+
// No dynamic semantics attached to `FakeRead`; MIR
154154
// interpreter is solely intended for borrowck'ed code.
155-
ReadForMatch(..) => {}
155+
FakeRead(..) => {}
156156

157157
// Validity checks.
158158
Validate(op, ref places) => {

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
108108
self.source_info = statement.source_info;
109109
match statement.kind {
110110
StatementKind::Assign(..) |
111-
StatementKind::ReadForMatch(..) |
111+
StatementKind::FakeRead(..) |
112112
StatementKind::SetDiscriminant { .. } |
113113
StatementKind::StorageLive(..) |
114114
StatementKind::StorageDead(..) |

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
10901090
StatementKind::Assign(ref place, ref rvalue) => {
10911091
this.visit_assign(bb, place, rvalue, location);
10921092
}
1093-
StatementKind::ReadForMatch(..) |
1093+
StatementKind::FakeRead(..) |
10941094
StatementKind::SetDiscriminant { .. } |
10951095
StatementKind::StorageLive(_) |
10961096
StatementKind::StorageDead(_) |

src/librustc_mir/transform/qualify_min_const_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn check_statement(
216216
check_rvalue(tcx, mir, rval, span)
217217
}
218218

219-
StatementKind::ReadForMatch(_) => Err((span, "match in const fn is unstable".into())),
219+
StatementKind::FakeRead(..) => Err((span, "match in const fn is unstable".into())),
220220

221221
// just an assignment
222222
StatementKind::SetDiscriminant { .. } => Ok(()),

src/librustc_mir/transform/remove_noop_landing_pads.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl RemoveNoopLandingPads {
4949
) -> bool {
5050
for stmt in &mir[bb].statements {
5151
match stmt.kind {
52-
StatementKind::ReadForMatch(_) |
52+
StatementKind::FakeRead(..) |
5353
StatementKind::StorageLive(_) |
5454
StatementKind::StorageDead(_) |
5555
StatementKind::EndRegion(_) |

src/librustc_mir/transform/rustc_peek.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
157157
mir::StatementKind::Assign(ref place, ref rvalue) => {
158158
(place, rvalue)
159159
}
160-
mir::StatementKind::ReadForMatch(_) |
160+
mir::StatementKind::FakeRead(..) |
161161
mir::StatementKind::StorageLive(_) |
162162
mir::StatementKind::StorageDead(_) |
163163
mir::StatementKind::InlineAsm { .. } |

src/librustc_passes/mir_stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
8282
self.record("Statement", statement);
8383
self.record(match statement.kind {
8484
StatementKind::Assign(..) => "StatementKind::Assign",
85-
StatementKind::ReadForMatch(..) => "StatementKind::ReadForMatch",
85+
StatementKind::FakeRead(..) => "StatementKind::FakeRead",
8686
StatementKind::EndRegion(..) => "StatementKind::EndRegion",
8787
StatementKind::Validate(..) => "StatementKind::Validate",
8888
StatementKind::SetDiscriminant { .. } => "StatementKind::SetDiscriminant",

0 commit comments

Comments
 (0)