Skip to content

Incorrect "unreachable match arm" warning  #117119

Closed
@RalfJung

Description

@RalfJung

The following code generates a warning:

fn main() {
    #[derive(Copy, Clone)]
    enum Void {}
    union Uninit<T: Copy> {
        value: T,
        uninit: (),
    }
    unsafe {
        let x: Uninit<Void> = Uninit { uninit: () };
        match x.value {
            _ => println!("hi from the void!"),
        }
    }
}
warning: unreachable pattern
  --> src/main.rs:12:13
   |
12 |             _ => println!("hi from the void!"),
   |             ^
   |
   = note: `#[warn(unreachable_patterns)]` on by default

This warning is wrong: running the code in Miri shows that this arm is reachable and there is no UB.

Metadata

Metadata

Assignees

Labels

A-exhaustiveness-checkingRelating to exhaustiveness / usefulness checking of 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