Skip to content

Commit

Permalink
Improved code noted by clippy.
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Dec 6, 2018
1 parent 973d676 commit d048e15
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions clippy_lints/src/implicit_return.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit d048e15

Please sign in to comment.