diff options
| author | Remy Rakic <remy.rakic@gmail.com> | 2018-09-14 18:07:17 +0200 |
|---|---|---|
| committer | Remy Rakic <remy.rakic@gmail.com> | 2018-09-18 14:34:51 +0200 |
| commit | 52b53629901f2f797bf0191afdaba380234f81ad (patch) | |
| tree | a5253a2b8bb72d17c9461df531d3526dc61d98d9 /src | |
| parent | c3c7a5bafe26d566242e000bb6136e3e9ee8d611 (diff) | |
| download | rust-52b53629901f2f797bf0191afdaba380234f81ad.tar.gz rust-52b53629901f2f797bf0191afdaba380234f81ad.zip | |
Explain the fake read injection better
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/build/matches/mod.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 91d439d430c..5c72679800c 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -265,9 +265,20 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard); unpack!(block = self.into(&place, block, initializer)); - // Inject a fake read of the newly created binding - // to test the fallout of fixing issue #53695 where NLL - // allows creating unused variables that are effectively unusable. + + // Officially, the semantics of + // + // `let pattern = <expr>;` + // + // is that `<expr>` is evaluated into a temporary and then this temporary is + // into the pattern. + // + // However, if we see the simple pattern `let var = <expr>`, we optimize this to + // evaluate `<expr>` directly into the variable `var`. This is mostly unobservable, + // but in some cases it can affect the borrow checker, as in #53695. + // Therefore, we insert a "fake read" here to ensure that we get + // appropriate errors. + // let source_info = self.source_info(irrefutable_pat.span); self.cfg.push( block, @@ -318,9 +329,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { }, ); - // Inject a fake read of the newly created binding - // to test the fallout of fixing issue #53695 where NLL - // allows creating unused variables that are effectively unusable. + // Similarly to the `let var = <expr>` case, we insert a "fake read" here to + // ensure that we get appropriate errors when this usually unobservable + // optimization affects the borrow checker. self.cfg.push( block, Statement { |
