about summary refs log tree commit diff
diff options
context:
space:
mode:
authory21 <30553356+y21@users.noreply.github.com>2023-11-16 23:05:17 +0100
committery21 <30553356+y21@users.noreply.github.com>2023-11-16 23:05:17 +0100
commitaca4086d7f4c889d2e55908325c782706ef4fa4f (patch)
tree821d401f717fae42b4b833a3677d6f736463d723
parent7696c9d1d506933dd4da46115dd0fd713fed6df4 (diff)
downloadrust-aca4086d7f4c889d2e55908325c782706ef4fa4f.tar.gz
rust-aca4086d7f4c889d2e55908325c782706ef4fa4f.zip
simplify matching on binop result
-rw-r--r--clippy_utils/src/eager_or_lazy.rs18
1 files changed, 7 insertions, 11 deletions
diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs
index f7a8bd131eb..4e71c6483e6 100644
--- a/clippy_utils/src/eager_or_lazy.rs
+++ b/clippy_utils/src/eager_or_lazy.rs
@@ -229,21 +229,17 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
 
                 ExprKind::Binary(op, left, right)
                     if matches!(op.node, BinOpKind::Div | BinOpKind::Rem)
-                        && let left_ty = self.cx.typeck_results().expr_ty(left)
                         && let right_ty = self.cx.typeck_results().expr_ty(right)
                         && let left = constant(self.cx, self.cx.typeck_results(), left)
-                            .and_then(|c| c.int_value(self.cx, left_ty))
                         && let right = constant(self.cx, self.cx.typeck_results(), right)
                             .and_then(|c| c.int_value(self.cx, right_ty))
-                        && match (left, right) {
-                            // `1 / x` -- x might be zero
-                            (_, None) => true,
-                            // `x / -1` -- x might be T::MIN = panic
-                            #[expect(clippy::match_same_arms)]
-                            (None, Some(FullInt::S(-1))) => true,
-                            // anything else is either fine or checked by the compiler
-                            _ => false,
-                        } =>
+                        && matches!(
+                            (left, right),
+                            // `1 / x`: x might be zero
+                            (_, None)
+                            // `x / -1`: x might be T::MIN
+                            | (None, Some(FullInt::S(-1)))
+                        ) =>
                 {
                     self.eagerness |= NoChange;
                 },