Skip to content

Point at assignment where unread previously assigned binding is overwritten #144079

@estebank

Description

@estebank

Code

fn main() {
    let mut x = 1;
    x = 2;
    x = 3;
    println!("{x}");
}

Current output

warning: value assigned to `x` is never read
 --> src/main.rs:2:13
  |
2 |     let mut x = 1;
  |             ^
  |
  = help: maybe it is overwritten before being read?
  = note: `#[warn(unused_assignments)]` on by default

warning: value assigned to `x` is never read
 --> src/main.rs:3:5
  |
3 |     x = 2;
  |     ^
  |
  = help: maybe it is overwritten before being read?

Desired output

warning: value assigned to `x` is never read
 --> src/main.rs:2:13
  |
2 |     let mut x = 1;
  |             ^
3 |     x = 2;
  |     - overwritten here before being read
  = note: `#[warn(unused_assignments)]` on by default

warning: value assigned to `x` is never read
 --> src/main.rs:3:5
  |
3 |     x = 2;
  |     ^
4 |     x = 3;
  |     - overwritten here before being read

Rationale and extra context

No response

Other cases

Rust Version

1.88 + 1.90-nightly as of today

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.D-papercutDiagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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