Description
Apologies if this is a dupe.
This doesn't compile:
fn main() {
match 25u8 {
0 ... 24 => println!("less than 25"),
25 => println!("exactly 25"),
26 ... 255 => println!("above 25")
}
}
Error message:
<anon>:2:5: 6:6 error: non-exhaustive patterns: `_` not covered [E0004]
<anon>:2 match 25u8 {
<anon>:3 0 ... 24 => println!("less than 25"),
<anon>:4 25 => println!("exactly 25"),
<anon>:5 26 ... 255 => println!("above 25")
<anon>:6 }
<anon>:2:5: 6:6 help: see the detailed explanation for E0004
error: aborting due to previous error
The compiler isn't actually checking whether all the values for u8
are covered, it's just checking whether or not there's a case for _
.
I've created some code that takes a Range<T>
(the 'all-encompassing' range, i.e. 0...255
for u8
) and Vec<Range<T>> where T: Ord + Copy
and determines which ranges (if any) are not covered by the ranges provided by the vector. However, this code needs proper inclusive range support in order to work; I can't add 1 to the maximum value of a type in order to make it include every possible value for that type. That is available here.
I'm interested in implementing this logic in the compiler but I've no idea where to start, plus the code has the aforementioned inclusive range requirement.