Rollup merge of #40976 - matthewjasper:char-const-expr, r=eddyb

Don't warn about `char` comparisons in constexprs

Fixes #40970 by evaluating const-exprs for comparisons on `char`s properly.
This commit is contained in:
Corey Farwell 2017-04-06 14:55:03 -04:00 committed by GitHub
commit 966878ee57
2 changed files with 15 additions and 0 deletions

View 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),
}

View File

@ -13,6 +13,10 @@
#![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;