Skip to content

NLL: match arm binding wrong suggestion in error message #51554

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

Closed
martin-t opened this issue Jun 14, 2018 · 3 comments
Closed

NLL: match arm binding wrong suggestion in error message #51554

martin-t opened this issue Jun 14, 2018 · 3 comments
Assignees
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-enhancement Category: An issue proposing an enhancement or a PR with one. NLL-diagnostics Working towards the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@martin-t
Copy link

martin-t commented Jun 14, 2018

Using this code on nightly:

#![feature(nll)]

enum E {
    Variant(i32),
}

fn main() {
    let e = E::Variant(5);
    match e {
        E::Variant(ref some_name) => *some_name += 10,
    }
}

I get this error message:

error[E0594]: cannot assign to data in a `&` reference
  --> src/main.rs:10:38
   |
10 |         E::Variant(ref some_name) => *some_name += 10,
   |                    -------------     ^^^^^^^^^^^^^^^^
   |                    |
   |                    help: consider changing this to be a mutable reference: `&mut ef some_name`
error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.

(playground link)

The correct suggestion is ref mut some_name.

Meta

rustc --version --verbose:

rustc 1.28.0-nightly (b907d9665 2018-06-13)
binary: rustc
commit-hash: b907d966528a6859ec847a2a4d32f092a5be6584
commit-date: 2018-06-13
host: x86_64-unknown-linux-gnu
release: 1.28.0-nightly
LLVM version: 6.0
@matthewjasper matthewjasper added A-NLL Area: Non-lexical lifetimes (NLL) WG-compiler-nll NLL-diagnostics Working towards the "diagnostic parity" goal labels Jun 14, 2018
@ashtneoi
Copy link
Contributor

This looks like it has the same root cause as #51515.

@jkordish jkordish added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 19, 2018
@nikomatsakis
Copy link
Contributor

Current error that I see is:

error[E0594]: cannot assign to `*some_name` which is behind a `&` reference
  --> src/main.rs:10:38
   |
10 |         E::Variant(ref some_name) => *some_name += 10,
   |                                      ^^^^^^^^^^^^^^^^ cannot assign

@nikomatsakis
Copy link
Contributor

This seems pretty good to me. Closing as fixed. Thanks @martin-t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-enhancement Category: An issue proposing an enhancement or a PR with one. NLL-diagnostics Working towards the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants