Skip to content

Help incorrectly suggests inserting assignment in pattern #145564

@traviscross

Description

@traviscross

The help text emitted for the following suggests code that is invalid.

fn main() {
    let ref mut x @ v;
    *x = 1;
}
error[E0381]: used binding `x` isn't initialized
 --> src/main.rs:3:5
  |
2 |     let ref mut x @ v;
  |         --------- binding declared here but left uninitialized
3 |     *x = 1;
  |     ^^^^^^ `x` used here but it isn't initialized
  |
help: consider assigning a value
  |
2 |     let ref mut x = &mut 42 @ v;
  |                   +++++++++

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-patternsRelating to patterns and pattern matchingD-imprecise-spansDiagnostics: spans don't point to exactly the erroneous codeD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-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