about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/middle/lint.rs8
-rw-r--r--src/test/compile-fail/lint-type-limits.rs12
2 files changed, 16 insertions, 4 deletions
diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs
index 93e8c637f17..aca8dc61252 100644
--- a/src/librustc/middle/lint.rs
+++ b/src/librustc/middle/lint.rs
@@ -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!()
         }
diff --git a/src/test/compile-fail/lint-type-limits.rs b/src/test/compile-fail/lint-type-limits.rs
index 1aaf68d7c1a..67ef9cd0680 100644
--- a/src/test/compile-fail/lint-type-limits.rs
+++ b/src/test/compile-fail/lint-type-limits.rs
@@ -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