Skip to content

Commit 973d676

Browse files
committed
Fix bug in implicit_return.
Bug was already covered by test, but test was not checked for.
1 parent f935912 commit 973d676

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clippy_lints/src/implicit_return.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ impl Pass {
9090
if let Some(expr) = &block.expr {
9191
Self::expr_match(cx, expr);
9292
}
93+
// only needed in the case of `break` with `;` at the end
94+
else if let Some(stmt) = block.stmts.last() {
95+
if let rustc::hir::StmtKind::Semi(expr, ..) = &stmt.node {
96+
Self::expr_match(cx, expr);
97+
}
98+
}
9399
},
94100
// skip if it already has a return statement
95101
ExprKind::Ret(..) => (),

tests/ui/implicit_return.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ error: missing return statement
3030
38 | true
3131
| ^^^^ help: add `return` as shown: `return true`
3232

33+
error: missing return statement
34+
--> $DIR/implicit_return.rs:46:9
35+
|
36+
46 | break true;
37+
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
38+
3339
error: missing return statement
3440
--> $DIR/implicit_return.rs:52:9
3541
|
@@ -42,5 +48,5 @@ error: missing return statement
4248
54 | let _ = || true;
4349
| ^^^^ help: add `return` as shown: `return true`
4450

45-
error: aborting due to 7 previous errors
51+
error: aborting due to 8 previous errors
4652

0 commit comments

Comments
 (0)