mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 10:18:25 +00:00

In rustc it doesn't really matter what the order of the witnesses is, but I'm planning to use the witnesses for implementing the "add missing match arms" assist in rust-analyzer, and there `true` before `false` is the natural order (like `Some` before `None`), and also what the current assist does. The current order doesn't seem to be intentional; the code was created when bool ctors became their own thing, not just int ctors, but for integer, 0 before 1 is indeed the natural order.
36 lines
1.1 KiB
Rust
36 lines
1.1 KiB
Rust
fn main() {
|
|
#[derive(Copy, Clone)]
|
|
union U8AsBool {
|
|
n: u8,
|
|
b: bool,
|
|
}
|
|
|
|
let x = U8AsBool { n: 1 };
|
|
unsafe {
|
|
match x {
|
|
// exhaustive
|
|
U8AsBool { n: 2 } => {}
|
|
U8AsBool { b: true } => {}
|
|
U8AsBool { b: false } => {}
|
|
}
|
|
match x {
|
|
// exhaustive
|
|
U8AsBool { b: true } => {}
|
|
U8AsBool { n: 0 } => {}
|
|
U8AsBool { n: 1.. } => {}
|
|
}
|
|
match x {
|
|
//~^ ERROR non-exhaustive patterns: `U8AsBool { n: 0_u8 }` and `U8AsBool { b: false }` not covered
|
|
U8AsBool { b: true } => {}
|
|
U8AsBool { n: 1.. } => {}
|
|
}
|
|
// Our approach can report duplicate witnesses sometimes.
|
|
match (x, true) {
|
|
//~^ ERROR non-exhaustive patterns: `(U8AsBool { n: 0_u8 }, false)`, `(U8AsBool { b: true }, false)`, `(U8AsBool { n: 0_u8 }, false)` and 1 more not covered
|
|
(U8AsBool { b: true }, true) => {}
|
|
(U8AsBool { b: false }, true) => {}
|
|
(U8AsBool { n: 1.. }, true) => {}
|
|
}
|
|
}
|
|
}
|