1
1
use clippy_config:: Conf ;
2
2
use clippy_utils:: diagnostics:: { span_lint, span_lint_and_note, span_lint_and_then} ;
3
+ use clippy_utils:: higher:: has_let_expr;
3
4
use clippy_utils:: source:: { IntoSpan , SpanRangeExt , first_line_of_span, indent_of, reindent_multiline, snippet} ;
4
5
use clippy_utils:: ty:: { InteriorMut , needs_ordered_drop} ;
5
6
use clippy_utils:: visitors:: for_each_expr_without_closures;
@@ -11,7 +12,7 @@ use clippy_utils::{
11
12
use core:: iter;
12
13
use core:: ops:: ControlFlow ;
13
14
use 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} ;
15
16
use rustc_lint:: { LateContext , LateLintPass } ;
16
17
use rustc_middle:: ty:: TyCtxt ;
17
18
use rustc_session:: impl_lint_pass;
@@ -189,24 +190,13 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste<'tcx> {
189
190
}
190
191
}
191
192
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
-
203
193
fn lint_if_same_then_else ( cx : & LateContext < ' _ > , conds : & [ & Expr < ' _ > ] , blocks : & [ & Block < ' _ > ] ) -> bool {
204
194
let mut eq = SpanlessEq :: new ( cx) ;
205
195
blocks
206
196
. array_windows :: < 2 > ( )
207
197
. enumerate ( )
208
198
. 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) ) {
210
200
span_lint_and_note (
211
201
cx,
212
202
IF_SAME_THEN_ELSE ,
0 commit comments