From 973d676cd105b3ec87e4edb99fc0fb63b374e213 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Thu, 6 Dec 2018 12:22:54 +0100 Subject: [PATCH] Fix bug in `implicit_return`. Bug was already covered by test, but test was not checked for. --- clippy_lints/src/implicit_return.rs | 6 ++++++ tests/ui/implicit_return.stderr | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index 664f182c5336..d29b508ba37a 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -90,6 +90,12 @@ fn expr_match(cx: &LateContext<'_, '_>, expr: &rustc::hir::Expr) { if let Some(expr) = &block.expr { Self::expr_match(cx, expr); } + // only needed in the case of `break` with `;` at the end + else if let Some(stmt) = block.stmts.last() { + if let rustc::hir::StmtKind::Semi(expr, ..) = &stmt.node { + Self::expr_match(cx, expr); + } + } }, // skip if it already has a return statement ExprKind::Ret(..) => (), diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index bba8d942e27d..6f4fe12757a3 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -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 | @@ -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