Merge pull request #3497 from daxpedda/master
Fix bug in `implicit_return`.
This commit is contained in:
commit
c4ef06a9b6
2 changed files with 9 additions and 8 deletions
|
@ -47,7 +47,8 @@ pub struct Pass;
|
||||||
impl Pass {
|
impl Pass {
|
||||||
fn expr_match(cx: &LateContext<'_, '_>, expr: &rustc::hir::Expr) {
|
fn expr_match(cx: &LateContext<'_, '_>, expr: &rustc::hir::Expr) {
|
||||||
match &expr.node {
|
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 {
|
if let Some(expr) = &block.expr {
|
||||||
Self::expr_match(cx, expr);
|
Self::expr_match(cx, expr);
|
||||||
}
|
}
|
||||||
|
@ -85,12 +86,6 @@ impl Pass {
|
||||||
Self::expr_match(cx, &arm.body);
|
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
|
// skip if it already has a return statement
|
||||||
ExprKind::Ret(..) => (),
|
ExprKind::Ret(..) => (),
|
||||||
// everything else is missing `return`
|
// everything else is missing `return`
|
||||||
|
|
|
@ -30,6 +30,12 @@ error: missing return statement
|
||||||
38 | true
|
38 | true
|
||||||
| ^^^^ help: add `return` as shown: `return 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
|
error: missing return statement
|
||||||
--> $DIR/implicit_return.rs:52:9
|
--> $DIR/implicit_return.rs:52:9
|
||||||
|
|
|
|
||||||
|
@ -42,5 +48,5 @@ error: missing return statement
|
||||||
54 | let _ = || true;
|
54 | let _ = || true;
|
||||||
| ^^^^ help: add `return` as shown: `return true`
|
| ^^^^ help: add `return` as shown: `return true`
|
||||||
|
|
||||||
error: aborting due to 7 previous errors
|
error: aborting due to 8 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue