mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Fix items_after_statements for sub-functions
This commit is contained in:
parent
6528749083
commit
be983fbf52
2 changed files with 28 additions and 28 deletions
|
@ -1081,18 +1081,6 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
|||
arg: &hir::Expr,
|
||||
span: Span,
|
||||
) {
|
||||
if name != "expect" {
|
||||
return;
|
||||
}
|
||||
|
||||
let self_type = cx.tables.expr_ty(self_expr);
|
||||
let known_types = &[&paths::OPTION, &paths::RESULT];
|
||||
|
||||
// if not a known type, return early
|
||||
if known_types.iter().all(|&k| !match_type(cx, self_type, k)) {
|
||||
return;
|
||||
}
|
||||
|
||||
fn is_call(node: &hir::ExprKind) -> bool {
|
||||
match node {
|
||||
hir::ExprKind::AddrOf(_, expr) => {
|
||||
|
@ -1107,6 +1095,18 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
|||
}
|
||||
}
|
||||
|
||||
if name != "expect" {
|
||||
return;
|
||||
}
|
||||
|
||||
let self_type = cx.tables.expr_ty(self_expr);
|
||||
let known_types = &[&paths::OPTION, &paths::RESULT];
|
||||
|
||||
// if not a known type, return early
|
||||
if known_types.iter().all(|&k| !match_type(cx, self_type, k)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if !is_call(&arg.node) {
|
||||
return;
|
||||
}
|
||||
|
@ -1338,14 +1338,6 @@ fn lint_iter_cloned_collect(cx: &LateContext<'_, '_>, expr: &hir::Expr, iter_arg
|
|||
}
|
||||
|
||||
fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args: &[hir::Expr]) {
|
||||
// Check that this is a call to Iterator::fold rather than just some function called fold
|
||||
if !match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert!(fold_args.len() == 3,
|
||||
"Expected fold_args to have three entries - the receiver, the initial value and the closure");
|
||||
|
||||
fn check_fold_with_op(
|
||||
cx: &LateContext<'_, '_>,
|
||||
fold_args: &[hir::Expr],
|
||||
|
@ -1402,6 +1394,14 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
|
|||
}
|
||||
}
|
||||
|
||||
// Check that this is a call to Iterator::fold rather than just some function called fold
|
||||
if !match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert!(fold_args.len() == 3,
|
||||
"Expected fold_args to have three entries - the receiver, the initial value and the closure");
|
||||
|
||||
// Check if the first argument to .fold is a suitable literal
|
||||
match fold_args[1].node {
|
||||
hir::ExprKind::Lit(ref lit) => {
|
||||
|
|
|
@ -46,6 +46,14 @@ pub struct Range<'a> {
|
|||
|
||||
/// Higher a `hir` range to something similar to `ast::ExprKind::Range`.
|
||||
pub fn range<'a, 'b, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'b hir::Expr) -> Option<Range<'b>> {
|
||||
/// Find the field named `name` in the field. Always return `Some` for
|
||||
/// convenience.
|
||||
fn get_field<'a>(name: &str, fields: &'a [hir::Field]) -> Option<&'a hir::Expr> {
|
||||
let expr = &fields.iter().find(|field| field.ident.name == name)?.expr;
|
||||
|
||||
Some(expr)
|
||||
}
|
||||
|
||||
|
||||
let def_path = match cx.tables.expr_ty(expr).sty {
|
||||
ty::Adt(def, _) => cx.tcx.def_path(def.did),
|
||||
|
@ -75,14 +83,6 @@ pub fn range<'a, 'b, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'b hir::Expr) -> O
|
|||
return None;
|
||||
}
|
||||
|
||||
/// Find the field named `name` in the field. Always return `Some` for
|
||||
/// convenience.
|
||||
fn get_field<'a>(name: &str, fields: &'a [hir::Field]) -> Option<&'a hir::Expr> {
|
||||
let expr = &fields.iter().find(|field| field.ident.name == name)?.expr;
|
||||
|
||||
Some(expr)
|
||||
}
|
||||
|
||||
// The range syntax is expanded to literal paths starting with `core` or `std`
|
||||
// depending on
|
||||
// `#[no_std]`. Testing both instead of resolving the paths.
|
||||
|
|
Loading…
Reference in a new issue