Skip to content

Commit 0e064d5

Browse files
committed
Replace ConstEvalLateContext::new() with two calls to constant() to simplify the code, after PR suggestion
1 parent 9646446 commit 0e064d5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

clippy_lints/src/operators/const_comparisons.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
use std::cmp::Ordering;
44

5-
use clippy_utils::consts;
6-
use clippy_utils::consts::{ConstEvalLateContext, Constant};
5+
use clippy_utils::consts::{constant, Constant};
76
use if_chain::if_chain;
87
use rustc_hir::{BinOpKind, Expr, ExprKind};
98
use rustc_lint::LateContext;
@@ -20,15 +19,15 @@ use super::{IMPOSSIBLE_COMPARISONS, REDUNDANT_COMPARISONS};
2019
// Extract a comparison between a const and non-const
2120
// Flip yoda conditionals, turnings expressions like `42 < x` into `x > 42`
2221
fn comparison_to_const<'tcx>(
23-
ctx: &mut ConstEvalLateContext<'_, 'tcx>,
22+
cx: &LateContext<'tcx>,
2423
typeck: &TypeckResults<'tcx>,
2524
expr: &'tcx Expr<'tcx>,
2625
) -> Option<(CmpOp, &'tcx Expr<'tcx>, &'tcx Expr<'tcx>, Constant<'tcx>, Ty<'tcx>)> {
2726
if_chain! {
2827
if let ExprKind::Binary(operator, left, right) = expr.kind;
2928
if let Ok(cmp_op) = CmpOp::try_from(operator.node);
3029
then {
31-
match (ctx.expr(left), ctx.expr(right)) {
30+
match (constant(cx, typeck, left), constant(cx, typeck, right)) {
3231
(Some(_), Some(_)) => None,
3332
(_, Some(con)) => Some((cmp_op, left, right, con, typeck.expr_ty(right))),
3433
(Some(con), _) => Some((cmp_op.reverse(), right, left, con, typeck.expr_ty(left))),
@@ -57,13 +56,12 @@ pub(super) fn check<'tcx>(
5756
if let ExprKind::Binary(_, _, _) = right_cond.kind;
5857

5958
let typeck = cx.typeck_results();
60-
let mut const_context = consts::ConstEvalLateContext::new(cx, typeck);
6159

6260
// Check that both operands to '&&' compare a non-literal to a literal
6361
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);
6563
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);
6765

6866
if left_type == right_type;
6967

0 commit comments

Comments
 (0)