@@ -1081,18 +1081,6 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
1081
1081
arg : & hir:: Expr ,
1082
1082
span : Span ,
1083
1083
) {
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
-
1096
1084
fn is_call ( node : & hir:: ExprKind ) -> bool {
1097
1085
match node {
1098
1086
hir:: ExprKind :: AddrOf ( _, expr) => {
@@ -1107,6 +1095,18 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
1107
1095
}
1108
1096
}
1109
1097
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
+
1110
1110
if !is_call ( & arg. node ) {
1111
1111
return ;
1112
1112
}
@@ -1338,14 +1338,6 @@ fn lint_iter_cloned_collect(cx: &LateContext<'_, '_>, expr: &hir::Expr, iter_arg
1338
1338
}
1339
1339
1340
1340
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
-
1349
1341
fn check_fold_with_op (
1350
1342
cx : & LateContext < ' _ , ' _ > ,
1351
1343
fold_args : & [ hir:: Expr ] ,
@@ -1402,6 +1394,14 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
1402
1394
}
1403
1395
}
1404
1396
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
+
1405
1405
// Check if the first argument to .fold is a suitable literal
1406
1406
match fold_args[ 1 ] . node {
1407
1407
hir:: ExprKind :: Lit ( ref lit) => {
0 commit comments