Skip to content

Suggestion for unused variables can sometimes be incorrect #56685

Closed
@alexcrichton

Description

@alexcrichton

First reported upstream this code:

fn main() {
    enum E {
        A(i32,),
        B(i32,),
    }
    match E::A(1) {
        E::A(x) | E::B(x) => {}
    }
}

when compiled yields a suggestion of

warning: unused variable: `x`
 --> src/main.rs:7:14
  |
7 |         E::A(x) | E::B(x) => {}
  |              ^ help: consider using `_x` instead
  |
  = note: #[warn(unused_variables)] on by default

warning: variant is never constructed: `B`
 --> src/main.rs:4:9
  |
4 |         B(i32),
  |         ^^^^^^
  |
  = note: #[warn(dead_code)] on by default

but the suggestion is not correct! Both instances of the x binding need to be renamed in order for the code to be automatically fixed.

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions