@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
22use clippy_utils:: sugg:: Sugg ;
33use clippy_utils:: ty:: is_type_diagnostic_item;
44use clippy_utils:: usage:: contains_return_break_continue_macro;
5- use clippy_utils:: { eager_or_lazy, get_enclosing_block, in_macro, is_lang_ctor} ;
5+ use clippy_utils:: { eager_or_lazy, get_enclosing_block, in_macro, is_else_clause , is_lang_ctor} ;
66use if_chain:: if_chain;
77use rustc_errors:: Applicability ;
88use rustc_hir:: LangItem :: OptionSome ;
@@ -161,13 +161,15 @@ fn detect_option_if_let_else<'tcx>(
161161 if_chain ! {
162162 if !in_macro( expr. span) ; // Don't lint macros, because it behaves weirdly
163163 if let ExprKind :: Match ( cond_expr, arms, MatchSource :: IfLetDesugar { contains_else_clause: true } ) = & expr. kind;
164+ if !is_else_clause( cx. tcx, expr) ;
164165 if arms. len( ) == 2 ;
165166 if !is_result_ok( cx, cond_expr) ; // Don't lint on Result::ok because a different lint does it already
166167 if let PatKind :: TupleStruct ( struct_qpath, & [ inner_pat] , _) = & arms[ 0 ] . pat. kind;
167168 if is_lang_ctor( cx, struct_qpath, OptionSome ) ;
168169 if let PatKind :: Binding ( bind_annotation, _, id, _) = & inner_pat. kind;
169170 if !contains_return_break_continue_macro( arms[ 0 ] . body) ;
170171 if !contains_return_break_continue_macro( arms[ 1 ] . body) ;
172+
171173 then {
172174 let capture_mut = if bind_annotation == & BindingAnnotation :: Mutable { "mut " } else { "" } ;
173175 let some_body = extract_body_from_arm( & arms[ 0 ] ) ?;
0 commit comments