From f9c73adce80e49cea2620a54a34545d5569a9d2a Mon Sep 17 00:00:00 2001 From: Mark-Simulacrum Date: Sun, 9 Oct 2016 08:43:23 -0600 Subject: [PATCH] Add comparison operators to boolean const eval. --- src/librustc_const_eval/eval.rs | 4 ++++ src/test/run-pass/const-err.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index d876b4b6fec2e..81dd642de5d27 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -732,6 +732,10 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir::BiBitOr => a | b, hir::BiEq => a == b, hir::BiNe => a != b, + hir::BiLt => a < b, + hir::BiLe => a <= b, + hir::BiGe => a >= b, + hir::BiGt => a > b, _ => signal!(e, InvalidOpForBools(op.node)), }) } diff --git a/src/test/run-pass/const-err.rs b/src/test/run-pass/const-err.rs index 9f4ae1ad927d7..a1c9ff8a21edb 100644 --- a/src/test/run-pass/const-err.rs +++ b/src/test/run-pass/const-err.rs @@ -17,4 +17,8 @@ const X: *const u8 = b"" as _; fn main() { let _ = ((-1 as i8) << 8 - 1) as f32; let _ = 0u8 as char; + let _ = true > false; + let _ = true >= false; + let _ = true < false; + let _ = true >= false; }