Skip to content

Commit ae6479c

Browse files
committed
Move comments for fake reads where the causes are defined
1 parent ab236df commit ae6479c

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

src/librustc/mir/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,25 @@ pub enum StatementKind<'tcx> {
16671667
/// The `FakeReadCause` describes the type of pattern why a `FakeRead` statement exists.
16681668
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)]
16691669
pub enum FakeReadCause {
1670+
/// Inject a fake read of the borrowed input at the start of each arm's
1671+
/// pattern testing code.
1672+
///
1673+
/// This should ensure that you cannot change the variant for an enum
1674+
/// while you are in the midst of matching on it.
16701675
ForMatch,
1676+
1677+
/// Officially, the semantics of
1678+
///
1679+
/// `let pattern = <expr>;`
1680+
///
1681+
/// is that `<expr>` is evaluated into a temporary and then this temporary is
1682+
/// into the pattern.
1683+
///
1684+
/// However, if we see the simple pattern `let var = <expr>`, we optimize this to
1685+
/// evaluate `<expr>` directly into the variable `var`. This is mostly unobservable,
1686+
/// but in some cases it can affect the borrow checker, as in #53695.
1687+
/// Therefore, we insert a "fake read" here to ensure that we get
1688+
/// appropriate errors.
16711689
ForLet,
16721690
}
16731691

src/librustc_mir/build/matches/mod.rs

+7-24
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,16 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
145145
if let (true, Some(borrow_temp)) =
146146
(tcx.emit_read_for_match(), borrowed_input_temp.clone())
147147
{
148-
// inject a fake read of the borrowed input at
149-
// the start of each arm's pattern testing
150-
// code.
151-
//
152-
// This should ensure that you cannot change
153-
// the variant for an enum while you are in
154-
// the midst of matching on it.
148+
// Inject a fake read, see comments on `FakeReadCause::ForMatch`.
155149
let pattern_source_info = self.source_info(pattern.span);
156150
self.cfg.push(
157151
*pre_binding_block,
158152
Statement {
159153
source_info: pattern_source_info,
160-
kind: StatementKind::FakeRead(FakeReadCause::ForMatch, borrow_temp.clone()),
154+
kind: StatementKind::FakeRead(
155+
FakeReadCause::ForMatch,
156+
borrow_temp.clone(),
157+
),
161158
},
162159
);
163160
}
@@ -266,19 +263,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
266263
unpack!(block = self.into(&place, block, initializer));
267264

268265

269-
// Officially, the semantics of
270-
//
271-
// `let pattern = <expr>;`
272-
//
273-
// is that `<expr>` is evaluated into a temporary and then this temporary is
274-
// into the pattern.
275-
//
276-
// However, if we see the simple pattern `let var = <expr>`, we optimize this to
277-
// evaluate `<expr>` directly into the variable `var`. This is mostly unobservable,
278-
// but in some cases it can affect the borrow checker, as in #53695.
279-
// Therefore, we insert a "fake read" here to ensure that we get
280-
// appropriate errors.
281-
//
266+
// Inject a fake read, see comments on `FakeReadCause::ForLet`.
282267
let source_info = self.source_info(irrefutable_pat.span);
283268
self.cfg.push(
284269
block,
@@ -329,9 +314,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
329314
},
330315
);
331316

332-
// Similarly to the `let var = <expr>` case, we insert a "fake read" here to
333-
// ensure that we get appropriate errors when this usually unobservable
334-
// optimization affects the borrow checker.
317+
// Inject a fake read, see comments on `FakeReadCause::ForLet`.
335318
self.cfg.push(
336319
block,
337320
Statement {

0 commit comments

Comments
 (0)