File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 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) {
788788 fn is_valid < T : cmp:: Ord > ( binop : ast:: BinOp , v : T ,
789789 min : T , max : T ) -> bool {
790790 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 ,
795795 ast:: BiEq | ast:: BiNe => v >= min && v <= max,
796796 _ => fail ! ( )
797797 }
Original file line number Diff line number Diff line change @@ -29,6 +29,18 @@ fn baz() -> bool {
2929 //~^ WARNING literal out of range for its type
3030}
3131
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+
3244fn qux ( ) {
3345 let mut i = 1i8 ;
3446 while 200 != i { //~ ERROR comparison is useless due to type limits
You can’t perform that action at this time.
0 commit comments