File tree 2 files changed +16
-4
lines changed
2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -788,10 +788,10 @@ fn check_type_limits(cx: &Context, e: &ast::Expr) {
788
788
fn is_valid < T : cmp:: Ord > ( binop : ast:: BinOp , v : T ,
789
789
min : T , max : T ) -> bool {
790
790
match binop {
791
- ast:: BiLt => v <= max,
792
- ast:: BiLe => v < max,
793
- ast:: BiGt => v >= min,
794
- ast:: BiGe => v > min,
791
+ ast:: BiLt => v > min && v <= max,
792
+ ast:: BiLe => v >= min && v < max,
793
+ ast:: BiGt => v >= min && v < max ,
794
+ ast:: BiGe => v > min && v <= max ,
795
795
ast:: BiEq | ast:: BiNe => v >= min && v <= max,
796
796
_ => fail ! ( )
797
797
}
Original file line number Diff line number Diff line change @@ -29,6 +29,18 @@ fn baz() -> bool {
29
29
//~^ WARNING literal out of range for its type
30
30
}
31
31
32
+ fn bleh ( ) {
33
+ let u = 42u8 ;
34
+ let _ = u > 255 ; //~ ERROR comparison is useless due to type limits
35
+ let _ = 255 < u; //~ ERROR comparison is useless due to type limits
36
+ let _ = u < 0 ; //~ ERROR comparison is useless due to type limits
37
+ let _ = 0 > u; //~ ERROR comparison is useless due to type limits
38
+ let _ = u <= 255 ; //~ ERROR comparison is useless due to type limits
39
+ let _ = 255 >= u; //~ ERROR comparison is useless due to type limits
40
+ let _ = u >= 0 ; //~ ERROR comparison is useless due to type limits
41
+ let _ = 0 <= u; //~ ERROR comparison is useless due to type limits
42
+ }
43
+
32
44
fn qux ( ) {
33
45
let mut i = 1i8 ;
34
46
while 200 != i { //~ ERROR comparison is useless due to type limits
You can’t perform that action at this time.
0 commit comments