book
book copied to clipboard
ch18-03: Guarded match arm exhaustivness clarification
trafficstars
As per experimentation shows, match arms exhaustivness is checked even when arms use match guard.
This simple sample
pub fn test() {
match Some(5) {
Some(50) => println!("Got it"),
Some(_n) if true => println!("Exhausted"),
None => (),
}
}
produces output

Notable observations are
- Arm
Some(_n) if true => println!("Exhausted")catches already any otherSomeother thanSome(50). - After
None => (),change to_ => (),, compilation produces no error.
Obviously compiler does no heuristics on possible results of match guard. But it still acts as if makes strong check on arms exhaustivness.