@@ -519,15 +519,23 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
519
519
}
520
520
hir:: ExprUnary ( hir:: UnDeref , _) => signal ! ( e, UnimplementedConstVal ( "deref operation" ) ) ,
521
521
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)
525
533
} ;
526
534
// technically, if we don't have type hints, but integral eval
527
535
// gives us a type through a type-suffix, cast or const def type
528
536
// we need to re-eval the other value of the BinOp if it was
529
537
// not inferred
530
- match ( cx. eval ( a, ty_hint ) ?,
538
+ match ( cx. eval ( a, a_ty ) ?,
531
539
cx. eval ( b, b_ty) ?) {
532
540
( Float ( a) , Float ( b) ) => {
533
541
use std:: cmp:: Ordering :: * ;
0 commit comments