Skip to content

unreachable_patterns emitted on _ that matches a local of uninhabited type (that is uninitialized) #134733

Open
@WaffleLapkin

Description

@WaffleLapkin

I tried this code:

enum Void {}

fn main() {
    let void: Void;
    match void {
        _ => (),
    }
}

(playground)

I expected to see this happen: the code compiler without warnings and successfully runs doing nothing.

Instead, this happened: a warning is emitted (the code compiles and runs as expected):

warning: unreachable pattern
 --> src/main.rs:6:9
  |
6 |         _ => (),
  |         ^-------
  |         |
  |         matches no values because `Void` is uninhabited
  |         help: remove the match arm
  |
  = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
  = note: `#[warn(unreachable_patterns)]` on by default

Meta

rustc version: 1.85.0-nightly (2024-12-23 bdc6b3de48646345549f)

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.L-unreachable_patternsLint: unreachable_patternsT-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