From d048e15835e19841211ae7725511dc946bdde5e2 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Thu, 6 Dec 2018 13:21:04 +0100 Subject: [PATCH] Improved code noted by clippy. --- clippy_lints/src/implicit_return.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index d29b508ba..543948e39 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -7,6 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![warn(clippy::match_same_arms)] use crate::rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl}; use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use crate::rustc::{declare_tool_lint, lint_array}; @@ -47,7 +48,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); } @@ -85,18 +87,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); - } - // 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(..) => (), // everything else is missing `return`