Skip to content

Commit 2060266

Browse files
committed
Don't warn about char comparisons in constexprs
1 parent 40feadb commit 2060266

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/librustc_const_eval/eval.rs

+11
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,17 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
490490
_ => span_bug!(e.span, "typeck error"),
491491
})
492492
}
493+
(Char(a), Char(b)) => {
494+
Bool(match op.node {
495+
hir::BiEq => a == b,
496+
hir::BiNe => a != b,
497+
hir::BiLt => a < b,
498+
hir::BiLe => a <= b,
499+
hir::BiGe => a >= b,
500+
hir::BiGt => a > b,
501+
_ => span_bug!(e.span, "typeck error"),
502+
})
503+
}
493504

494505
_ => signal!(e, MiscBinaryOp),
495506
}

src/test/run-pass/const-err.rs

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#![deny(const_err)]
1414

1515
const X: *const u8 = b"" as _;
16+
const Y: bool = 'A' == 'B';
17+
const Z: char = 'A';
18+
const W: bool = Z <= 'B';
19+
1620

1721
fn main() {
1822
let _ = ((-1 as i8) << 8 - 1) as f32;

0 commit comments

Comments
 (0)