os-rust/tests/ui/pattern/usefulness/unions.rs

36 lines
1.1 KiB
Rust
Raw Normal View History

2024-03-31 23:57:47 +02:00
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 {
2024-03-31 23:57:53 +02:00
//~^ ERROR non-exhaustive patterns: `U8AsBool { n: 0_u8 }` and `U8AsBool { b: false }` not covered
2024-03-31 23:57:47 +02:00
U8AsBool { b: true } => {}
U8AsBool { n: 1.. } => {}
}
2024-03-31 23:57:53 +02:00
// Our approach can report duplicate witnesses sometimes.
2024-03-31 23:57:47 +02:00
match (x, true) {
2024-03-31 23:57:53 +02:00
//~^ ERROR non-exhaustive patterns: `(U8AsBool { n: 0_u8 }, false)`, `(U8AsBool { b: false }, false)`, `(U8AsBool { n: 0_u8 }, false)` and 1 more not covered
2024-03-31 23:57:47 +02:00
(U8AsBool { b: true }, true) => {}
(U8AsBool { b: false }, true) => {}
(U8AsBool { n: 1.. }, true) => {}
}
}
}