about summary refs log tree commit diff
path: root/clippy_lints/src
diff options
context:
space:
mode:
authorAlejandra González <blyxyas@gmail.com>2025-05-28 15:42:03 +0000
committerGitHub <noreply@github.com>2025-05-28 15:42:03 +0000
commit3a1159ed9f8d6939b15a028313daf93d0d83964f (patch)
treec3c989a142b58419c8241eb9502c6a6231f3c082 /clippy_lints/src
parent291b8fd3beeb65beba848958412c6e3eb7eaa525 (diff)
parentc364717b15dc7db94ea1f986c2388726b4cc34c3 (diff)
`needless_return`: look inside `else if` parts as well (#14798)
`if` expressions don't necessarily contain a block in the `else` part in
the presence of an `else if`. The `else` part, if present, must be
handled as a regular expression, not necessarily as a block expression.

Found while applying Clippy to triagebot and looking at the result. This
also found an issue in Clippy itself.

changelog: [`needless_return`]: look inside `else if` parts as well
Diffstat (limited to 'clippy_lints/src')
-rw-r--r--clippy_lints/src/panic_unimplemented.rs1
-rw-r--r--clippy_lints/src/returns.rs4
2 files changed, 3 insertions, 2 deletions
diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs
index 8962f36db1e..449d3da7639 100644
--- a/clippy_lints/src/panic_unimplemented.rs
+++ b/clippy_lints/src/panic_unimplemented.rs
@@ -152,7 +152,6 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented {
                 expr.span,
                 "`panic_any` should not be present in production code",
             );
-            return;
         }
     }
 }
diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs
index ab9b0f88f93..401b6a5635f 100644
--- a/clippy_lints/src/returns.rs
+++ b/clippy_lints/src/returns.rs
@@ -435,7 +435,9 @@ fn check_final_expr<'tcx>(
         ExprKind::If(_, then, else_clause_opt) => {
             check_block_return(cx, &then.kind, peeled_drop_expr.span, semi_spans.clone());
             if let Some(else_clause) = else_clause_opt {
-                check_block_return(cx, &else_clause.kind, peeled_drop_expr.span, semi_spans);
+                // The `RetReplacement` won't be used there as `else_clause` will be either a block or
+                // a `if` expression.
+                check_final_expr(cx, else_clause, semi_spans, RetReplacement::Empty, match_ty_opt);
             }
         },
         // a match expr, check all arms