Skip to content

Suggestion for unused variables can sometimes be incorrect #56685

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.

Activity

  1. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    on Dec 10, 2018
  2. self-assigned this
    on Jan 25, 2019
  3. added a commit that references this issue on Jan 27, 2019
    93350f4
  4. added a commit that references this issue on Jan 27, 2019
    843d50f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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