From d64d711db221e7959994e8fe22c6d8a975efcc4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 12 Mar 2022 14:26:16 +0100 Subject: [PATCH] fix clippy::map_flatten --- crates/hir/src/lib.rs | 4 ++-- crates/hir_expand/src/quote.rs | 2 +- crates/ide/src/annotations.rs | 3 +-- crates/ide_db/src/symbol_index.rs | 3 +-- crates/rust-analyzer/src/handlers.rs | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index d83fb16d10f..04171968431 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -231,7 +231,7 @@ impl Crate { return None; } - let doc_url = doc_attr_q.tt_values().map(|tt| { + let doc_url = doc_attr_q.tt_values().filter_map(|tt| { let name = tt.token_trees.iter() .skip_while(|tt| !matches!(tt, TokenTree::Leaf(Leaf::Ident(Ident { text, ..} )) if text == "html_root_url")) .nth(2); @@ -240,7 +240,7 @@ impl Crate { Some(TokenTree::Leaf(Leaf::Literal(Literal{ref text, ..}))) => Some(text), _ => None } - }).flatten().next(); + }).next(); doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/") } diff --git a/crates/hir_expand/src/quote.rs b/crates/hir_expand/src/quote.rs index 230a599641b..82f410ecda9 100644 --- a/crates/hir_expand/src/quote.rs +++ b/crates/hir_expand/src/quote.rs @@ -261,7 +261,7 @@ mod tests { // } let struct_name = mk_ident("Foo"); let fields = [mk_ident("name"), mk_ident("id")]; - let fields = fields.iter().map(|it| quote!(#it: self.#it.clone(), ).token_trees).flatten(); + let fields = fields.iter().flat_map(|it| quote!(#it: self.#it.clone(), ).token_trees); let list = tt::Subtree { delimiter: Some(tt::Delimiter { diff --git a/crates/ide/src/annotations.rs b/crates/ide/src/annotations.rs index 986db75c610..8bfcf3beb87 100644 --- a/crates/ide/src/annotations.rs +++ b/crates/ide/src/annotations.rs @@ -170,10 +170,9 @@ pub(crate) fn resolve_annotation(db: &RootDatabase, mut annotation: Annotation) result .into_iter() .flat_map(|res| res.references) - .map(|(file_id, access)| { + .flat_map(|(file_id, access)| { access.into_iter().map(move |(range, _)| FileRange { file_id, range }) }) - .flatten() .collect() }); } diff --git a/crates/ide_db/src/symbol_index.rs b/crates/ide_db/src/symbol_index.rs index b5979e6b83a..a812c838acc 100644 --- a/crates/ide_db/src/symbol_index.rs +++ b/crates/ide_db/src/symbol_index.rs @@ -120,8 +120,7 @@ fn library_symbols(db: &dyn SymbolsDatabase, source_root_id: SourceRootId) -> Ar // we specifically avoid calling SymbolsDatabase::module_symbols here, even they do the same thing, // as the index for a library is not going to really ever change, and we do not want to store each // module's index in salsa. - .map(|module| SymbolCollector::collect(db.upcast(), module)) - .flatten() + .flat_map(|module| SymbolCollector::collect(db.upcast(), module)) .collect(); Arc::new(SymbolIndex::new(symbols)) diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index b5e9776000c..e63b6f490ba 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -532,7 +532,7 @@ pub(crate) fn handle_will_rename_files( let mut source_change = source_changes.next().unwrap_or_default(); source_change.file_system_edits.clear(); // no collect here because we want to merge text edits on same file ids - source_change.extend(source_changes.map(|it| it.source_file_edits).flatten()); + source_change.extend(source_changes.flat_map(|it| it.source_file_edits)); if source_change.source_file_edits.is_empty() { Ok(None) } else {