-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Error message referring to non-existent variable: "cannot return value referencing local variable __next
"
#63027
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
jonas-schievink
added
A-diagnostics
Area: Messages for errors, warnings, and lints
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Jul 26, 2019
The correct error should be
|
Centril
added a commit
to Centril/rust
that referenced
this issue
Jul 28, 2019
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 ```
Centril
added a commit
to Centril/rust
that referenced
this issue
Jul 28, 2019
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 ```
Current output:
|
Triage: no change. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Compiling the following code on stable result in an error message which is referring to a non-existent variable
__next
The error message:
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: