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:
commit
966878ee57
@ -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),
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user