Skip to content

Commit

Permalink
Rollup merge of rust-lang#40976 - matthewjasper:char-const-expr, r=eddyb
Browse files Browse the repository at this point in the history
Don't warn about `char` comparisons in constexprs

Fixes rust-lang#40970 by evaluating const-exprs for comparisons on `char`s properly.
  • Loading branch information
frewsxcv authored Apr 6, 2017
2 parents cce5c2d + 2060266 commit 966878e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/librustc_const_eval/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/run-pass/const-err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 966878e

Please sign in to comment.