E0135
A range pattern that cannot match
ErrorA range pattern takes i64, u8 or char, and matches at least one value: 5..=4 and 5..5 match none.
Why
A range compares a value with its bounds, so it needs a type whose values are ordered: an integer, or a char by its code point. A string, bool or enum has no such order in a pattern. A range that matches no value is a mistake, usually bounds in the wrong order, and Rust rejects it too.
Broken
fn first_half(c: char) -> bool {
match c {
"a".."n" => true
_ => false
}
}
fn main() {
print(first_half('c'))
}
What sisu says
error[E0135]: a range pattern takes `i64`, `u8` or `char` --> E0135.sisu:3:9 | 3 | "a".."n" => true | ^^^^^^^^ sisu: 1 error sisu: for more on a code, run `sisu explain <code>`: E0135
Fixed
fn first_half(c: char) -> bool {
match c {
'a'..'n' => true
_ => false
}
}
fn main() {
print(first_half('c'))
}
Sisu