]> git.lizzy.rs Git - rust.git/commitdiff
Don't warn about `char` comparisons in constexprs
authorMatthew Jasper <mjjasper1@gmail.com>
Fri, 31 Mar 2017 22:52:35 +0000 (23:52 +0100)
committerMatthew Jasper <mjjasper1@gmail.com>
Fri, 31 Mar 2017 22:52:35 +0000 (23:52 +0100)
src/librustc_const_eval/eval.rs
src/test/run-pass/const-err.rs

index c5d577ce571d40aceb664dd8d190a19f4efb709d..54f5cff16ed6cb584b888d46983820938f5e9d1e 100644 (file)
@@ -490,6 +490,17 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
               _ => span_bug!(e.span, "typeck error"),
              })
           }
+          (Char(a), Char(b)) => {
+            Bool(match op.node {
+              hir::BiEq => a == b,
+              hir::BiNe => a != b,
+              hir::BiLt => a < b,
+              hir::BiLe => a <= b,
+              hir::BiGe => a >= b,
+              hir::BiGt => a > b,
+              _ => span_bug!(e.span, "typeck error"),
+             })
+          }
 
           _ => signal!(e, MiscBinaryOp),
         }
index a1c9ff8a21edb4b45341181130892a66f50a9e87..f7f79356a0b9f22284b76925a49f0b2f82eca5ed 100644 (file)
 #![deny(const_err)]
 
 const X: *const u8 = b"" as _;
+const Y: bool = 'A' == 'B';
+const Z: char = 'A';
+const W: bool = Z <= 'B';
+
 
 fn main() {
     let _ = ((-1 as i8) << 8 - 1) as f32;