Skip to content

Incorrect "variant is never used" lint #44083

Closed
@LukasKalbertodt

Description

@LukasKalbertodt

A "variant is never used" lint is incorrectly triggered, presumably due to optimizations on MIR. I know my code sample looks pretty stupid as no human would write this, probably. But this kind of code might be generated. Anyway, the lint is incorrect I'd say.

I tried this code:

enum Baz {
    Foo,
    Bar,
}

fn main() {
    let x = Baz::Foo;
    match x {
        Baz::Foo => {},
        Baz::Bar if true => {},
        _ => {}
    }
}

I expected to see this happen: no warning

Instead, this happened:

warning: variant is never used: `Bar`
 --> src/main.rs:3:5
  |
3 |     Bar,
  |     ^^^
  |
  = note: #[warn(dead_code)] on by default

Meta

Happens with

  • 1.19 stable,
  • 1.20 beta,
  • 1.21 nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions