@@ -265,9 +265,20 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
265
265
self . storage_live_binding ( block, var, irrefutable_pat. span , OutsideGuard ) ;
266
266
unpack ! ( block = self . into( & place, block, initializer) ) ;
267
267
268
- // Inject a fake read of the newly created binding
269
- // to test the fallout of fixing issue #53695 where NLL
270
- // allows creating unused variables that are effectively unusable.
268
+
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
+ //
271
282
let source_info = self . source_info ( irrefutable_pat. span ) ;
272
283
self . cfg . push (
273
284
block,
@@ -318,9 +329,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
318
329
} ,
319
330
) ;
320
331
321
- // Inject a fake read of the newly created binding
322
- // to test the fallout of fixing issue #53695 where NLL
323
- // allows creating unused variables that are effectively unusable .
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 .
324
335
self . cfg . push (
325
336
block,
326
337
Statement {
0 commit comments