From 68a48f83e2f7151fffc5c7da92c7f11f2205a35b Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Mon, 30 Oct 2023 07:05:22 +0900 Subject: [PATCH] Fix clippy 1.73 warnings --- src/hg_connect.rs | 39 ++++++++++++++++++--------------------- src/main.rs | 17 ++++++++--------- src/store.rs | 3 ++- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/hg_connect.rs b/src/hg_connect.rs index d6536cb09..56b0e8501 100644 --- a/src/hg_connect.rs +++ b/src/hg_connect.rs @@ -653,17 +653,17 @@ pub fn find_common( } let sample = take_sample::<_, _, SAMPLE_SIZE>(&mut rng, &mut undetermined); - let (known, unknown): (Vec<_>, Vec<_>) = conn - .known(&sample) - .iter() - .zip(sample.into_iter()) - .partition_map(|(&known, head)| { - if known { - Either::Left(head) - } else { - Either::Right(head) - } - }); + let (known, unknown): (Vec<_>, Vec<_>) = + conn.known(&sample) + .iter() + .zip(sample) + .partition_map(|(&known, head)| { + if known { + Either::Left(head) + } else { + Either::Right(head) + } + }); if undetermined.is_empty() && unknown.is_empty() { return known; @@ -711,20 +711,20 @@ pub fn find_common( undetermined_count += 1; } for (cs, c) in known { - if let Some((_, mut data)) = dag.get_mut(&*c) { + if let Some((_, data)) = dag.get_mut(&*c) { data.hg_node = Some(cs.clone()); data.known = Some(true); undetermined_count -= 1; } } for (_, c) in unknown { - if let Some((_, mut data)) = dag.get_mut(&*c) { + if let Some((_, data)) = dag.get_mut(&*c) { data.known = Some(false); undetermined_count -= 1; } } for (cs, c) in &undetermined { - if let Some((_, mut data)) = dag.get_mut(c) { + if let Some((_, data)) = dag.get_mut(c) { data.hg_node = Some(cs.clone()); } } @@ -775,10 +775,8 @@ pub fn find_common( } } dag.iter() - .filter_map(|(_, data)| { - (data.known == Some(true) && !data.has_known_children) - .then(|| data.hg_node.clone().unwrap()) - }) + .filter(|(_, data)| data.known == Some(true) && !data.has_known_children) + .map(|(_, data)| data.hg_node.clone().unwrap()) .collect_vec() } @@ -793,9 +791,8 @@ pub fn get_bundle( .lock() .unwrap() .branch_heads() - .filter_map(|(h, b)| { - (branch_names.is_empty() || branch_names.contains(b)).then(|| h.clone()) - }) + .filter(|(_, b)| branch_names.is_empty() || branch_names.contains(b)) + .map(|(h, _)| h.clone()) .collect_vec() }; diff --git a/src/main.rs b/src/main.rs index b8dde71d7..807c3bdd8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -820,7 +820,8 @@ fn do_rollback( print!("{}", m); let matched_labels = labels .iter() - .filter_map(|(name, cid)| (*cid == m).then(|| *name)) + .filter(|(_, cid)| *cid == m) + .map(|(name, _)| *name) .collect_vec() .join(", "); if !matched_labels.is_empty() { @@ -1135,7 +1136,7 @@ fn do_unbundle(clonebundle: bool, mut url: OsString) -> Result<(), String> { } let mut url = hg_url(&url).unwrap(); if !["http", "https", "file"].contains(&url.scheme()) { - return Err(format!("{} urls are not supported.", url.scheme())); + Err(format!("{} urls are not supported.", url.scheme()))?; } if graft_config_enabled(None)?.unwrap_or(false) { init_graft(); @@ -1143,7 +1144,7 @@ fn do_unbundle(clonebundle: bool, mut url: OsString) -> Result<(), String> { if clonebundle { let mut conn = get_connection(&url).unwrap(); if conn.get_capability(b"clonebundles").is_none() { - return Err("Repository does not support clonebundles")?; + Err("Repository does not support clonebundles")?; } url = get_clonebundle_url(&mut *conn).ok_or("Repository didn't provide a clonebundle")?; eprintln!("Getting clone bundle from {}", url); @@ -3551,7 +3552,8 @@ fn remote_helper_import( let mut tags = None; let mut unknown_wanted_heads = wanted_refs .iter() - .filter_map(|(_, csid, cid)| cid.is_none().then(|| (*csid).clone())) + .filter(|(_, _, cid)| cid.is_none()) + .map(|(_, csid, _)| (*csid).clone()) .unique() .collect_vec(); if !unknown_wanted_heads.is_empty() { @@ -3719,11 +3721,8 @@ fn remote_helper_push( .lock() .unwrap() .branch_heads() - .filter_map(|(h, b)| { - branch_names - .contains(b) - .then(|| format!("^{}", h.to_git().unwrap())) - }) + .filter(|(_, b)| branch_names.contains(*b)) + .map(|(h, _)| format!("^{}", h.to_git().unwrap())) .chain(push_commits.iter().map(ToString::to_string)) .chain(["--topo-order".to_string(), "--full-history".to_string()]), ) diff --git a/src/store.rs b/src/store.rs index 5ab1b1ef5..24875d464 100644 --- a/src/store.rs +++ b/src/store.rs @@ -844,7 +844,8 @@ impl TagSet { pub fn iter(&self) -> impl Iterator { self.tags .iter() - .filter_map(|(tag, (node, _))| (node != &HgChangesetId::null()).then(|| (&**tag, node))) + .filter(|(_, (node, _))| node != &HgChangesetId::null()) + .map(|(tag, (node, _))| (&**tag, node)) } }