Skip to content

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

Closed
@martin-t

Description

@martin-t

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

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)C-enhancementCategory: An issue proposing an enhancement or a PR with one.NLL-diagnosticsWorking towards the "diagnostic parity" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions