aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorMatthias Krüger <[email protected]>2021-03-21 12:13:34 +0000
committerMatthias Krüger <[email protected]>2021-03-21 12:13:34 +0000
commitae7e55c1dd801c60092205ec8890179e10a47814 (patch)
tree7e55e7a0c144610d55509b3e28bde0edf0953e39 /crates
parentbd407a9882250cbbb0897faba08e7d5ef80a4862 (diff)
clippy::complexity simplifications related to Iterators
Diffstat (limited to 'crates')
-rw-r--r--crates/hir/src/lib.rs2
-rw-r--r--crates/hir_def/src/attr.rs2
-rw-r--r--crates/hir_ty/src/infer/pat.rs2
-rw-r--r--crates/ide/src/extend_selection.rs7
-rw-r--r--crates/ide_assists/src/handlers/convert_comment_block.rs5
-rw-r--r--crates/ide_assists/src/handlers/expand_glob_import.rs19
-rw-r--r--crates/ide_assists/src/handlers/reorder_impl.rs2
-rw-r--r--crates/ide_completion/src/patterns.rs2
-rw-r--r--crates/ide_ssr/src/parsing.rs2
-rw-r--r--crates/mbe/src/tests/expand.rs3
-rw-r--r--crates/project_model/src/build_data.rs91
-rw-r--r--crates/syntax/src/ast/edit.rs3
12 files changed, 62 insertions, 78 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index e34be7e42..44eaeffb9 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -213,7 +213,7 @@ impl Crate {
213 Some(TokenTree::Leaf(Leaf::Literal(Literal{ref text, ..}))) => Some(text), 213 Some(TokenTree::Leaf(Leaf::Literal(Literal{ref text, ..}))) => Some(text),
214 _ => None 214 _ => None
215 } 215 }
216 }).flat_map(|t| t).next(); 216 }).flatten().next();
217 217
218 doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/") 218 doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
219 } 219 }
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs
index 2c10f46d8..52a2bce9b 100644
--- a/crates/hir_def/src/attr.rs
+++ b/crates/hir_def/src/attr.rs
@@ -638,7 +638,7 @@ fn collect_attrs(
638 owner: &dyn ast::AttrsOwner, 638 owner: &dyn ast::AttrsOwner,
639) -> impl Iterator<Item = Either<ast::Attr, ast::Comment>> { 639) -> impl Iterator<Item = Either<ast::Attr, ast::Comment>> {
640 let (inner_attrs, inner_docs) = inner_attributes(owner.syntax()) 640 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)));
642 642
643 let outer_attrs = owner.attrs().filter(|attr| attr.excl_token().is_none()); 643 let outer_attrs = owner.attrs().filter(|attr| attr.excl_token().is_none());
644 let attrs = outer_attrs 644 let attrs = outer_attrs
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs
index befa0d69b..ec491648f 100644
--- a/crates/hir_ty/src/infer/pat.rs
+++ b/crates/hir_ty/src/infer/pat.rs
@@ -38,7 +38,7 @@ impl<'a> InferenceContext<'a> {
38 let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); 38 let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default();
39 let (pre, post) = match ellipsis { 39 let (pre, post) = match ellipsis {
40 Some(idx) => subpats.split_at(idx), 40 Some(idx) => subpats.split_at(idx),
41 None => (&subpats[..], &[][..]), 41 None => (subpats, &[][..]),
42 }; 42 };
43 let post_idx_offset = field_tys.iter().count() - post.len(); 43 let post_idx_offset = field_tys.iter().count() - post.len();
44 44
diff --git a/crates/ide/src/extend_selection.rs b/crates/ide/src/extend_selection.rs
index e187243cb..5201ce587 100644
--- a/crates/ide/src/extend_selection.rs
+++ b/crates/ide/src/extend_selection.rs
@@ -263,11 +263,10 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
263 ) -> Option<SyntaxToken> { 263 ) -> Option<SyntaxToken> {
264 node.siblings_with_tokens(dir) 264 node.siblings_with_tokens(dir)
265 .skip(1) 265 .skip(1)
266 .skip_while(|node| match node { 266 .find(|node| match node {
267 NodeOrToken::Node(_) => false, 267 NodeOrToken::Node(_) => true,
268 NodeOrToken::Token(it) => is_single_line_ws(it), 268 NodeOrToken::Token(it) => !is_single_line_ws(it),
269 }) 269 })
270 .next()
271 .and_then(|it| it.into_token()) 270 .and_then(|it| it.into_token())
272 .filter(|node| node.kind() == delimiter_kind) 271 .filter(|node| node.kind() == delimiter_kind)
273 } 272 }
diff --git a/crates/ide_assists/src/handlers/convert_comment_block.rs b/crates/ide_assists/src/handlers/convert_comment_block.rs
index cdc45fc42..9dc3ee28f 100644
--- a/crates/ide_assists/src/handlers/convert_comment_block.rs
+++ b/crates/ide_assists/src/handlers/convert_comment_block.rs
@@ -1,5 +1,4 @@
1use itertools::Itertools; 1use itertools::Itertools;
2use std::convert::identity;
3use syntax::{ 2use syntax::{
4 ast::{ 3 ast::{
5 self, 4 self,
@@ -140,7 +139,7 @@ fn relevant_line_comments(comment: &ast::Comment) -> Vec<Comment> {
140 .filter(|s| !skippable(s)) 139 .filter(|s| !skippable(s))
141 .map(|not| not.into_token().and_then(Comment::cast).filter(same_prefix)) 140 .map(|not| not.into_token().and_then(Comment::cast).filter(same_prefix))
142 .take_while(|opt_com| opt_com.is_some()) 141 .take_while(|opt_com| opt_com.is_some())
143 .filter_map(identity) 142 .flatten()
144 .skip(1); // skip the first element so we don't duplicate it in next_comments 143 .skip(1); // skip the first element so we don't duplicate it in next_comments
145 144
146 let next_comments = comment 145 let next_comments = comment
@@ -149,7 +148,7 @@ fn relevant_line_comments(comment: &ast::Comment) -> Vec<Comment> {
149 .filter(|s| !skippable(s)) 148 .filter(|s| !skippable(s))
150 .map(|not| not.into_token().and_then(Comment::cast).filter(same_prefix)) 149 .map(|not| not.into_token().and_then(Comment::cast).filter(same_prefix))
151 .take_while(|opt_com| opt_com.is_some()) 150 .take_while(|opt_com| opt_com.is_some())
152 .filter_map(identity); 151 .flatten();
153 152
154 let mut comments: Vec<_> = prev_comments.collect(); 153 let mut comments: Vec<_> = prev_comments.collect();
155 comments.reverse(); 154 comments.reverse();
diff --git a/crates/ide_assists/src/handlers/expand_glob_import.rs b/crates/ide_assists/src/handlers/expand_glob_import.rs
index 83aa11d52..98389e4f7 100644
--- a/crates/ide_assists/src/handlers/expand_glob_import.rs
+++ b/crates/ide_assists/src/handlers/expand_glob_import.rs
@@ -136,18 +136,13 @@ impl Refs {
136 .into_iter() 136 .into_iter()
137 .filter(|r| { 137 .filter(|r| {
138 if let Def::ModuleDef(ModuleDef::Trait(tr)) = r.def { 138 if let Def::ModuleDef(ModuleDef::Trait(tr)) = r.def {
139 if tr 139 if tr.items(ctx.db()).into_iter().any(|ai| {
140 .items(ctx.db()) 140 if let AssocItem::Function(f) = ai {
141 .into_iter() 141 Def::ModuleDef(ModuleDef::Function(f)).is_referenced_in(ctx)
142 .find(|ai| { 142 } else {
143 if let AssocItem::Function(f) = *ai { 143 false
144 Def::ModuleDef(ModuleDef::Function(f)).is_referenced_in(ctx) 144 }
145 } else { 145 }) {
146 false
147 }
148 })
149 .is_some()
150 {
151 return true; 146 return true;
152 } 147 }
153 } 148 }
diff --git a/crates/ide_assists/src/handlers/reorder_impl.rs b/crates/ide_assists/src/handlers/reorder_impl.rs
index edf4b0bfe..f976e73ad 100644
--- a/crates/ide_assists/src/handlers/reorder_impl.rs
+++ b/crates/ide_assists/src/handlers/reorder_impl.rs
@@ -95,7 +95,7 @@ fn compute_method_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<FxHashM
95 _ => None, 95 _ => None,
96 }) 96 })
97 .enumerate() 97 .enumerate()
98 .map(|(idx, func)| ((func.name(ctx.db()).to_string(), idx))) 98 .map(|(idx, func)| (func.name(ctx.db()).to_string(), idx))
99 .collect(), 99 .collect(),
100 ) 100 )
101} 101}
diff --git a/crates/ide_completion/src/patterns.rs b/crates/ide_completion/src/patterns.rs
index cf5ef07b7..d82564381 100644
--- a/crates/ide_completion/src/patterns.rs
+++ b/crates/ide_completion/src/patterns.rs
@@ -71,7 +71,7 @@ fn test_has_block_expr_parent() {
71} 71}
72 72
73pub(crate) fn has_bind_pat_parent(element: SyntaxElement) -> bool { 73pub(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)
75} 75}
76#[test] 76#[test]
77fn test_has_bind_pat_parent() { 77fn test_has_bind_pat_parent() {
diff --git a/crates/ide_ssr/src/parsing.rs b/crates/ide_ssr/src/parsing.rs
index 5ff25cb6d..5e757e701 100644
--- a/crates/ide_ssr/src/parsing.rs
+++ b/crates/ide_ssr/src/parsing.rs
@@ -67,7 +67,7 @@ impl ParsedRule {
67 ) -> Result<Vec<ParsedRule>, SsrError> { 67 ) -> Result<Vec<ParsedRule>, SsrError> {
68 let raw_pattern = pattern.as_rust_code(); 68 let raw_pattern = pattern.as_rust_code();
69 let raw_template = template.map(|t| t.as_rust_code()); 69 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();
71 let mut builder = RuleBuilder { 71 let mut builder = RuleBuilder {
72 placeholders_by_stand_in: pattern.placeholders_by_stand_in(), 72 placeholders_by_stand_in: pattern.placeholders_by_stand_in(),
73 rules: Vec::new(), 73 rules: Vec::new(),
diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs
index 2cce62781..8951f3813 100644
--- a/crates/mbe/src/tests/expand.rs
+++ b/crates/mbe/src/tests/expand.rs
@@ -1225,8 +1225,7 @@ macro_rules! m {
1225 ) 1225 )
1226 .expand_statements(r#"m!(C("0"))"#) 1226 .expand_statements(r#"m!(C("0"))"#)
1227 .descendants() 1227 .descendants()
1228 .find(|token| token.kind() == ERROR) 1228 .any(|token| token.kind() == ERROR));
1229 .is_some());
1230} 1229}
1231 1230
1232#[test] 1231#[test]
diff --git a/crates/project_model/src/build_data.rs b/crates/project_model/src/build_data.rs
index 728a258ea..f7050be4e 100644
--- a/crates/project_model/src/build_data.rs
+++ b/crates/project_model/src/build_data.rs
@@ -137,60 +137,53 @@ fn collect_from_workspace(
137 let stdout = BufReader::new(child_stdout); 137 let stdout = BufReader::new(child_stdout);
138 138
139 let mut res = BuildDataMap::default(); 139 let mut res = BuildDataMap::default();
140 for message in cargo_metadata::Message::parse_stream(stdout) { 140 for message in cargo_metadata::Message::parse_stream(stdout).flatten() {
141 if let Ok(message) = message { 141 match message {
142 match message { 142 Message::BuildScriptExecuted(BuildScript {
143 Message::BuildScriptExecuted(BuildScript { 143 package_id, out_dir, cfgs, env, ..
144 package_id, 144 }) => {
145 out_dir, 145 let cfgs = {
146 cfgs, 146 let mut acc = Vec::new();
147 env, 147 for cfg in cfgs {
148 .. 148 match cfg.parse::<CfgFlag>() {
149 }) => { 149 Ok(it) => acc.push(it),
150 let cfgs = { 150 Err(err) => {
151 let mut acc = Vec::new(); 151 anyhow::bail!("invalid cfg from cargo-metadata: {}", err)
152 for cfg in cfgs { 152 }
153 match cfg.parse::<CfgFlag>() { 153 };
154 Ok(it) => acc.push(it),
155 Err(err) => {
156 anyhow::bail!("invalid cfg from cargo-metadata: {}", err)
157 }
158 };
159 }
160 acc
161 };
162 let res = res.entry(package_id.repr.clone()).or_default();
163 // cargo_metadata crate returns default (empty) path for
164 // older cargos, which is not absolute, so work around that.
165 if !out_dir.as_str().is_empty() {
166 let out_dir = AbsPathBuf::assert(PathBuf::from(out_dir.into_os_string()));
167 res.out_dir = Some(out_dir);
168 res.cfgs = cfgs;
169 } 154 }
170 155 acc
171 res.envs = env; 156 };
157 let res = res.entry(package_id.repr.clone()).or_default();
158 // cargo_metadata crate returns default (empty) path for
159 // older cargos, which is not absolute, so work around that.
160 if !out_dir.as_str().is_empty() {
161 let out_dir = AbsPathBuf::assert(PathBuf::from(out_dir.into_os_string()));
162 res.out_dir = Some(out_dir);
163 res.cfgs = cfgs;
172 } 164 }
173 Message::CompilerArtifact(message) => { 165
174 progress(format!("metadata {}", message.target.name)); 166 res.envs = env;
175 167 }
176 if message.target.kind.contains(&"proc-macro".to_string()) { 168 Message::CompilerArtifact(message) => {
177 let package_id = message.package_id; 169 progress(format!("metadata {}", message.target.name));
178 // Skip rmeta file 170
179 if let Some(filename) = message.filenames.iter().find(|name| is_dylib(name)) 171 if message.target.kind.contains(&"proc-macro".to_string()) {
180 { 172 let package_id = message.package_id;
181 let filename = AbsPathBuf::assert(PathBuf::from(&filename)); 173 // Skip rmeta file
182 let res = res.entry(package_id.repr.clone()).or_default(); 174 if let Some(filename) = message.filenames.iter().find(|name| is_dylib(name)) {
183 res.proc_macro_dylib_path = Some(filename); 175 let filename = AbsPathBuf::assert(PathBuf::from(&filename));
184 } 176 let res = res.entry(package_id.repr.clone()).or_default();
177 res.proc_macro_dylib_path = Some(filename);
185 } 178 }
186 } 179 }
187 Message::CompilerMessage(message) => {
188 progress(message.target.name.clone());
189 }
190 Message::BuildFinished(_) => {}
191 Message::TextLine(_) => {}
192 _ => {}
193 } 180 }
181 Message::CompilerMessage(message) => {
182 progress(message.target.name.clone());
183 }
184 Message::BuildFinished(_) => {}
185 Message::TextLine(_) => {}
186 _ => {}
194 } 187 }
195 } 188 }
196 189
diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs
index 80be8b79c..365de4463 100644
--- a/crates/syntax/src/ast/edit.rs
+++ b/crates/syntax/src/ast/edit.rs
@@ -461,8 +461,7 @@ impl ast::MatchArmList {
461 let end = if let Some(comma) = start 461 let end = if let Some(comma) = start
462 .siblings_with_tokens(Direction::Next) 462 .siblings_with_tokens(Direction::Next)
463 .skip(1) 463 .skip(1)
464 .skip_while(|it| it.kind().is_trivia()) 464 .find(|it| !it.kind().is_trivia())
465 .next()
466 .filter(|it| it.kind() == T![,]) 465 .filter(|it| it.kind() == T![,])
467 { 466 {
468 comma 467 comma