1
1
use clippy_utils:: consts:: { constant_simple, Constant } ;
2
2
use clippy_utils:: diagnostics:: { span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then} ;
3
+ use clippy_utils:: higher;
3
4
use clippy_utils:: source:: snippet;
4
5
use clippy_utils:: ty:: match_type;
5
6
use clippy_utils:: {
@@ -17,8 +18,8 @@ use rustc_hir::def_id::DefId;
17
18
use rustc_hir:: hir_id:: CRATE_HIR_ID ;
18
19
use rustc_hir:: intravisit:: { NestedVisitorMap , Visitor } ;
19
20
use rustc_hir:: {
20
- BinOpKind , Block , Crate , Expr , ExprKind , HirId , Item , Local , MatchSource , MutTy , Mutability , Node , Path , Stmt ,
21
- StmtKind , Ty , TyKind , UnOp ,
21
+ BinOpKind , Block , Crate , Expr , ExprKind , HirId , Item , Local , MutTy , Mutability , Node , Path , Stmt , StmtKind , Ty ,
22
+ TyKind , UnOp ,
22
23
} ;
23
24
use rustc_lint:: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext } ;
24
25
use rustc_middle:: hir:: map:: Map ;
@@ -1106,16 +1107,10 @@ impl<'tcx> LateLintPass<'tcx> for IfChainStyle {
1106
1107
}
1107
1108
1108
1109
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
1109
- let ( cond, then, els) = match expr. kind {
1110
- ExprKind :: If ( cond, then, els) => ( Some ( cond) , then, els. is_some ( ) ) ,
1111
- ExprKind :: Match (
1112
- _,
1113
- [ arm, ..] ,
1114
- MatchSource :: IfLetDesugar {
1115
- contains_else_clause : els,
1116
- } ,
1117
- ) => ( None , arm. body , els) ,
1118
- _ => return ,
1110
+ let ( cond, then, els) = if let Some ( higher:: IfOrIfLet { cond, r#else, then } ) = higher:: IfOrIfLet :: hir ( expr) {
1111
+ ( cond, then, r#else. is_some ( ) )
1112
+ } else {
1113
+ return ;
1119
1114
} ;
1120
1115
let then_block = match then. kind {
1121
1116
ExprKind :: Block ( block, _) => block,
@@ -1131,7 +1126,6 @@ impl<'tcx> LateLintPass<'tcx> for IfChainStyle {
1131
1126
} ;
1132
1127
// check for `if a && b;`
1133
1128
if_chain ! {
1134
- if let Some ( cond) = cond;
1135
1129
if let ExprKind :: Binary ( op, _, _) = cond. kind;
1136
1130
if op. node == BinOpKind :: And ;
1137
1131
if cx. sess( ) . source_map( ) . is_multiline( cond. span) ;
@@ -1166,9 +1160,7 @@ fn check_nested_if_chains(
1166
1160
_ => return ,
1167
1161
} ;
1168
1162
if_chain ! {
1169
- if matches!( tail. kind,
1170
- ExprKind :: If ( _, _, None )
1171
- | ExprKind :: Match ( .., MatchSource :: IfLetDesugar { contains_else_clause: false } ) ) ;
1163
+ if let Some ( higher:: IfOrIfLet { r#else: None , .. } ) = higher:: IfOrIfLet :: hir( tail) ;
1172
1164
let sm = cx. sess( ) . source_map( ) ;
1173
1165
if head
1174
1166
. iter( )
0 commit comments