@@ -8358,37 +8358,43 @@ impl<'ast> ast::visit::Visit<'ast> for UnwrapAnonymousFunction<'ast> {
8358
8358
// We need the existing argument list for the fn to be a 1:1 match for the args we pass
8359
8359
// to the called function. We figure out what the call-arg list needs to look like here,
8360
8360
// and bail out if any incoming args are discarded.
8361
- let mut expected_arguments = Vec :: with_capacity ( arguments. len ( ) ) ;
8361
+ let mut expected_argument_names = Vec :: with_capacity ( arguments. len ( ) ) ;
8362
8362
for a in arguments {
8363
8363
match & a. names {
8364
- ArgNames :: Named { name, .. } => expected_arguments . push ( name) ,
8365
- ArgNames :: NamedLabelled { name, .. } => expected_arguments . push ( name) ,
8364
+ ArgNames :: Named { name, .. } => expected_argument_names . push ( name) ,
8365
+ ArgNames :: NamedLabelled { name, .. } => expected_argument_names . push ( name) ,
8366
8366
ArgNames :: Discard { .. } => return ,
8367
8367
ArgNames :: LabelledDiscard { .. } => return ,
8368
8368
}
8369
8369
}
8370
8370
8371
- // match fn bodies with only a single function call
8372
- if let [ stmt] = body. as_slice ( )
8373
- && let TypedStatement :: Expression ( expr) = stmt
8374
- && let TypedExpr :: Call { fun, arguments, .. } = expr
8375
- {
8376
- let mut call_arguments = Vec :: with_capacity ( arguments. len ( ) ) ;
8377
- for a in arguments {
8378
- match & a. value {
8379
- TypedExpr :: Var { name, .. } => call_arguments. push ( name) ,
8380
- _ => return ,
8381
- }
8382
- }
8371
+ // We can only apply to anonymous functions containing a single function call
8372
+ let [
8373
+ TypedStatement :: Expression ( TypedExpr :: Call {
8374
+ fun : called_function,
8375
+ arguments : call_arguments,
8376
+ ..
8377
+ } ) ,
8378
+ ] = body. as_slice ( )
8379
+ else {
8380
+ return ;
8381
+ } ;
8383
8382
8384
- if call_arguments != expected_arguments {
8385
- return ;
8383
+ let mut call_argument_names = Vec :: with_capacity ( arguments. len ( ) ) ;
8384
+ for a in call_arguments {
8385
+ match & a. value {
8386
+ TypedExpr :: Var { name, .. } => call_argument_names. push ( name) ,
8387
+ _ => return ,
8386
8388
}
8389
+ }
8387
8390
8388
- self . targets . push ( FnToUnwrap {
8389
- fn_location : * location,
8390
- inner_function_location : fun. location ( ) ,
8391
- } )
8391
+ if call_argument_names != expected_argument_names {
8392
+ return ;
8392
8393
}
8394
+
8395
+ self . targets . push ( FnToUnwrap {
8396
+ fn_location : * location,
8397
+ inner_function_location : called_function. location ( ) ,
8398
+ } )
8393
8399
}
8394
8400
}
0 commit comments