Skip to content

Commit 91200e3

Browse files
bors[bot]lnicola
andauthored
Merge #11161
11161: minor: style nits r=lnicola a=lnicola - avoid `fold` with a `Vec` seed which could have been a `for_each` - we can't drop the dependency, but avoid `Itertools::collect_vec` bors r+ Co-authored-by: Laurențiu Nicola <[email protected]>
2 parents b706ae2 + 53ddf48 commit 91200e3

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

crates/ide_assists/src/handlers/add_turbo_fish.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use ide_db::defs::{Definition, NameRefClass};
2-
use itertools::Itertools;
32
use syntax::{ast, AstNode, SyntaxKind, T};
43

54
use crate::{
@@ -79,7 +78,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<(
7978
}
8079

8180
let number_of_arguments = generics.len();
82-
let fish_head = std::iter::repeat("_").take(number_of_arguments).collect_vec().join(",");
81+
let fish_head = std::iter::repeat("_").take(number_of_arguments).collect::<Vec<_>>().join(",");
8382

8483
acc.add(
8584
AssistId("add_turbo_fish", AssistKind::RefactorRewrite),

crates/ide_assists/src/handlers/destructure_tuple_binding.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use ide_db::{
33
defs::Definition,
44
search::{FileReference, SearchScope, UsageSearchResult},
55
};
6-
use itertools::Itertools;
76
use syntax::{
87
ast::{self, AstNode, FieldExpr, HasName, IdentPat, MethodCallExpr},
98
TextRange,
@@ -121,7 +120,7 @@ fn collect_data(ident_pat: IdentPat, ctx: &AssistContext) -> Option<TupleData> {
121120

122121
let field_names = (0..field_types.len())
123122
.map(|i| generate_name(ctx, i, &name, &ident_pat, &usages))
124-
.collect_vec();
123+
.collect::<Vec<_>>();
125124

126125
Some(TupleData { ident_pat, range, ref_type, field_names, usages })
127126
}

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)

crates/rust-analyzer/src/handlers.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use ide::{
1414
SourceChange, TextEdit,
1515
};
1616
use ide_db::SymbolKind;
17-
use itertools::Itertools;
1817
use lsp_server::ErrorCode;
1918
use lsp_types::{
2019
CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
@@ -854,7 +853,7 @@ pub(crate) fn handle_completion_resolve(
854853
)?
855854
.into_iter()
856855
.flat_map(|edit| edit.into_iter().map(|indel| to_proto::text_edit(&line_index, indel)))
857-
.collect_vec();
856+
.collect::<Vec<_>>();
858857

859858
if !all_edits_are_disjoint(&original_completion, &additional_edits) {
860859
return Err(LspError::new(
@@ -1164,7 +1163,7 @@ pub(crate) fn handle_code_action_resolve(
11641163
}
11651164

11661165
fn parse_action_id(action_id: &str) -> Result<(usize, SingleResolve), String> {
1167-
let id_parts = action_id.split(':').collect_vec();
1166+
let id_parts = action_id.split(':').collect::<Vec<_>>();
11681167
match id_parts.as_slice() {
11691168
[assist_id_string, assist_kind_string, index_string] => {
11701169
let assist_kind: AssistKind = assist_kind_string.parse()?;

0 commit comments

Comments
 (0)