about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGernot Ohner <gernot.ohner@locatee.ch>2023-10-30 15:16:23 -0600
committerGernot Ohner <gernot.ohner@locatee.ch>2023-10-30 15:16:23 -0600
commited982afc8fc27a1e57f373d8be25f69542fd149a (patch)
treeb1d9fae80471cd3ad1de99b7df9e02bea578785b
parenta799249766a34e66aeac848b96df898f404c04ff (diff)
downloadrust-ed982afc8fc27a1e57f373d8be25f69542fd149a.tar.gz
rust-ed982afc8fc27a1e57f373d8be25f69542fd149a.zip
Expliticly specify else branches in hir_utils::hash_expr
-rw-r--r--clippy_utils/src/hir_utils.rs56
1 files changed, 48 insertions, 8 deletions
diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs
index c6133417017..4a255ec108a 100644
--- a/clippy_utils/src/hir_utils.rs
+++ b/clippy_utils/src/hir_utils.rs
@@ -247,7 +247,7 @@ impl HirEqInterExpr<'_, '_, '_> {
         res
     }
 
-    #[expect(clippy::similar_names)]
+    #[expect(clippy::similar_names, clippy::too_many_lines)]
     pub fn eq_expr(&mut self, left: &Expr<'_>, right: &Expr<'_>) -> bool {
         if !self.check_ctxt(left.span.ctxt(), right.span.ctxt()) {
             return false;
@@ -346,13 +346,53 @@ impl HirEqInterExpr<'_, '_, '_> {
             (&ExprKind::OffsetOf(l_container, l_fields), &ExprKind::OffsetOf(r_container, r_fields)) => {
                 self.eq_ty(l_container, r_container) && over(l_fields, r_fields, |l, r| l.name == r.name)
             },
-            (&ExprKind::ConstBlock(_), _)
-            | (&ExprKind::Closure(_), _)
-            | (&ExprKind::Become(_), _)
-            | (&ExprKind::InlineAsm(_), _)
-            | (&ExprKind::Yield(_, _), _)
-            | (&ExprKind::Err(_), _) => false,
-            _ => false,
+            (
+                // Else branches for branches above, grouped as per `match_same_arms`.
+                | &ExprKind::AddrOf(..)
+                | &ExprKind::Array(..)
+                | &ExprKind::Assign(..)
+                | &ExprKind::AssignOp(..)
+                | &ExprKind::Binary(..)
+                | &ExprKind::Become(..)
+                | &ExprKind::Block(..)
+                | &ExprKind::Break(..)
+                | &ExprKind::Call(..)
+                | &ExprKind::Cast(..)
+                | &ExprKind::ConstBlock(..)
+                | &ExprKind::Continue(..)
+                | &ExprKind::DropTemps(..)
+                | &ExprKind::Field(..)
+                | &ExprKind::Index(..)
+                | &ExprKind::If(..)
+                | &ExprKind::Let(..)
+                | &ExprKind::Lit(..)
+                | &ExprKind::Loop(..)
+                | &ExprKind::Match(..)
+                | &ExprKind::MethodCall(..)
+                | &ExprKind::OffsetOf(..)
+                | &ExprKind::Path(..)
+                | &ExprKind::Repeat(..)
+                | &ExprKind::Ret(..)
+                | &ExprKind::Struct(..)
+                | &ExprKind::Tup(..)
+                | &ExprKind::Type(..)
+                | &ExprKind::Unary(..)
+                | &ExprKind::Yield(..)
+
+                // --- Special cases that do not have a positive branch.
+
+                // `Err` represents an invalid expression, so let's never assume that
+                // an invalid expressions is equal to anything.
+                | &ExprKind::Err(..)
+
+                // For the time being, we always consider that two closures are unequal.
+                // This behavior may change in the future.
+                | &ExprKind::Closure(..)
+                // For the time being, we always consider that two instances of InlineAsm are different.
+                // This behavior may change in the future.
+                | &ExprKind::InlineAsm(_)
+                , _
+            ) => false,
         };
         (is_eq && (!self.should_ignore(left) || !self.should_ignore(right)))
             || self.inner.expr_fallback.as_mut().map_or(false, |f| f(left, right))