Skip to content

Incorrect "unreachable pattern" warning in Rust 1.50. #82012

Closed
@AlephAlpha

Description

@AlephAlpha

This seems to be a new issue in Rust 1.50. The latest nightly does not have this issue.

macro_rules! some {
    ($item:pat) => {
        Some($item)
    };
}

fn main() {
    let a = Some('A');
    match a {
        some!('a') | some!('A') => println!("A!"),
        _ => println!("Not a!"),
    }
}

playground

It prints "A!" without any error, but gives the following warning.

warning: unreachable pattern
  --> src/main.rs:3:9
   |
3  |         Some($item)
   |         ^^^^^^^^^^^
...
10 |         some!('a') | some!('A') => println!("A!"),
   |                      ---------- in this macro invocation
   |
   = note: `#[warn(unreachable_patterns)]` on by default
   = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted

some!('A') is obviously reachable, otherwise it won't print "A!".

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-exhaustiveness-checkingRelating to exhaustiveness / usefulness checking of patternsC-bugCategory: This is a bug.T-releaseRelevant to the release subteam, 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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions