Skip to content

Non-exhaustive pattern error when matching on ! #115716

Open
@cjgillot

Description

@cjgillot

I tried this code:

#![feature(never_type)]

fn main() {
    let x: !;
    match x {
        _ if { loop {} } => (),
    }
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=4a9450423c54a62242360d62e9480bf3

I expected to see this happen: complain about the uninitialized binding x.
Like it does in https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=99dc49582c1bce26b084e33bfd366026

Instead, this happened: error E0004: non-exhaustive patterns: () not covered
A match on a scrutinee of type ! should not expect a pattern of type ().

Meta

rustc --version --verbose:

rustc 1.71.1 (eb26296b5 2023-08-03)
binary: rustc
commit-hash: eb26296b556cef10fb713a38f3d16b9886080f26
commit-date: 2023-08-03
host: x86_64-unknown-linux-gnu
release: 1.71.1
LLVM version: 16.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-never_type`#![feature(never_type)]`T-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