11use clippy_config:: Conf ;
22use clippy_utils:: diagnostics:: { span_lint, span_lint_and_note, span_lint_and_then} ;
3+ use clippy_utils:: higher:: has_let_expr;
34use clippy_utils:: source:: { IntoSpan , SpanRangeExt , first_line_of_span, indent_of, reindent_multiline, snippet} ;
45use clippy_utils:: ty:: { InteriorMut , needs_ordered_drop} ;
56use clippy_utils:: visitors:: for_each_expr_without_closures;
@@ -11,7 +12,7 @@ use clippy_utils::{
1112use core:: iter;
1213use core:: ops:: ControlFlow ;
1314use rustc_errors:: Applicability ;
14- use rustc_hir:: { BinOpKind , Block , Expr , ExprKind , HirId , HirIdSet , LetStmt , Node , Stmt , StmtKind , intravisit} ;
15+ use rustc_hir:: { Block , Expr , ExprKind , HirId , HirIdSet , LetStmt , Node , Stmt , StmtKind , intravisit} ;
1516use rustc_lint:: { LateContext , LateLintPass } ;
1617use rustc_middle:: ty:: TyCtxt ;
1718use rustc_session:: impl_lint_pass;
@@ -189,24 +190,13 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste<'tcx> {
189190 }
190191}
191192
192- /// Checks if the given expression is a let chain.
193- fn contains_let ( e : & Expr < ' _ > ) -> bool {
194- match e. kind {
195- ExprKind :: Let ( ..) => true ,
196- ExprKind :: Binary ( op, lhs, rhs) if op. node == BinOpKind :: And => {
197- matches ! ( lhs. kind, ExprKind :: Let ( ..) ) || contains_let ( rhs)
198- } ,
199- _ => false ,
200- }
201- }
202-
203193fn lint_if_same_then_else ( cx : & LateContext < ' _ > , conds : & [ & Expr < ' _ > ] , blocks : & [ & Block < ' _ > ] ) -> bool {
204194 let mut eq = SpanlessEq :: new ( cx) ;
205195 blocks
206196 . array_windows :: < 2 > ( )
207197 . enumerate ( )
208198 . fold ( true , |all_eq, ( i, & [ lhs, rhs] ) | {
209- if eq. eq_block ( lhs, rhs) && !contains_let ( conds[ i] ) && conds. get ( i + 1 ) . is_none_or ( |e| !contains_let ( e) ) {
199+ if eq. eq_block ( lhs, rhs) && !has_let_expr ( conds[ i] ) && conds. get ( i + 1 ) . is_none_or ( |e| !has_let_expr ( e) ) {
210200 span_lint_and_note (
211201 cx,
212202 IF_SAME_THEN_ELSE ,
0 commit comments