Improved code noted by clippy.

This commit is contained in:
daxpedda 2018-12-06 13:21:04 +01:00
parent 973d676cd1
commit d048e15835
No known key found for this signature in database
GPG key ID: C722DCB6A191EEAB

View file

@ -7,6 +7,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![warn(clippy::match_same_arms)]
use crate::rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl}; use crate::rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl};
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use crate::rustc::{declare_tool_lint, lint_array}; use crate::rustc::{declare_tool_lint, lint_array};
@ -47,7 +48,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,18 +87,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);
}
// 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 // skip if it already has a return statement
ExprKind::Ret(..) => (), ExprKind::Ret(..) => (),
// everything else is missing `return` // everything else is missing `return`