Skip to content

Unnecessary parentheses warning for (A | B) as :pat in 2018 edition #86959

Open
@ExpHP

Description

@ExpHP

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=30f392098326a970e468c3125f7c5413

macro_rules! mac {
    ($expr:expr, $pat:pat) => {
        match $expr {
            $pat => {},
            _ => panic!(),
        }
    };
}

fn main() {
    mac!('a', ('a' | 'A'));
}

The current output is:

   Compiling playground v0.0.1 (/playground)
warning: unnecessary parentheses around pattern
  --> src/main.rs:12:15
   |
12 |     mac!('a', ('a' | 'A'));
   |               ^^^^^^^^^^^ help: remove these parentheses
   |
   = note: `#[warn(unused_parens)]` on by default

warning: 1 warning emitted

While it would be true that these parentheses are unnecessary in 2021 edition, (and also of course in the macro expanded output as well, which is why the warning occurs), they are required here in 2018 edition because :pat cannot match 'a' | 'A' in this edition, making the warning a nuisance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.L-unused_parensLint: unused_parensP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions