Replace folds with for loops

This commit is contained in:
Laurențiu Nicola 2022-01-02 12:03:34 +02:00
parent b706ae22dc
commit fdf1136e79
2 changed files with 13 additions and 14 deletions

View File

@ -311,18 +311,17 @@ impl Module {
let (body_items, mut replacements, record_field_parents, impls) =
get_replacements_for_visibilty_change(self.body_items.clone(), false);
let impl_items = impls.into_iter().fold(Vec::new(), |mut impl_items, x| {
let mut this_impl_items =
x.syntax().descendants().fold(Vec::new(), |mut this_impl_items, x| {
if let Some(item) = ast::Item::cast(x) {
this_impl_items.push(item);
}
return this_impl_items;
});
let mut impl_items = Vec::new();
for impl_ in impls {
let mut this_impl_items = Vec::new();
for node in impl_.syntax().descendants() {
if let Some(item) = ast::Item::cast(node) {
this_impl_items.push(item);
}
}
impl_items.append(&mut this_impl_items);
return impl_items;
});
}
let (_, mut impl_item_replacements, _, _) =
get_replacements_for_visibilty_change(impl_items, true);

View File

@ -456,10 +456,10 @@ fn fn_args(
/// assert_eq!(names, expected);
/// ```
fn deduplicate_arg_names(arg_names: &mut Vec<String>) {
let arg_name_counts = arg_names.iter().fold(FxHashMap::default(), |mut m, name| {
*m.entry(name).or_insert(0) += 1;
m
});
let mut arg_name_counts = FxHashMap::default();
for name in arg_names.iter() {
*arg_name_counts.entry(name).or_insert(0) += 1;
}
let duplicate_arg_names: FxHashSet<String> = arg_name_counts
.into_iter()
.filter(|(_, count)| *count >= 2)