Skip to content

Incorrect unused_variables diagnostic for or-ed patterns #67691

Closed
@sapir

Description

@sapir

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: _ } => {
   |                ^^^^            ^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.F-or_patterns`#![feature(or_patterns)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions