Skip to content

Fix bug in implicit_return. #3497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions clippy_lints/src/implicit_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ pub struct Pass;
impl Pass {
fn expr_match(cx: &LateContext<'_, '_>, expr: &rustc::hir::Expr) {
match &expr.node {
ExprKind::Block(block, ..) => {
// loops could be using `break` instead of `return`
ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => {
if let Some(expr) = &block.expr {
Self::expr_match(cx, expr);
}
Expand Down Expand Up @@ -85,12 +86,6 @@ impl Pass {
Self::expr_match(cx, &arm.body);
}
},
// loops could be using `break` instead of `return`
ExprKind::Loop(block, ..) => {
if let Some(expr) = &block.expr {
Self::expr_match(cx, expr);
}
},
// skip if it already has a return statement
ExprKind::Ret(..) => (),
// everything else is missing `return`
Expand Down
8 changes: 7 additions & 1 deletion tests/ui/implicit_return.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ error: missing return statement
38 | true
| ^^^^ help: add `return` as shown: `return true`

error: missing return statement
--> $DIR/implicit_return.rs:46:9
|
46 | break true;
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`

error: missing return statement
--> $DIR/implicit_return.rs:52:9
|
Expand All @@ -42,5 +48,5 @@ error: missing return statement
54 | let _ = || true;
| ^^^^ help: add `return` as shown: `return true`

error: aborting due to 7 previous errors
error: aborting due to 8 previous errors