Skip to content

Commit c4ef06a

Browse files
authored
Merge pull request #3497 from daxpedda/master
Fix bug in `implicit_return`.
2 parents 0fb3021 + a4ec7be commit c4ef06a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Diff for: clippy_lints/src/implicit_return.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ pub struct Pass;
4747
impl Pass {
4848
fn expr_match(cx: &LateContext<'_, '_>, expr: &rustc::hir::Expr) {
4949
match &expr.node {
50-
ExprKind::Block(block, ..) => {
50+
// loops could be using `break` instead of `return`
51+
ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => {
5152
if let Some(expr) = &block.expr {
5253
Self::expr_match(cx, expr);
5354
}
@@ -85,12 +86,6 @@ impl Pass {
8586
Self::expr_match(cx, &arm.body);
8687
}
8788
},
88-
// loops could be using `break` instead of `return`
89-
ExprKind::Loop(block, ..) => {
90-
if let Some(expr) = &block.expr {
91-
Self::expr_match(cx, expr);
92-
}
93-
},
9489
// skip if it already has a return statement
9590
ExprKind::Ret(..) => (),
9691
// everything else is missing `return`

Diff for: tests/ui/implicit_return.stderr

+7-1
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)