Skip to content

Commit b9d6754

Browse files
committed
remove chained if-let
1 parent c20b981 commit b9d6754

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

compiler-core/src/language_server/code_action.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8358,37 +8358,43 @@ impl<'ast> ast::visit::Visit<'ast> for UnwrapAnonymousFunction<'ast> {
83588358
// We need the existing argument list for the fn to be a 1:1 match for the args we pass
83598359
// to the called function. We figure out what the call-arg list needs to look like here,
83608360
// 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());
83628362
for a in arguments {
83638363
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),
83668366
ArgNames::Discard { .. } => return,
83678367
ArgNames::LabelledDiscard { .. } => return,
83688368
}
83698369
}
83708370

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+
};
83838382

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,
83868388
}
8389+
}
83878390

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;
83928393
}
8394+
8395+
self.targets.push(FnToUnwrap {
8396+
fn_location: *location,
8397+
inner_function_location: called_function.location(),
8398+
})
83938399
}
83948400
}

0 commit comments

Comments
 (0)