Skip to content

Provide hint for assignment to &mut variable that should use * #36251

@joshtriplett

Description

@joshtriplett

Consider the following code:

fn main() {
    let mut x = 5;
    {
        let r = &mut x;
        r = 10;
    }
    println!("{}", x);
}

Compiling this produces the following error:

mutref.rs:5:13: 5:15 error: mismatched types [E0308]
mutref.rs:5         r = 10;
                        ^~
mutref.rs:5:13: 5:15 help: run `rustc --explain E0308` to see a detailed explanation
mutref.rs:5:13: 5:15 note: expected type `&mut _`
mutref.rs:5:13: 5:15 note:    found type `_`
error: aborting due to previous error

Ideally, this error should include a suggestion that the user probably meant to assign to *r.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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