@@ -4,10 +4,12 @@ use clippy_utils::eager_or_lazy::switch_to_eager_eval;
44use clippy_utils:: msrvs:: { self , Msrv } ;
55use clippy_utils:: source:: { snippet_with_applicability, snippet_with_context, walk_span_to_context} ;
66use clippy_utils:: sugg:: Sugg ;
7+ use clippy_utils:: visitors:: for_each_expr_without_closures;
78use clippy_utils:: {
8- as_some_expr, contains_return , expr_adjustment_requires_coercion, higher, is_else_clause, is_in_const_context,
9- is_none_expr , peel_blocks, sym,
9+ as_some_expr, expr_adjustment_requires_coercion, higher, is_else_clause, is_in_const_context, is_none_expr ,
10+ peel_blocks, sym,
1011} ;
12+ use core:: ops:: ControlFlow ;
1113use rustc_errors:: Applicability ;
1214use rustc_hir:: { Expr , ExprKind } ;
1315use rustc_lint:: { LateContext , LateLintPass } ;
@@ -76,8 +78,14 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone {
7678 && !is_else_clause ( cx. tcx , expr)
7779 && !is_in_const_context ( cx)
7880 && self . msrv . meets ( cx, msrvs:: BOOL_THEN )
79- && !contains_return ( then_block. stmts )
80- && then_block. expr . is_none_or ( |expr| !contains_return ( expr) )
81+ && for_each_expr_without_closures ( then_block, |e| {
82+ if matches ! ( e. kind, ExprKind :: Ret ( ..) | ExprKind :: Yield ( ..) ) {
83+ ControlFlow :: Break ( ( ) )
84+ } else {
85+ ControlFlow :: Continue ( ( ) )
86+ }
87+ } )
88+ . is_none ( )
8189 {
8290 let method_name = if switch_to_eager_eval ( cx, expr) && self . msrv . meets ( cx, msrvs:: BOOL_THEN_SOME ) {
8391 sym:: then_some
0 commit comments