From 9db046795e88d4ce170f0e47a0d4eb0e51e59d59 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 2 Oct 2024 23:13:49 +0200 Subject: [PATCH] style: remove redundant else blocks --- Cargo.toml | 1 + cli/src/cli_util.rs | 12 +++++------- cli/src/commands/file/untrack.rs | 7 +++---- cli/src/commands/workspace/.add.rs.swp | Bin 0 -> 16384 bytes cli/src/commands/workspace/add.rs | 3 +-- lib/src/default_index/rev_walk.rs | 5 ++--- lib/src/default_index/store.rs | 4 +--- lib/src/file_util.rs | 8 ++++---- lib/src/merged_tree.rs | 3 +-- lib/src/simple_op_store.rs | 8 ++++---- 10 files changed, 22 insertions(+), 29 deletions(-) create mode 100644 cli/src/commands/workspace/.add.rs.swp diff --git a/Cargo.toml b/Cargo.toml index 50062118d3..819f417c14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -135,6 +135,7 @@ testutils = { path = "lib/testutils" } [workspace.lints.clippy] explicit_iter_loop = "deny" implicit_clone = "deny" +redundant_else = "deny" semicolon_if_nothing_returned = "deny" uninlined_format_args = "deny" diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 301e9b2382..bd0c031c73 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -3009,15 +3009,13 @@ fn resolve_aliases( string_args.extend_from_slice(&alias_args); resolved_aliases.insert(alias_name.clone()); continue; - } else { - return Err(user_error(format!( - r#"Alias definition for "{alias_name}" must be a string list"# - ))); } - } else { - // Not a real command and not an alias, so return what we've resolved so far - return Ok(string_args); + return Err(user_error(format!( + r#"Alias definition for "{alias_name}" must be a string list"# + ))); } + // Not a real command and not an alias, so return what we've resolved so far + return Ok(string_args); } } // No more alias commands, or hit unknown option diff --git a/cli/src/commands/file/untrack.rs b/cli/src/commands/file/untrack.rs index 97752226b0..933d024f99 100644 --- a/cli/src/commands/file/untrack.rs +++ b/cli/src/commands/file/untrack.rs @@ -97,11 +97,10 @@ pub(crate) fn cmd_file_untrack( "Files that are not ignored will be added back by the next command. Make sure they're ignored, then try again.", )); - } else { - // This means there were some concurrent changes made in the working copy. We - // don't want to mix those in, so reset the working copy again. - locked_ws.locked_wc().reset(&new_commit)?; } + // This means there were some concurrent changes made in the working copy. We + // don't want to mix those in, so reset the working copy again. + locked_ws.locked_wc().reset(&new_commit)?; } let num_rebased = tx.repo_mut().rebase_descendants(command.settings())?; if num_rebased > 0 { diff --git a/cli/src/commands/workspace/.add.rs.swp b/cli/src/commands/workspace/.add.rs.swp new file mode 100644 index 0000000000000000000000000000000000000000..9581019b574f80e260026c05cff92a6ff4fc2497 GIT binary patch literal 16384 zcmeHNZLAzs86N5fDk20-lz*ptp`A5*XWQ~a*_P7F?QOb9Thi@^Sa3Rb=Iq_Mot@d9 zbLQTzv}ytxgE28i{)vJLY9i<#KZpU1@hi~~j7f?75J*TA6C=?d#vdj=?>Y0eAEhMv zgP57*xqEl!ocFx%d*1VY&93e^(LKa&aduj`uC=TkPyM_9K;vgy_Wa$kq&K9ym%Ucg zet&$~QI_=y5Nz+~8}0S=wjYIUDg3sd42NDE$o6I;&d8DH^R^cRj*xGFUOlANK&^o{ zsDV`V7e92hb@Q&BJ7~s2V=KGmi0XFCEzaLCZGZQ<2{!38t`o(0NxM$?rO{W zF7PDqDDVjI8NdY&0yhFz0I$B=vVIDD1^6`Z0B{=E3tS1je3fNA1w0Ns1_VG0xE{Fp zF3b8Y@MYkOKo2+w8~|2;oxmdS;yW$tA>b^~1De3Kz~A0sS$_f^1|9^)fD2p?{NhT> zdKyT8n}CaNx2$J?9{_8>`+#4+&9a^V9s*Ke2k_^&LLT55;A!A7;B&yofqQ{{00Uk| z^W>|*d0-#V0se`G%ddbZfk%PQ0ts+8una5$?**;~Xm6eaeolKd?_#(juIPiVh?~EP z6+fzQ!+_n&PUgR{=mwom%s1`W8*;~wl9=1g=5C9oT`(W?FI|pGT&YADuh~sY-^u z_O(8G324);Chl$X#F}*U07IxRI~`wePjNR0g}rTh>89f+vEt{{oJY51$|^V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Tl{G#ymBqsSXqj$UI~zlEywZK*`O z2itg0qfzP^yCC6tQc6*+S;be`D>Q+0p(Ic}`EDQ41x?oSDVg)+H_dQ)YetsxQGRYJ zNwnsW&YL~&*x;<4%tIfwe9)&UdDcB9{Su5UPA4%1HTtIcx|Cxw$+_N(N(Mbo^vZds zOmE&0?c(*?rKfJ@ukL6I=&GDxGRJ^zH|5KAbRH+(`B{26{>*<_m{&`B7>*H%>X_Va cHci}CstX~Xavn<2i RevWalk for RevWalkImpl { // No more wanted entries to walk debug_assert!(!self.queue.items.iter().any(|x| x.is_wanted())); return None; - } else { - self.queue - .extend_unwanted(index.adjacent_positions(item.pos)); } + self.queue + .extend_unwanted(index.adjacent_positions(item.pos)); } debug_assert_eq!( diff --git a/lib/src/default_index/store.rs b/lib/src/default_index/store.rs index de5b7f3191..8c516a0dec 100644 --- a/lib/src/default_index/store.rs +++ b/lib/src/default_index/store.rs @@ -354,9 +354,7 @@ impl IndexStore for DefaultIndexStore { ); } ReadonlyIndexLoadError::Other { name: _, error } => { - eprintln!( - "{err} (maybe the format has changed): {error}. Reindexing..." - ); + eprintln!("{err} (maybe the format has changed): {error}. Reindexing..."); } } self.reinit().map_err(|err| IndexReadError(err.into()))?; diff --git a/lib/src/file_util.rs b/lib/src/file_util.rs index 12c83afe9c..548ebcae4c 100644 --- a/lib/src/file_util.rs +++ b/lib/src/file_util.rs @@ -92,13 +92,13 @@ pub fn relative_path(from: &Path, to: &Path) -> PathBuf { // Find common prefix. for (i, base) in from.ancestors().enumerate() { if let Ok(suffix) = to.strip_prefix(base) { - if i == 0 && suffix.as_os_str().is_empty() { - return ".".into(); + return if i == 0 && suffix.as_os_str().is_empty() { + ".".into() } else { let mut result = PathBuf::from_iter(iter::repeat("..").take(i)); result.push(suffix); - return result; - } + result + }; } } diff --git a/lib/src/merged_tree.rs b/lib/src/merged_tree.rs index 81090aedb0..45db0a2a14 100644 --- a/lib/src/merged_tree.rs +++ b/lib/src/merged_tree.rs @@ -783,9 +783,8 @@ impl Iterator for TreeDiffIterator<'_> { path, values: Ok((before, after)), }); - } else { - unreachable!(); } + unreachable!(); } }; diff --git a/lib/src/simple_op_store.rs b/lib/src/simple_op_store.rs index 1cadb9ce9a..36b9c60463 100644 --- a/lib/src/simple_op_store.rs +++ b/lib/src/simple_op_store.rs @@ -212,12 +212,12 @@ impl OpStore for SimpleOpStore { let hex_prefix = prefix.hex(); if hex_prefix.len() == OPERATION_ID_LENGTH * 2 { // Fast path for full-length ID - if matches_root || op_dir.join(hex_prefix).try_exists()? { + return Ok(if matches_root || op_dir.join(hex_prefix).try_exists()? { let id = OperationId::from_bytes(prefix.as_full_bytes().unwrap()); - return Ok(PrefixResolution::SingleMatch(id)); + PrefixResolution::SingleMatch(id) } else { - return Ok(PrefixResolution::NoMatch); - } + PrefixResolution::NoMatch + }); } let mut matched = matches_root.then(|| self.root_operation_id.clone());