2
2
3
3
use std:: cmp:: Ordering ;
4
4
5
- use clippy_utils:: consts;
6
- use clippy_utils:: consts:: { ConstEvalLateContext , Constant } ;
5
+ use clippy_utils:: consts:: { constant, Constant } ;
7
6
use if_chain:: if_chain;
8
7
use rustc_hir:: { BinOpKind , Expr , ExprKind } ;
9
8
use rustc_lint:: LateContext ;
@@ -20,15 +19,15 @@ use super::{IMPOSSIBLE_COMPARISONS, REDUNDANT_COMPARISONS};
20
19
// Extract a comparison between a const and non-const
21
20
// Flip yoda conditionals, turnings expressions like `42 < x` into `x > 42`
22
21
fn comparison_to_const < ' tcx > (
23
- ctx : & mut ConstEvalLateContext < ' _ , ' tcx > ,
22
+ cx : & LateContext < ' tcx > ,
24
23
typeck : & TypeckResults < ' tcx > ,
25
24
expr : & ' tcx Expr < ' tcx > ,
26
25
) -> Option < ( CmpOp , & ' tcx Expr < ' tcx > , & ' tcx Expr < ' tcx > , Constant < ' tcx > , Ty < ' tcx > ) > {
27
26
if_chain ! {
28
27
if let ExprKind :: Binary ( operator, left, right) = expr. kind;
29
28
if let Ok ( cmp_op) = CmpOp :: try_from( operator. node) ;
30
29
then {
31
- match ( ctx . expr ( left) , ctx . expr ( right) ) {
30
+ match ( constant ( cx , typeck , left) , constant ( cx , typeck , right) ) {
32
31
( Some ( _) , Some ( _) ) => None ,
33
32
( _, Some ( con) ) => Some ( ( cmp_op, left, right, con, typeck. expr_ty( right) ) ) ,
34
33
( Some ( con) , _) => Some ( ( cmp_op. reverse( ) , right, left, con, typeck. expr_ty( left) ) ) ,
@@ -57,13 +56,12 @@ pub(super) fn check<'tcx>(
57
56
if let ExprKind :: Binary ( _, _, _) = right_cond. kind;
58
57
59
58
let typeck = cx. typeck_results( ) ;
60
- let mut const_context = consts:: ConstEvalLateContext :: new( cx, typeck) ;
61
59
62
60
// Check that both operands to '&&' compare a non-literal to a literal
63
61
if let Some ( ( left_cmp_op, left_expr, left_const_expr, left_const, left_type) ) =
64
- comparison_to_const( & mut const_context , typeck, left_cond) ;
62
+ comparison_to_const( cx , typeck, left_cond) ;
65
63
if let Some ( ( right_cmp_op, right_expr, right_const_expr, right_const, right_type) ) =
66
- comparison_to_const( & mut const_context , typeck, right_cond) ;
64
+ comparison_to_const( cx , typeck, right_cond) ;
67
65
68
66
if left_type == right_type;
69
67
0 commit comments