about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-07-28 11:11:12 +0200
committerGitHub <noreply@github.com>2019-07-28 11:11:12 +0200
commita558668cf2bd01cf47613694b786c08b6a91a607 (patch)
tree3ed6abc5656b8c07f4e9076c6296d7c5e165031f /src/liballoc
parent48802974aa2caabc7d386e4a39c72fd765f5b98e (diff)
parent01ba0e3718b9006030d2d5391176745547f7c9a7 (diff)
downloadrust-a558668cf2bd01cf47613694b786c08b6a91a607.tar.gz
rust-a558668cf2bd01cf47613694b786c08b6a91a607.zip
Rollup merge of #63051 - estebank:borrow-ice, r=matthewjasper
Avoid ICE when referencing desugared local binding in borrow error

To avoid leaking the names of local bindings from expressions like for loops, #60984 explicitly ignored them, but an assertion that `LocalKind::Var` *must* have a name would trigger an ICE.

Before this change, the binding generated by desugaring the for loop would leak into the diagnostic (#63027):
```
error[E0515]: cannot return value referencing local variable `__next`
  --> return-local-binding-from-desugaring.rs:LL:CC
   |
LL |     for ref x in xs {
   |         ----- `__next` is borrowed here
...
LL |     result
   |     ^^^^^^ returns a value referencing data owned by the current function
```

Ideally `LocalKind` would carry more information to more accurately explain the problem, but for now, in order to avoid the ICE (fix #63026), we accept `LocalKind::Var` without a name and produce the following output:

```
error[E0515]: cannot return value referencing local binding
  --> $DIR/return-local-binding-from-desugaring.rs:30:5
   |
LL |     for ref x in xs {
   |                  -- local binding introduced here
...
LL |     result
   |     ^^^^^^ returns a value referencing data owned by the current function
```
Diffstat (limited to 'src/liballoc')
0 files changed, 0 insertions, 0 deletions