diff options
| author | Jason Newcomb <jsnewcomb@pm.me> | 2024-08-01 00:36:21 -0400 |
|---|---|---|
| committer | Jason Newcomb <jsnewcomb@pm.me> | 2024-08-08 10:37:10 -0400 |
| commit | e4ad36d6a8c0d2947a3ce05959b6a30cf695d8df (patch) | |
| tree | 073a33ddccab1c9d9900a79d09a5b8cf92ad0ad0 /clippy_lints/src/operators/modulo_arithmetic.rs | |
| parent | d2cb227eb4582c961ad0a9b7bfce41b1e08001f0 (diff) | |
Require `ConstEvalCtxt` to be constructed.
Diffstat (limited to 'clippy_lints/src/operators/modulo_arithmetic.rs')
| -rw-r--r-- | clippy_lints/src/operators/modulo_arithmetic.rs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/clippy_lints/src/operators/modulo_arithmetic.rs b/clippy_lints/src/operators/modulo_arithmetic.rs index d65fffac5a8..c83bdda347a 100644 --- a/clippy_lints/src/operators/modulo_arithmetic.rs +++ b/clippy_lints/src/operators/modulo_arithmetic.rs @@ -1,4 +1,4 @@ -use clippy_utils::consts::{constant, Constant}; +use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::sext; use rustc_hir::{BinOpKind, Expr, ExprKind, Node}; @@ -42,15 +42,11 @@ fn used_in_comparison_with_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { }; if op.node == BinOpKind::Eq || op.node == BinOpKind::Ne { - if let Some(Constant::Int(0)) = constant(cx, cx.typeck_results(), rhs) { - return true; - } - if let Some(Constant::Int(0)) = constant(cx, cx.typeck_results(), lhs) { - return true; - } + let ecx = ConstEvalCtxt::new(cx); + matches!(ecx.eval(lhs), Some(Constant::Int(0))) || matches!(ecx.eval(rhs), Some(Constant::Int(0))) + } else { + false } - - false } struct OperandInfo { @@ -60,7 +56,7 @@ struct OperandInfo { } fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<OperandInfo> { - match constant(cx, cx.typeck_results(), operand) { + match ConstEvalCtxt::new(cx).eval(operand) { Some(Constant::Int(v)) => match *cx.typeck_results().expr_ty(expr).kind() { ty::Int(ity) => { let value = sext(cx.tcx, v, ity); |
