rust/tests/ui/pattern/usefulness/guards.rs
2024-05-02 19:42:31 -04:00

22 lines
422 B
Rust

#![deny(unreachable_patterns)]
enum Q { R(Option<usize>) }
pub fn main() {
match Q::R(None) {
Q::R(S) if S.is_some() => {}
_ => {}
}
match 0u8 { //~ ERROR non-exhaustive patterns
0 .. 128 => {}
128 ..= 255 if true => {}
}
match 0u8 {
0 .. 128 => {}
128 ..= 255 if false => {}
128 ..= 255 => {} // ok, because previous arm was guarded
}
}