Skip to content

Incorrect "unreachable pattern" warning with opaque constant #78057

Closed
@Nadrieril

Description

I tried this code (playground link):

#[derive(PartialEq)]
struct Opaque(i32);

impl Eq for Opaque {}

const FOO: Opaque = Opaque(42);

fn foo() {
    match Opaque(0) {
        FOO => {},
        _ => {}
    }
}

This emits an "unreachable pattern" warning on the second branch of the match, even though it is clearly reachable. This gives the same warning for current nightly and beta, as well as stable 1.47.0 and 1.40.0.

This was uncovered while discussing #77390.

Meta

rustc --version --verbose:

rustc 1.47.0 (18bf6b4f0 2020-10-07)
binary: rustc
commit-hash: 18bf6b4f01a6feaf7259ba7cdae58031af1b7b39
commit-date: 2020-10-07
host: x86_64-unknown-linux-gnu
release: 1.47.0
LLVM version: 11.0

Metadata

Assignees

No one assigned

    Labels

    A-exhaustiveness-checkingRelating to exhaustiveness / usefulness checking of patternsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions