Add missing cases to the type_limits lint
and exhaustive testing for the `u8` type.
This commit is contained in:
parent
4f1b0b5199
commit
0e8e0b2ede
@ -788,10 +788,10 @@ fn check_type_limits(cx: &Context, e: &ast::Expr) {
|
||||
fn is_valid<T:cmp::Ord>(binop: ast::BinOp, v: T,
|
||||
min: T, max: T) -> bool {
|
||||
match binop {
|
||||
ast::BiLt => v <= max,
|
||||
ast::BiLe => v < max,
|
||||
ast::BiGt => v >= min,
|
||||
ast::BiGe => v > min,
|
||||
ast::BiLt => v > min && v <= max,
|
||||
ast::BiLe => v >= min && v < max,
|
||||
ast::BiGt => v >= min && v < max,
|
||||
ast::BiGe => v > min && v <= max,
|
||||
ast::BiEq | ast::BiNe => v >= min && v <= max,
|
||||
_ => fail!()
|
||||
}
|
||||
|
@ -29,6 +29,18 @@ fn baz() -> bool {
|
||||
//~^ WARNING literal out of range for its type
|
||||
}
|
||||
|
||||
fn bleh() {
|
||||
let u = 42u8;
|
||||
let _ = u > 255; //~ ERROR comparison is useless due to type limits
|
||||
let _ = 255 < u; //~ ERROR comparison is useless due to type limits
|
||||
let _ = u < 0; //~ ERROR comparison is useless due to type limits
|
||||
let _ = 0 > u; //~ ERROR comparison is useless due to type limits
|
||||
let _ = u <= 255; //~ ERROR comparison is useless due to type limits
|
||||
let _ = 255 >= u; //~ ERROR comparison is useless due to type limits
|
||||
let _ = u >= 0; //~ ERROR comparison is useless due to type limits
|
||||
let _ = 0 <= u; //~ ERROR comparison is useless due to type limits
|
||||
}
|
||||
|
||||
fn qux() {
|
||||
let mut i = 1i8;
|
||||
while 200 != i { //~ ERROR comparison is useless due to type limits
|
||||
|
Loading…
Reference in New Issue
Block a user