Skip to content

Commit 3ec71f7

Browse files
committed
use iterators for comparing arguments instead of vecs
1 parent 6e01d2c commit 3ec71f7

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

compiler-core/src/language_server/code_action.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8436,30 +8436,24 @@ impl<'a> UnwrapAnonymousFunction<'a> {
84368436
// the args we pass to the called function, so we need to collect the
84378437
// names used in both lists and check they're equal.
84388438

8439-
let mut outer_argument_names = Vec::with_capacity(arguments.len());
8440-
for a in arguments {
8441-
match &a.names {
8442-
ArgNames::Named { name, .. } => outer_argument_names.push(name),
8443-
// We can bail out early if any arguments are discarded, since
8444-
// they couldn't match those actually used.
8445-
ArgNames::Discard { .. } => return,
8446-
// Anonymous functions can't have labelled arguments.
8447-
ArgNames::NamedLabelled { .. } => unreachable!(),
8448-
ArgNames::LabelledDiscard { .. } => unreachable!(),
8449-
}
8450-
}
8439+
let outer_argument_names = arguments.iter().map(|a| match &a.names {
8440+
ArgNames::Named { name, .. } => Some(name),
8441+
// We can bail out early if any arguments are discarded, since
8442+
// they couldn't match those actually used.
8443+
ArgNames::Discard { .. } => None,
8444+
// Anonymous functions can't have labelled arguments.
8445+
ArgNames::NamedLabelled { .. } => unreachable!(),
8446+
ArgNames::LabelledDiscard { .. } => unreachable!(),
8447+
});
84518448

8452-
let mut inner_argument_names = Vec::with_capacity(arguments.len());
8453-
for a in call_arguments {
8454-
match &a.value {
8455-
TypedExpr::Var { name, .. } => inner_argument_names.push(name),
8456-
// We can bail out early if any of these aren't variables, since
8457-
// they couldn't match the inputs.
8458-
_ => return,
8459-
}
8460-
}
8449+
let inner_argument_names = call_arguments.iter().map(|a| match &a.value {
8450+
TypedExpr::Var { name, .. } => Some(name),
8451+
// We can bail out early if any of these aren't variables, since
8452+
// they couldn't match the inputs.
8453+
_ => None,
8454+
});
84618455

8462-
if inner_argument_names != outer_argument_names {
8456+
if !inner_argument_names.eq(outer_argument_names) {
84638457
return;
84648458
}
84658459

0 commit comments

Comments
 (0)