mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Improved code noted by clippy.
This commit is contained in:
parent
973d676cd1
commit
d048e15835
1 changed files with 3 additions and 13 deletions
|
@ -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`
|
||||
|
|
Loading…
Reference in a new issue