Skip to content

Commit c8dd1e8

Browse files
committed
Fix type hint bug in eval_const_expr_partial().
1 parent bc524d3 commit c8dd1e8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/librustc_const_eval/eval.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -519,15 +519,23 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
519519
}
520520
hir::ExprUnary(hir::UnDeref, _) => signal!(e, UnimplementedConstVal("deref operation")),
521521
hir::ExprBinary(op, ref a, ref b) => {
522-
let b_ty = match op.node {
523-
hir::BiShl | hir::BiShr => ty_hint.erase_hint(),
524-
_ => ty_hint
522+
// Use the same type hint for the operands as for the whole
523+
// expression, except when the operation is a shift, in which
524+
// case we use no type hint for the RHS, and when the operation
525+
// is a comparison, in which case we use no type hint for
526+
// either operand.
527+
let (a_ty, b_ty) = match op.node {
528+
hir::BiShl | hir::BiShr => (ty_hint, ty_hint.erase_hint()),
529+
hir::BiEq | hir::BiLe | hir::BiLt |
530+
hir::BiNe | hir::BiGe | hir::BiGt =>
531+
(ty_hint.erase_hint(), ty_hint.erase_hint()),
532+
_ => (ty_hint, ty_hint)
525533
};
526534
// technically, if we don't have type hints, but integral eval
527535
// gives us a type through a type-suffix, cast or const def type
528536
// we need to re-eval the other value of the BinOp if it was
529537
// not inferred
530-
match (cx.eval(a, ty_hint)?,
538+
match (cx.eval(a, a_ty)?,
531539
cx.eval(b, b_ty)?) {
532540
(Float(a), Float(b)) => {
533541
use std::cmp::Ordering::*;

0 commit comments

Comments
 (0)