Skip to content

Commit be983fb

Browse files
Fix items_after_statements for sub-functions
1 parent 6528749 commit be983fb

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,18 +1081,6 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
10811081
arg: &hir::Expr,
10821082
span: Span,
10831083
) {
1084-
if name != "expect" {
1085-
return;
1086-
}
1087-
1088-
let self_type = cx.tables.expr_ty(self_expr);
1089-
let known_types = &[&paths::OPTION, &paths::RESULT];
1090-
1091-
// if not a known type, return early
1092-
if known_types.iter().all(|&k| !match_type(cx, self_type, k)) {
1093-
return;
1094-
}
1095-
10961084
fn is_call(node: &hir::ExprKind) -> bool {
10971085
match node {
10981086
hir::ExprKind::AddrOf(_, expr) => {
@@ -1107,6 +1095,18 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
11071095
}
11081096
}
11091097

1098+
if name != "expect" {
1099+
return;
1100+
}
1101+
1102+
let self_type = cx.tables.expr_ty(self_expr);
1103+
let known_types = &[&paths::OPTION, &paths::RESULT];
1104+
1105+
// if not a known type, return early
1106+
if known_types.iter().all(|&k| !match_type(cx, self_type, k)) {
1107+
return;
1108+
}
1109+
11101110
if !is_call(&arg.node) {
11111111
return;
11121112
}
@@ -1338,14 +1338,6 @@ fn lint_iter_cloned_collect(cx: &LateContext<'_, '_>, expr: &hir::Expr, iter_arg
13381338
}
13391339

13401340
fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args: &[hir::Expr]) {
1341-
// Check that this is a call to Iterator::fold rather than just some function called fold
1342-
if !match_trait_method(cx, expr, &paths::ITERATOR) {
1343-
return;
1344-
}
1345-
1346-
assert!(fold_args.len() == 3,
1347-
"Expected fold_args to have three entries - the receiver, the initial value and the closure");
1348-
13491341
fn check_fold_with_op(
13501342
cx: &LateContext<'_, '_>,
13511343
fold_args: &[hir::Expr],
@@ -1402,6 +1394,14 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
14021394
}
14031395
}
14041396

1397+
// Check that this is a call to Iterator::fold rather than just some function called fold
1398+
if !match_trait_method(cx, expr, &paths::ITERATOR) {
1399+
return;
1400+
}
1401+
1402+
assert!(fold_args.len() == 3,
1403+
"Expected fold_args to have three entries - the receiver, the initial value and the closure");
1404+
14051405
// Check if the first argument to .fold is a suitable literal
14061406
match fold_args[1].node {
14071407
hir::ExprKind::Lit(ref lit) => {

clippy_lints/src/utils/higher.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ pub struct Range<'a> {
4646

4747
/// Higher a `hir` range to something similar to `ast::ExprKind::Range`.
4848
pub fn range<'a, 'b, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'b hir::Expr) -> Option<Range<'b>> {
49+
/// Find the field named `name` in the field. Always return `Some` for
50+
/// convenience.
51+
fn get_field<'a>(name: &str, fields: &'a [hir::Field]) -> Option<&'a hir::Expr> {
52+
let expr = &fields.iter().find(|field| field.ident.name == name)?.expr;
53+
54+
Some(expr)
55+
}
56+
4957

5058
let def_path = match cx.tables.expr_ty(expr).sty {
5159
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
7583
return None;
7684
}
7785

78-
/// Find the field named `name` in the field. Always return `Some` for
79-
/// convenience.
80-
fn get_field<'a>(name: &str, fields: &'a [hir::Field]) -> Option<&'a hir::Expr> {
81-
let expr = &fields.iter().find(|field| field.ident.name == name)?.expr;
82-
83-
Some(expr)
84-
}
85-
8686
// The range syntax is expanded to literal paths starting with `core` or `std`
8787
// depending on
8888
// `#[no_std]`. Testing both instead of resolving the paths.

0 commit comments

Comments
 (0)