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

NLL: E0594 removes first char of variable name #51515

Closed
ashtneoi opened this issue Jun 12, 2018 · 2 comments · Fixed by #51612
Closed

NLL: E0594 removes first char of variable name #51515

ashtneoi opened this issue Jun 12, 2018 · 2 comments · Fixed by #51612
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. NLL-diagnostics Working torwads the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ashtneoi
Copy link
Contributor

When I build this code on nightly...

#![feature(nll)]

fn main() {
    let foo = &16;
    *foo = 32;
    let bar = foo;
    *bar = 64;
}

...I get these errors:

error[E0594]: cannot assign to data in a `&` reference
 --> src/main.rs:5:5
  |
4 |     let foo = &16;
  |               --- help: consider changing this to be a mutable reference: `&mut 16`
5 |     *foo = 32;
  |     ^^^^^^^^^

error[E0594]: cannot assign to data in a `&` reference
 --> src/main.rs:7:5
  |
6 |     let bar = foo;
  |               --- help: consider changing this to be a mutable reference: `&mut oo`
7 |     *bar = 64;
  |     ^^^^^^^^^

The first error is fine, but the second one is missing the first character of foo. It looks like rustc assumes the first character is an & and removes it without checking.

Meta

rustc --version --verbose:

rustc 1.28.0-nightly (1d4dbf488 2018-06-11)
binary: rustc
commit-hash: 1d4dbf488a4364413e7b9611866b7a5c75ce566f
commit-date: 2018-06-11
host: x86_64-unknown-linux-gnu
release: 1.28.0-nightly
LLVM version: 6.0
@ashtneoi ashtneoi changed the title NLL: E0594 (cannot assign to data in a & reference) truncates variable name NLL: E0594 removes first char of variable name Jun 12, 2018
@csmoe csmoe added A-diagnostics Area: Messages for errors, warnings, and lints NLL-diagnostics Working torwads the "diagnostic parity" goal labels Jun 12, 2018
@jkordish jkordish added C-enhancement Category: An issue proposing an enhancement or a PR with one. WG-compiler-nll T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 13, 2018
@ashtneoi
Copy link
Contributor Author

Currently working on a fix here: https://github.com/ashtneoi/rust/tree/51515-missing-first-char. Still need to add UI tests, which I'll do once I figure out how they work.

@nikomatsakis
Copy link
Contributor

Adding to the Rust 2018 Edition Preview milestone. Has a pending PR, too.

ashtneoi added a commit to ashtneoi/ashtcore that referenced this issue Jul 9, 2018
ashtneoi added a commit to ashtneoi/ashtcore that referenced this issue Jul 9, 2018
bors added a commit that referenced this issue Jul 10, 2018
NLL: fix E0594 "change to mutable ref" suggestion

Fix #51515.
Fix #51879.

Questions:
- [x] Is this the right place to fix this? It feels brittle, being so close to the frontend. **It's probably fine.**
- [ ] Have I missed any other cases that trigger this behavior?
- [x] Is it okay to use HELP and SUGGESTION in the UI test? **Yes.**
- [x] Do I need more tests for this? **No.**
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 10, 2018
…r=pnkfelix

NLL: fix E0594 "change to mutable ref" suggestion

Fix rust-lang#51515.
Fix rust-lang#51879.

Questions:
- [x] Is this the right place to fix this? It feels brittle, being so close to the frontend. **It's probably fine.**
- [ ] Have I missed any other cases that trigger this behavior?
- [x] Is it okay to use HELP and SUGGESTION in the UI test? **Yes.**
- [x] Do I need more tests for this? **No.**
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-enhancement Category: An issue proposing an enhancement or a PR with one. NLL-diagnostics Working torwads the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants