Skip to content

Commit e975a2a

Browse files
committed
use iterators for comparing arguments instead of vecs
1 parent 5ca2f53 commit e975a2a

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
@@ -7739,30 +7739,24 @@ impl<'a> UnwrapAnonymousFunction<'a> {
77397739
// the args we pass to the called function, so we need to collect the
77407740
// names used in both lists and check they're equal.
77417741

7742-
let mut outer_argument_names = Vec::with_capacity(arguments.len());
7743-
for a in arguments {
7744-
match &a.names {
7745-
ArgNames::Named { name, .. } => outer_argument_names.push(name),
7746-
// We can bail out early if any arguments are discarded, since
7747-
// they couldn't match those actually used.
7748-
ArgNames::Discard { .. } => return,
7749-
// Anonymous functions can't have labelled arguments.
7750-
ArgNames::NamedLabelled { .. } => unreachable!(),
7751-
ArgNames::LabelledDiscard { .. } => unreachable!(),
7752-
}
7753-
}
7742+
let outer_argument_names = arguments.iter().map(|a| match &a.names {
7743+
ArgNames::Named { name, .. } => Some(name),
7744+
// We can bail out early if any arguments are discarded, since
7745+
// they couldn't match those actually used.
7746+
ArgNames::Discard { .. } => None,
7747+
// Anonymous functions can't have labelled arguments.
7748+
ArgNames::NamedLabelled { .. } => unreachable!(),
7749+
ArgNames::LabelledDiscard { .. } => unreachable!(),
7750+
});
77547751

7755-
let mut inner_argument_names = Vec::with_capacity(arguments.len());
7756-
for a in call_arguments {
7757-
match &a.value {
7758-
TypedExpr::Var { name, .. } => inner_argument_names.push(name),
7759-
// We can bail out early if any of these aren't variables, since
7760-
// they couldn't match the inputs.
7761-
_ => return,
7762-
}
7763-
}
7752+
let inner_argument_names = call_arguments.iter().map(|a| match &a.value {
7753+
TypedExpr::Var { name, .. } => Some(name),
7754+
// We can bail out early if any of these aren't variables, since
7755+
// they couldn't match the inputs.
7756+
_ => None,
7757+
});
77647758

7765-
if inner_argument_names != outer_argument_names {
7759+
if !inner_argument_names.eq(outer_argument_names) {
77667760
return;
77677761
}
77687762

0 commit comments

Comments
 (0)