Enable clippy::manual_flatten (#8739)

This PR enables the
[`clippy::manual_flatten`](https://rust-lang.github.io/rust-clippy/master/index.html#/manual_flatten)
rule and fixes the outstanding violations.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-03-02 20:28:26 -05:00 committed by GitHub
parent f79f56f8b4
commit 503bebaacc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 20 additions and 33 deletions

View File

@ -3918,8 +3918,7 @@ impl BackgroundScanner {
let repository =
dotgit_path.and_then(|path| state.build_git_repository(path, self.fs.as_ref()));
for new_job in new_jobs {
if let Some(mut new_job) = new_job {
for mut new_job in new_jobs.into_iter().flatten() {
if let Some(containing_repository) = &repository {
new_job.containing_repository = Some(containing_repository.clone());
}
@ -3928,7 +3927,6 @@ impl BackgroundScanner {
.try_send(new_job)
.expect("channel is unbounded");
}
}
Ok(())
}

View File

@ -278,11 +278,7 @@ impl VectorDatabase {
let worktree_id = worktree_query
.query_row(params![worktree_root_path], |row| Ok(row.get::<_, i64>(0)?));
if worktree_id.is_ok() {
return Ok(true);
} else {
return Ok(false);
}
Ok(worktree_id.is_ok())
})
}
@ -302,17 +298,15 @@ impl VectorDatabase {
let digests = Rc::new(
digests
.into_iter()
.map(|p| Value::Blob(p.0.to_vec()))
.map(|digest| Value::Blob(digest.0.to_vec()))
.collect::<Vec<_>>(),
);
let rows = query.query_map(params![digests], |row| {
Ok((row.get::<_, SpanDigest>(0)?, row.get::<_, Embedding>(1)?))
})?;
for row in rows {
if let Ok(row) = row {
embeddings_by_digest.insert(row.0, row.1);
}
for (digest, embedding) in rows.flatten() {
embeddings_by_digest.insert(digest, embedding);
}
Ok(embeddings_by_digest)
@ -344,10 +338,8 @@ impl VectorDatabase {
Ok((row.get::<_, SpanDigest>(0)?, row.get::<_, Embedding>(1)?))
})?;
for row in rows {
if let Ok(row) = row {
embeddings_by_digest.insert(row.0, row.1);
}
for (digest, embedding) in rows.flatten() {
embeddings_by_digest.insert(digest, embedding);
}
}

View File

@ -3713,7 +3713,7 @@ fn open_items(
project_paths_to_open
.into_iter()
.enumerate()
.map(|(i, (abs_path, project_path))| {
.map(|(ix, (abs_path, project_path))| {
let workspace = workspace.clone();
cx.spawn(|mut cx| {
let fs = app_state.fs.clone();
@ -3721,7 +3721,7 @@ fn open_items(
let file_project_path = project_path?;
if fs.is_file(&abs_path).await {
Some((
i,
ix,
workspace
.update(&mut cx, |workspace, cx| {
workspace.open_path(file_project_path, None, true, cx)
@ -3739,10 +3739,8 @@ fn open_items(
let tasks = tasks.collect::<Vec<_>>();
let tasks = futures::future::join_all(tasks.into_iter());
for maybe_opened_path in tasks.await.into_iter() {
if let Some((i, path_open_result)) = maybe_opened_path {
opened_items[i] = Some(path_open_result);
}
for (ix, path_open_result) in tasks.await.into_iter().flatten() {
opened_items[ix] = Some(path_open_result);
}
Ok(opened_items)

View File

@ -296,9 +296,9 @@ fn main() {
let task = workspace::open_paths(&paths, &app_state, None, cx);
cx.spawn(|_| async move {
if let Some((_window, results)) = task.await.log_err() {
for result in results {
if let Some(Err(e)) = result {
log::error!("Error opening path: {}", e);
for result in results.into_iter().flatten() {
if let Err(err) = result {
log::error!("Error opening path: {err}",);
}
}
}

View File

@ -101,7 +101,6 @@ fn run_clippy(args: ClippyArgs) -> Result<()> {
"clippy::iter_kv_map",
"clippy::iter_overeager_cloned",
"clippy::let_underscore_future",
"clippy::manual_flatten",
"clippy::map_entry",
"clippy::needless_arbitrary_self_type",
"clippy::needless_borrowed_reference",