From 2e7b63105f1384f6ccd862b0a247c80acf4d63ba Mon Sep 17 00:00:00 2001 From: Pierre Chevalier Date: Wed, 13 Sep 2023 04:25:38 -0700 Subject: [PATCH] exec: Fix low hanging fruit clippy warnings Summary: **Split from D49099286** Reviewed By: markbt Differential Revision: D49150400 fbshipit-source-id: 82a5918a5de2a83497d25d7722b2596f7c606a13 --- eden/scm/exec/fsprobe/src/main.rs | 6 +++--- eden/scm/exec/hgmain/src/chg.rs | 2 +- eden/scm/exec/hgmain/src/main.rs | 2 +- eden/scm/exec/scratch/src/lib.rs | 2 +- eden/scm/exec/scratch/src/main.rs | 26 +++++++++----------------- 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/eden/scm/exec/fsprobe/src/main.rs b/eden/scm/exec/fsprobe/src/main.rs index 427318fddd..faecbafbcc 100644 --- a/eden/scm/exec/fsprobe/src/main.rs +++ b/eden/scm/exec/fsprobe/src/main.rs @@ -102,7 +102,7 @@ impl ProbePlan { pub fn run(self, stats: &Arc) { for action in self.0 { - action.run(&*stats); + action.run(stats); } } @@ -114,7 +114,7 @@ impl ProbePlan { let (sender, recv) = mpsc::sync_channel::(8); let thread = thread::spawn(move || { for action in recv { - action.run(&*stats) + action.run(&stats) } }); threads.push(thread); @@ -144,7 +144,7 @@ impl ProbeAction { if let Some(space) = space { let cmd = &s[..space]; let path = &s[space + 1..]; - if path.len() == 0 { + if path.is_empty() { bail!("{} requires path", cmd); } match cmd { diff --git a/eden/scm/exec/hgmain/src/chg.rs b/eden/scm/exec/hgmain/src/chg.rs index cc2d04f874..8913c4fd3c 100644 --- a/eden/scm/exec/hgmain/src/chg.rs +++ b/eden/scm/exec/hgmain/src/chg.rs @@ -39,7 +39,7 @@ fn chg_main_wrapper(args: Vec, envs: Vec) -> i32 { envp.as_mut_ptr(), name.as_c_str().as_ptr(), ) - } as i32; + }; rc } diff --git a/eden/scm/exec/hgmain/src/main.rs b/eden/scm/exec/hgmain/src/main.rs index 04bf8735b9..5be412661d 100644 --- a/eden/scm/exec/hgmain/src/main.rs +++ b/eden/scm/exec/hgmain/src/main.rs @@ -126,7 +126,7 @@ fn main() { // Run atexit handlers. atexit::drop_queued(); - std::process::exit(code as i32); + std::process::exit(code); } #[cfg(unix)] diff --git a/eden/scm/exec/scratch/src/lib.rs b/eden/scm/exec/scratch/src/lib.rs index f4959fb1bd..ae9e7a60ca 100644 --- a/eden/scm/exec/scratch/src/lib.rs +++ b/eden/scm/exec/scratch/src/lib.rs @@ -67,7 +67,7 @@ pub fn zzencode(path: &str) -> String { match b { '/' | '\\' => result.push('Z'), 'Z' => result.push_str("_Z"), - ':' => result.push_str("_"), + ':' => result.push('_'), _ => result.push(b), } } diff --git a/eden/scm/exec/scratch/src/main.rs b/eden/scm/exec/scratch/src/main.rs index cf9ac5fcc8..d6b5d923a1 100644 --- a/eden/scm/exec/scratch/src/main.rs +++ b/eden/scm/exec/scratch/src/main.rs @@ -38,11 +38,12 @@ use serde::Deserialize; /// Configuration for scratch space style. This decides whether the directory /// structure is kept exactly as provided subdir or not. -#[derive(Debug, Deserialize)] +#[derive(Debug, Default, Deserialize)] #[serde(rename_all = "lowercase")] enum ScratchStyle { /// With flat scratch style, the sub-directories are created one-level under /// the repository namespace with serialized names. + #[default] Flat, /// With mirror scratch style, the sub-directories mirror the directory @@ -50,12 +51,6 @@ enum ScratchStyle { Mirror, } -impl Default for ScratchStyle { - fn default() -> Self { - ScratchStyle::Flat - } -} - /// The configuration is intentionally very minimal, and explicitly /// not made accessible via command line options; the intent is that /// placement of the scratch space is the policy of the owner of the @@ -100,10 +95,7 @@ struct Config { fn home_dir() -> String { let home = dirs::home_dir().expect("resolved HOME dir"); home.to_str() - .expect(&format!( - "HOME dir {:?} was not representable as UTF-8", - home - )) + .unwrap_or_else(|| panic!("HOME dir {:?} was not representable as UTF-8", home)) .into() } @@ -136,7 +128,7 @@ impl Config { file.read_to_string(&mut s)?; toml::from_str(&s) - .map(|c| Some(c)) + .map(Some) .map_err(|e| format_err!("error while loading TOML from {}: {:?}", path.display(), e)) } @@ -190,8 +182,8 @@ impl Config { return over.clone(); } match &self.template { - &Some(ref s) => s.clone(), - &None => { + Some(s) => s.clone(), + None => { // This is a little bit of a hack; ideally we'd // configure this in chef, but don't have bandwidth // to prepare a recipe for this in time; will follow @@ -522,7 +514,7 @@ fn path_command( let repo_root = locate_repo_root(&path)?.unwrap_or(&path); // Get the base scratch path for this repo - let mut result = scratch_root(&config, repo_root, encoder)?; + let mut result = scratch_root(config, repo_root, encoder)?; readme_in_scratch_path(&result)?; let repo_owner = get_file_owner(repo_root)?; @@ -548,13 +540,13 @@ fn path_command( ancestors.reverse(); for ancestor in ancestors.iter() { match fs::create_dir(ancestor) { - Ok(()) => set_file_owner(&ancestor, &repo_owner)?, + Ok(()) => set_file_owner(ancestor, &repo_owner)?, Err(_) if ancestor.is_dir() => {} Err(e) => bail!(e), } } if watchable { - create_watchmanconfig(&config, &result, &repo_owner)?; + create_watchmanconfig(config, &result, &repo_owner)?; } }