Skip to content

Commit d048e15

Browse files
committed
Improved code noted by clippy.
1 parent 973d676 commit d048e15

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

clippy_lints/src/implicit_return.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10+
#![warn(clippy::match_same_arms)]
1011
use crate::rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl};
1112
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1213
use crate::rustc::{declare_tool_lint, lint_array};
@@ -47,7 +48,8 @@ pub struct Pass;
4748
impl Pass {
4849
fn expr_match(cx: &LateContext<'_, '_>, expr: &rustc::hir::Expr) {
4950
match &expr.node {
50-
ExprKind::Block(block, ..) => {
51+
// loops could be using `break` instead of `return`
52+
ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => {
5153
if let Some(expr) = &block.expr {
5254
Self::expr_match(cx, expr);
5355
}
@@ -85,18 +87,6 @@ impl Pass {
8587
Self::expr_match(cx, &arm.body);
8688
}
8789
},
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-
// 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-
}
99-
},
10090
// skip if it already has a return statement
10191
ExprKind::Ret(..) => (),
10292
// everything else is missing `return`

0 commit comments

Comments
 (0)