Skip to content

Commit ae7e55c

Browse files
committed
clippy::complexity simplifications related to Iterators
1 parent bd407a9 commit ae7e55c

File tree

12 files changed

+62
-78
lines changed

12 files changed

+62
-78
lines changed

crates/hir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl Crate {
213213
Some(TokenTree::Leaf(Leaf::Literal(Literal{ref text, ..}))) => Some(text),
214214
_ => None
215215
}
216-
}).flat_map(|t| t).next();
216+
}).flatten().next();
217217

218218
doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
219219
}

crates/hir_def/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ fn collect_attrs(
638638
owner: &dyn ast::AttrsOwner,
639639
) -> impl Iterator<Item = Either<ast::Attr, ast::Comment>> {
640640
let (inner_attrs, inner_docs) = inner_attributes(owner.syntax())
641-
.map_or((None, None), |(attrs, docs)| ((Some(attrs), Some(docs))));
641+
.map_or((None, None), |(attrs, docs)| (Some(attrs), Some(docs)));
642642

643643
let outer_attrs = owner.attrs().filter(|attr| attr.excl_token().is_none());
644644
let attrs = outer_attrs

crates/hir_ty/src/infer/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'a> InferenceContext<'a> {
3838
let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default();
3939
let (pre, post) = match ellipsis {
4040
Some(idx) => subpats.split_at(idx),
41-
None => (&subpats[..], &[][..]),
41+
None => (subpats, &[][..]),
4242
};
4343
let post_idx_offset = field_tys.iter().count() - post.len();
4444

crates/ide/src/extend_selection.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,10 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
263263
) -> Option<SyntaxToken> {
264264
node.siblings_with_tokens(dir)
265265
.skip(1)
266-
.skip_while(|node| match node {
267-
NodeOrToken::Node(_) => false,
268-
NodeOrToken::Token(it) => is_single_line_ws(it),
266+
.find(|node| match node {
267+
NodeOrToken::Node(_) => true,
268+
NodeOrToken::Token(it) => !is_single_line_ws(it),
269269
})
270-
.next()
271270
.and_then(|it| it.into_token())
272271
.filter(|node| node.kind() == delimiter_kind)
273272
}

crates/ide_assists/src/handlers/convert_comment_block.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use itertools::Itertools;
2-
use std::convert::identity;
32
use syntax::{
43
ast::{
54
self,
@@ -140,7 +139,7 @@ fn relevant_line_comments(comment: &ast::Comment) -> Vec<Comment> {
140139
.filter(|s| !skippable(s))
141140
.map(|not| not.into_token().and_then(Comment::cast).filter(same_prefix))
142141
.take_while(|opt_com| opt_com.is_some())
143-
.filter_map(identity)
142+
.flatten()
144143
.skip(1); // skip the first element so we don't duplicate it in next_comments
145144

146145
let next_comments = comment
@@ -149,7 +148,7 @@ fn relevant_line_comments(comment: &ast::Comment) -> Vec<Comment> {
149148
.filter(|s| !skippable(s))
150149
.map(|not| not.into_token().and_then(Comment::cast).filter(same_prefix))
151150
.take_while(|opt_com| opt_com.is_some())
152-
.filter_map(identity);
151+
.flatten();
153152

154153
let mut comments: Vec<_> = prev_comments.collect();
155154
comments.reverse();

crates/ide_assists/src/handlers/expand_glob_import.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,13 @@ impl Refs {
136136
.into_iter()
137137
.filter(|r| {
138138
if let Def::ModuleDef(ModuleDef::Trait(tr)) = r.def {
139-
if tr
140-
.items(ctx.db())
141-
.into_iter()
142-
.find(|ai| {
143-
if let AssocItem::Function(f) = *ai {
144-
Def::ModuleDef(ModuleDef::Function(f)).is_referenced_in(ctx)
145-
} else {
146-
false
147-
}
148-
})
149-
.is_some()
150-
{
139+
if tr.items(ctx.db()).into_iter().any(|ai| {
140+
if let AssocItem::Function(f) = ai {
141+
Def::ModuleDef(ModuleDef::Function(f)).is_referenced_in(ctx)
142+
} else {
143+
false
144+
}
145+
}) {
151146
return true;
152147
}
153148
}

crates/ide_assists/src/handlers/reorder_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn compute_method_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<FxHashM
9595
_ => None,
9696
})
9797
.enumerate()
98-
.map(|(idx, func)| ((func.name(ctx.db()).to_string(), idx)))
98+
.map(|(idx, func)| (func.name(ctx.db()).to_string(), idx))
9999
.collect(),
100100
)
101101
}

crates/ide_completion/src/patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn test_has_block_expr_parent() {
7171
}
7272

7373
pub(crate) fn has_bind_pat_parent(element: SyntaxElement) -> bool {
74-
element.ancestors().find(|it| it.kind() == IDENT_PAT).is_some()
74+
element.ancestors().any(|it| it.kind() == IDENT_PAT)
7575
}
7676
#[test]
7777
fn test_has_bind_pat_parent() {

crates/ide_ssr/src/parsing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl ParsedRule {
6767
) -> Result<Vec<ParsedRule>, SsrError> {
6868
let raw_pattern = pattern.as_rust_code();
6969
let raw_template = template.map(|t| t.as_rust_code());
70-
let raw_template = raw_template.as_ref().map(|s| s.as_str());
70+
let raw_template = raw_template.as_deref();
7171
let mut builder = RuleBuilder {
7272
placeholders_by_stand_in: pattern.placeholders_by_stand_in(),
7373
rules: Vec::new(),

crates/mbe/src/tests/expand.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,8 +1225,7 @@ macro_rules! m {
12251225
)
12261226
.expand_statements(r#"m!(C("0"))"#)
12271227
.descendants()
1228-
.find(|token| token.kind() == ERROR)
1229-
.is_some());
1228+
.any(|token| token.kind() == ERROR));
12301229
}
12311230

12321231
#[test]

0 commit comments

Comments
 (0)