Skip to content

Commit fdf1136

Browse files
committed
Replace folds with for loops
1 parent b706ae2 commit fdf1136

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

crates/ide_assists/src/handlers/extract_module.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -311,18 +311,17 @@ impl Module {
311311
let (body_items, mut replacements, record_field_parents, impls) =
312312
get_replacements_for_visibilty_change(self.body_items.clone(), false);
313313

314-
let impl_items = impls.into_iter().fold(Vec::new(), |mut impl_items, x| {
315-
let mut this_impl_items =
316-
x.syntax().descendants().fold(Vec::new(), |mut this_impl_items, x| {
317-
if let Some(item) = ast::Item::cast(x) {
318-
this_impl_items.push(item);
319-
}
320-
return this_impl_items;
321-
});
314+
let mut impl_items = Vec::new();
315+
for impl_ in impls {
316+
let mut this_impl_items = Vec::new();
317+
for node in impl_.syntax().descendants() {
318+
if let Some(item) = ast::Item::cast(node) {
319+
this_impl_items.push(item);
320+
}
321+
}
322322

323323
impl_items.append(&mut this_impl_items);
324-
return impl_items;
325-
});
324+
}
326325

327326
let (_, mut impl_item_replacements, _, _) =
328327
get_replacements_for_visibilty_change(impl_items, true);

crates/ide_assists/src/handlers/generate_function.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,10 @@ fn fn_args(
456456
/// assert_eq!(names, expected);
457457
/// ```
458458
fn deduplicate_arg_names(arg_names: &mut Vec<String>) {
459-
let arg_name_counts = arg_names.iter().fold(FxHashMap::default(), |mut m, name| {
460-
*m.entry(name).or_insert(0) += 1;
461-
m
462-
});
459+
let mut arg_name_counts = FxHashMap::default();
460+
for name in arg_names.iter() {
461+
*arg_name_counts.entry(name).or_insert(0) += 1;
462+
}
463463
let duplicate_arg_names: FxHashSet<String> = arg_name_counts
464464
.into_iter()
465465
.filter(|(_, count)| *count >= 2)

0 commit comments

Comments
 (0)