Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ICE when referencing desugared local binding in borrow error #63051

Merged
merged 2 commits into from Jul 28, 2019

Conversation

@estebank
Copy link
Contributor

commented Jul 27, 2019

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
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Jul 27, 2019

r? @zackmdavis

(rust_highfive has picked a reviewer for you, use r? to override)

@estebank

This comment has been minimized.

Copy link
Contributor Author

commented Jul 27, 2019

@matthewjasper

This comment has been minimized.

Copy link
Contributor

commented Jul 27, 2019

@estebank estebank force-pushed the estebank:borrow-ice branch from 1fde40f to 01ba0e3 Jul 28, 2019

@matthewjasper

This comment has been minimized.

Copy link
Contributor

commented Jul 28, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

commented Jul 28, 2019

📌 Commit 01ba0e3 has been approved by matthewjasper

Centril added a commit to Centril/rust that referenced this pull request Jul 28, 2019

Rollup merge of rust-lang#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, rust-lang#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 (rust-lang#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 rust-lang#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
```

bors added a commit that referenced this pull request Jul 28, 2019

Auto merge of #63072 - Centril:rollup-u9u7ijy, r=Centril
Rollup of 5 pull requests

Successful merges:

 - #62806 (Fix few Clippy warnings)
 - #63051 (Avoid ICE when referencing desugared local binding in borrow error)
 - #63061 (In which we constantly improve the Vec(Deque) array PartialEq impls)
 - #63067 (Add test for issue-50900)
 - #63071 (Allow rustbot to add `F-*` + `requires-nightly`.)

Failed merges:

r? @ghost

Centril added a commit to Centril/rust that referenced this pull request Jul 28, 2019

Rollup merge of rust-lang#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, rust-lang#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 (rust-lang#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 rust-lang#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
```

bors added a commit that referenced this pull request Jul 28, 2019

Auto merge of #63074 - Centril:rollup-k1a8z0n, r=Centril
Rollup of 8 pull requests

Successful merges:

 - #62550 (Implement RFC 2707 + Parser recovery for range patterns)
 - #62759 (Actually add rustc-guide to toolstate, don't fail builds for the guide)
 - #62806 (Fix few Clippy warnings)
 - #62974 (bump crossbeam-epoch dependency)
 - #63051 (Avoid ICE when referencing desugared local binding in borrow error)
 - #63061 (In which we constantly improve the Vec(Deque) array PartialEq impls)
 - #63067 (Add test for issue-50900)
 - #63071 (Allow rustbot to add `F-*` + `requires-nightly`.)

Failed merges:

r? @ghost

@bors bors merged commit 01ba0e3 into rust-lang:master Jul 28, 2019

4 checks passed

pr Build #20190728.7 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details
pr (LinuxTools) LinuxTools succeeded
Details

@nagisa nagisa added the beta-accepted label Aug 8, 2019

@Mark-Simulacrum Mark-Simulacrum referenced this pull request Aug 12, 2019

bors added a commit that referenced this pull request Aug 12, 2019

Auto merge of #63498 - Mark-Simulacrum:stable-next, r=Mark-Simulacrum
1.37.0 stable

This promotes beta to stable and backports a few PRs:

 - Avoid ICE when referencing desugared local binding in borrow error (#63051)
 - Don't access a static just for its size and alignment (#62982) via 331e09b

bors added a commit that referenced this pull request Aug 12, 2019

Auto merge of #63498 - Mark-Simulacrum:stable-next, r=Mark-Simulacrum
1.37.0 stable

This promotes beta to stable and backports a few PRs:

 - Avoid ICE when referencing desugared local binding in borrow error (#63051)
 - Don't access a static just for its size and alignment (#62982) via 331e09b

bors added a commit that referenced this pull request Aug 12, 2019

Auto merge of #63498 - Mark-Simulacrum:stable-next, r=Mark-Simulacrum
1.37.0 stable

This promotes beta to stable and backports a few PRs:

 - Avoid ICE when referencing desugared local binding in borrow error (#63051)
 - Don't access a static just for its size and alignment (#62982) via 331e09b

bors added a commit that referenced this pull request Aug 13, 2019

Auto merge of #63498 - Mark-Simulacrum:stable-next, r=Mark-Simulacrum
1.37.0 stable

This promotes beta to stable and backports a few PRs:

 - Avoid ICE when referencing desugared local binding in borrow error (#63051)
 - Don't access a static just for its size and alignment (#62982) via 331e09b

bors added a commit that referenced this pull request Aug 13, 2019

Auto merge of #63498 - Mark-Simulacrum:stable-next, r=Mark-Simulacrum
1.37.0 stable

This promotes beta to stable and backports a few PRs:

 - Avoid ICE when referencing desugared local binding in borrow error (#63051)
 - Don't access a static just for its size and alignment (#62982) via 331e09b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.