@@ -51,14 +51,19 @@ pub(super) fn check<'tcx>(
51
51
// Ensure that the binary operator is &&
52
52
if and_op. node == BinOpKind :: And ;
53
53
54
- let typeck_results = cx. typeck_results( ) ;
55
- let mut const_context = consts:: ConstEvalLateContext :: new( cx, typeck_results) ;
54
+ // Check that both operands to '&&' are themselves a binary operation
55
+ // The `comparison_to_const` step also checks this, so this step is just an optimization
56
+ if let ExprKind :: Binary ( _, _, _) = left_cond. kind;
57
+ if let ExprKind :: Binary ( _, _, _) = right_cond. kind;
58
+
59
+ let typeck = cx. typeck_results( ) ;
60
+ let mut const_context = consts:: ConstEvalLateContext :: new( cx, typeck) ;
56
61
57
62
// Check that both operands to '&&' compare a non-literal to a literal
58
63
if let Some ( ( left_cmp_op, left_expr, left_const_expr, left_const, left_type) ) =
59
- comparison_to_const( & mut const_context, typeck_results , left_cond) ;
64
+ comparison_to_const( & mut const_context, typeck , left_cond) ;
60
65
if let Some ( ( right_cmp_op, right_expr, right_const_expr, right_const, right_type) ) =
61
- comparison_to_const( & mut const_context, typeck_results , right_cond) ;
66
+ comparison_to_const( & mut const_context, typeck , right_cond) ;
62
67
63
68
if left_type == right_type;
64
69
0 commit comments