mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
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 <lnicola@dend.ro>
This commit is contained in:
commit
91200e31e3
@ -1,5 +1,4 @@
|
|||||||
use ide_db::defs::{Definition, NameRefClass};
|
use ide_db::defs::{Definition, NameRefClass};
|
||||||
use itertools::Itertools;
|
|
||||||
use syntax::{ast, AstNode, SyntaxKind, T};
|
use syntax::{ast, AstNode, SyntaxKind, T};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -79,7 +78,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let number_of_arguments = generics.len();
|
let number_of_arguments = generics.len();
|
||||||
let fish_head = std::iter::repeat("_").take(number_of_arguments).collect_vec().join(",");
|
let fish_head = std::iter::repeat("_").take(number_of_arguments).collect::<Vec<_>>().join(",");
|
||||||
|
|
||||||
acc.add(
|
acc.add(
|
||||||
AssistId("add_turbo_fish", AssistKind::RefactorRewrite),
|
AssistId("add_turbo_fish", AssistKind::RefactorRewrite),
|
||||||
|
@ -3,7 +3,6 @@ use ide_db::{
|
|||||||
defs::Definition,
|
defs::Definition,
|
||||||
search::{FileReference, SearchScope, UsageSearchResult},
|
search::{FileReference, SearchScope, UsageSearchResult},
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, FieldExpr, HasName, IdentPat, MethodCallExpr},
|
ast::{self, AstNode, FieldExpr, HasName, IdentPat, MethodCallExpr},
|
||||||
TextRange,
|
TextRange,
|
||||||
@ -121,7 +120,7 @@ fn collect_data(ident_pat: IdentPat, ctx: &AssistContext) -> Option<TupleData> {
|
|||||||
|
|
||||||
let field_names = (0..field_types.len())
|
let field_names = (0..field_types.len())
|
||||||
.map(|i| generate_name(ctx, i, &name, &ident_pat, &usages))
|
.map(|i| generate_name(ctx, i, &name, &ident_pat, &usages))
|
||||||
.collect_vec();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Some(TupleData { ident_pat, range, ref_type, field_names, usages })
|
Some(TupleData { ident_pat, range, ref_type, field_names, usages })
|
||||||
}
|
}
|
||||||
|
@ -311,18 +311,17 @@ impl Module {
|
|||||||
let (body_items, mut replacements, record_field_parents, impls) =
|
let (body_items, mut replacements, record_field_parents, impls) =
|
||||||
get_replacements_for_visibilty_change(self.body_items.clone(), false);
|
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 impl_items = Vec::new();
|
||||||
let mut this_impl_items =
|
for impl_ in impls {
|
||||||
x.syntax().descendants().fold(Vec::new(), |mut this_impl_items, x| {
|
let mut this_impl_items = Vec::new();
|
||||||
if let Some(item) = ast::Item::cast(x) {
|
for node in impl_.syntax().descendants() {
|
||||||
this_impl_items.push(item);
|
if let Some(item) = ast::Item::cast(node) {
|
||||||
}
|
this_impl_items.push(item);
|
||||||
return this_impl_items;
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
impl_items.append(&mut this_impl_items);
|
impl_items.append(&mut this_impl_items);
|
||||||
return impl_items;
|
}
|
||||||
});
|
|
||||||
|
|
||||||
let (_, mut impl_item_replacements, _, _) =
|
let (_, mut impl_item_replacements, _, _) =
|
||||||
get_replacements_for_visibilty_change(impl_items, true);
|
get_replacements_for_visibilty_change(impl_items, true);
|
||||||
|
@ -456,10 +456,10 @@ fn fn_args(
|
|||||||
/// assert_eq!(names, expected);
|
/// assert_eq!(names, expected);
|
||||||
/// ```
|
/// ```
|
||||||
fn deduplicate_arg_names(arg_names: &mut Vec<String>) {
|
fn deduplicate_arg_names(arg_names: &mut Vec<String>) {
|
||||||
let arg_name_counts = arg_names.iter().fold(FxHashMap::default(), |mut m, name| {
|
let mut arg_name_counts = FxHashMap::default();
|
||||||
*m.entry(name).or_insert(0) += 1;
|
for name in arg_names.iter() {
|
||||||
m
|
*arg_name_counts.entry(name).or_insert(0) += 1;
|
||||||
});
|
}
|
||||||
let duplicate_arg_names: FxHashSet<String> = arg_name_counts
|
let duplicate_arg_names: FxHashSet<String> = arg_name_counts
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|(_, count)| *count >= 2)
|
.filter(|(_, count)| *count >= 2)
|
||||||
|
@ -14,7 +14,6 @@ use ide::{
|
|||||||
SourceChange, TextEdit,
|
SourceChange, TextEdit,
|
||||||
};
|
};
|
||||||
use ide_db::SymbolKind;
|
use ide_db::SymbolKind;
|
||||||
use itertools::Itertools;
|
|
||||||
use lsp_server::ErrorCode;
|
use lsp_server::ErrorCode;
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
|
CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
|
||||||
@ -854,7 +853,7 @@ pub(crate) fn handle_completion_resolve(
|
|||||||
)?
|
)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|edit| edit.into_iter().map(|indel| to_proto::text_edit(&line_index, indel)))
|
.flat_map(|edit| edit.into_iter().map(|indel| to_proto::text_edit(&line_index, indel)))
|
||||||
.collect_vec();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
if !all_edits_are_disjoint(&original_completion, &additional_edits) {
|
if !all_edits_are_disjoint(&original_completion, &additional_edits) {
|
||||||
return Err(LspError::new(
|
return Err(LspError::new(
|
||||||
@ -1164,7 +1163,7 @@ pub(crate) fn handle_code_action_resolve(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_action_id(action_id: &str) -> Result<(usize, SingleResolve), String> {
|
fn parse_action_id(action_id: &str) -> Result<(usize, SingleResolve), String> {
|
||||||
let id_parts = action_id.split(':').collect_vec();
|
let id_parts = action_id.split(':').collect::<Vec<_>>();
|
||||||
match id_parts.as_slice() {
|
match id_parts.as_slice() {
|
||||||
[assist_id_string, assist_kind_string, index_string] => {
|
[assist_id_string, assist_kind_string, index_string] => {
|
||||||
let assist_kind: AssistKind = assist_kind_string.parse()?;
|
let assist_kind: AssistKind = assist_kind_string.parse()?;
|
||||||
|
Loading…
Reference in New Issue
Block a user