Incorrect unused_variables diagnostic for or-ed patterns · Issue #67691 · rust-lang/rust (original) (raw)

With rustc 1.42.0-nightly (0de96d3 2019-12-19):

For the following code:

pub enum MyEnum { A { i: i32, j: i32 }, B { i: i32, j: i32 }, }

pub fn foo(x: MyEnum) { use MyEnum::*;

match x {
    A { i, j } | B { i, j } => {
        println!("{}", i);
    }
}

}

I get the following diagnostic:

) rustc +nightly test.rs -o test --crate-type lib
warning: unused variable: `j`
  --> test.rs:10:16
   |
10 |         A { i, j } | B { i, j } => {
   |                ^            ^
   |
   = note: `#[warn(unused_variables)]` on by default
help: try ignoring the field
   |
10 |         A { i, j: _j: _ } | B { i, j } => {
   |                ^^^^^^^

Instead of:

help: try ignoring the field
   |
10 |         A { i, j: _ } | B { i, j: _ } => {
   |                ^^^^            ^^^^