about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2025-07-25 15:08:50 +0200
committerPhilipp Krones <hello@philkrones.com>2025-07-25 15:08:50 +0200
commitd0fa808df5b2dbcecfadaa5fc7017ca6444ba883 (patch)
treebcee3b99ff5656b54fd5a5546766300879402519
parent31baffd6eee81c649b552d5eae9dbf2d6a9fa911 (diff)
downloadrust-d0fa808df5b2dbcecfadaa5fc7017ca6444ba883.tar.gz
rust-d0fa808df5b2dbcecfadaa5fc7017ca6444ba883.zip
Fix if_same_then_else with if let conditions
Apparently they are no longer split 1 LHS + rest RHS
-rw-r--r--clippy_lints/src/copies.rs16
1 files changed, 3 insertions, 13 deletions
diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs
index 27918698cd6..4bd34527d21 100644
--- a/clippy_lints/src/copies.rs
+++ b/clippy_lints/src/copies.rs
@@ -1,5 +1,6 @@
 use clippy_config::Conf;
 use clippy_utils::diagnostics::{span_lint, span_lint_and_note, span_lint_and_then};
+use clippy_utils::higher::has_let_expr;
 use clippy_utils::source::{IntoSpan, SpanRangeExt, first_line_of_span, indent_of, reindent_multiline, snippet};
 use clippy_utils::ty::{InteriorMut, needs_ordered_drop};
 use clippy_utils::visitors::for_each_expr_without_closures;
@@ -11,7 +12,7 @@ use clippy_utils::{
 use core::iter;
 use core::ops::ControlFlow;
 use rustc_errors::Applicability;
-use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Node, Stmt, StmtKind, intravisit};
+use rustc_hir::{Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Node, Stmt, StmtKind, intravisit};
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_middle::ty::TyCtxt;
 use rustc_session::impl_lint_pass;
@@ -189,24 +190,13 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste<'tcx> {
     }
 }
 
-/// Checks if the given expression is a let chain.
-fn contains_let(e: &Expr<'_>) -> bool {
-    match e.kind {
-        ExprKind::Let(..) => true,
-        ExprKind::Binary(op, lhs, rhs) if op.node == BinOpKind::And => {
-            matches!(lhs.kind, ExprKind::Let(..)) || contains_let(rhs)
-        },
-        _ => false,
-    }
-}
-
 fn lint_if_same_then_else(cx: &LateContext<'_>, conds: &[&Expr<'_>], blocks: &[&Block<'_>]) -> bool {
     let mut eq = SpanlessEq::new(cx);
     blocks
         .array_windows::<2>()
         .enumerate()
         .fold(true, |all_eq, (i, &[lhs, rhs])| {
-            if eq.eq_block(lhs, rhs) && !contains_let(conds[i]) && conds.get(i + 1).is_none_or(|e| !contains_let(e)) {
+            if eq.eq_block(lhs, rhs) && !has_let_expr(conds[i]) && conds.get(i + 1).is_none_or(|e| !has_let_expr(e)) {
                 span_lint_and_note(
                     cx,
                     IF_SAME_THEN_ELSE,