From eb929d1b0623e0857441643109b5f25e9ba32da2 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 17 Oct 2023 12:20:16 +0200 Subject: [PATCH] Fix some clippy warnings --- src/compiler/c.rs | 2 +- src/compiler/compiler.rs | 18 ++++++------------ src/compiler/diab.rs | 2 +- src/compiler/gcc.rs | 2 +- src/compiler/msvc.rs | 5 ++--- src/compiler/nvcc.rs | 4 ++-- src/compiler/nvhpc.rs | 4 ++-- src/compiler/rust.rs | 14 +++++++------- src/compiler/tasking_vx.rs | 4 ++-- src/server.rs | 16 ++++------------ src/util.rs | 2 +- tests/system.rs | 2 +- 12 files changed, 30 insertions(+), 45 deletions(-) diff --git a/src/compiler/c.rs b/src/compiler/c.rs index ed28fe5ca..067c0f144 100644 --- a/src/compiler/c.rs +++ b/src/compiler/c.rs @@ -704,7 +704,7 @@ pub fn hash_key( m.update(hash.as_bytes()); } - for &(ref var, ref val) in env_vars.iter() { + for (var, val) in env_vars.iter() { if CACHED_ENV_VARS.contains(var.as_os_str()) { var.hash(&mut HashToDigest { digest: &mut m }); m.update(&b"="[..]); diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index fe6a72a4a..3deeb2e10 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -641,7 +641,7 @@ where "fetched {:?}", jc.outputs .iter() - .map(|&(ref p, ref bs)| (p, bs.lens().to_string())) + .map(|(p, bs)| (p, bs.lens().to_string())) .collect::>() ); let mut output_paths: Vec = vec![]; @@ -869,19 +869,14 @@ pub enum CompileResult { } /// The state of `--color` options passed to a compiler. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Default)] pub enum ColorMode { Off, On, + #[default] Auto, } -impl Default for ColorMode { - fn default() -> ColorMode { - ColorMode::Auto - } -} - /// Can't derive(Debug) because of `CacheWriteFuture`. impl fmt::Debug for CompileResult { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -903,10 +898,9 @@ impl PartialEq for CompileResult { match (self, other) { (&CompileResult::Error, &CompileResult::Error) => true, (&CompileResult::CacheHit(_), &CompileResult::CacheHit(_)) => true, - ( - &CompileResult::CacheMiss(ref m, ref dt, _, _), - &CompileResult::CacheMiss(ref n, ref dt2, _, _), - ) => m == n && dt == dt2, + (CompileResult::CacheMiss(m, dt, _, _), CompileResult::CacheMiss(n, dt2, _, _)) => { + m == n && dt == dt2 + } (&CompileResult::NotCacheable, &CompileResult::NotCacheable) => true, (&CompileResult::CompileFailed, &CompileResult::CompileFailed) => true, _ => false, diff --git a/src/compiler/diab.rs b/src/compiler/diab.rs index 4eb3f410f..9b9a18e59 100644 --- a/src/compiler/diab.rs +++ b/src/compiler/diab.rs @@ -320,7 +320,7 @@ where .args(&parsed_args.preprocessor_args) .args(&parsed_args.common_args) .env_clear() - .envs(env_vars.iter().map(|&(ref k, ref v)| (k, v))) + .envs(env_vars.iter().map(|(k, v)| (k, v))) .current_dir(cwd); if log_enabled!(Trace) { diff --git a/src/compiler/gcc.rs b/src/compiler/gcc.rs index cc51bee26..91968b28f 100644 --- a/src/compiler/gcc.rs +++ b/src/compiler/gcc.rs @@ -692,7 +692,7 @@ fn preprocess_cmd( .args(&parsed_args.common_args) .args(arch_args_to_use) .env_clear() - .envs(env_vars.iter().map(|&(ref k, ref v)| (k, v))) + .envs(env_vars.iter().map(|(k, v)| (k, v))) .current_dir(cwd); debug!("cmd after -arch rewrite: {:?}", cmd); } diff --git a/src/compiler/msvc.rs b/src/compiler/msvc.rs index 6f6502b83..7298d93dd 100644 --- a/src/compiler/msvc.rs +++ b/src/compiler/msvc.rs @@ -951,7 +951,7 @@ where // Read for more info: https://github.com/mozilla/sccache/issues/1725 .arg("/wd4668") .env_clear() - .envs(env_vars.iter().map(|&(ref k, ref v)| (k, v))) + .envs(env_vars.iter().map(|(k, v)| (k, v))) .current_dir(cwd); if is_clang { @@ -985,8 +985,7 @@ where } let parsed_args = &parsed_args; - if let (Some(obj), &Some(ref depfile)) = (parsed_args.outputs.get("obj"), &parsed_args.depfile) - { + if let (Some(obj), Some(depfile)) = (parsed_args.outputs.get("obj"), &parsed_args.depfile) { let objfile = &obj.path; let f = File::create(cwd.join(depfile))?; let mut f = BufWriter::new(f); diff --git a/src/compiler/nvcc.rs b/src/compiler/nvcc.rs index 4d765aa5d..0e668fa5e 100644 --- a/src/compiler/nvcc.rs +++ b/src/compiler/nvcc.rs @@ -142,7 +142,7 @@ impl CCompilerImpl for Nvcc { dep_cmd .args(&transformed_deps) .env_clear() - .envs(env_vars.iter().map(|&(ref k, ref v)| (k, v))) + .envs(env_vars.iter().map(|(k, v)| (k, v))) .current_dir(cwd); if log_enabled!(Trace) { @@ -168,7 +168,7 @@ impl CCompilerImpl for Nvcc { cmd.arg("-E") .arg(no_line_num_flag) .env_clear() - .envs(env_vars.iter().map(|&(ref k, ref v)| (k, v))) + .envs(env_vars.iter().map(|(k, v)| (k, v))) .current_dir(cwd); if log_enabled!(Trace) { trace!("preprocess: {:?}", cmd); diff --git a/src/compiler/nvhpc.rs b/src/compiler/nvhpc.rs index 247b2a425..de0b704b8 100644 --- a/src/compiler/nvhpc.rs +++ b/src/compiler/nvhpc.rs @@ -119,7 +119,7 @@ impl CCompilerImpl for Nvhpc { dep_cmd .args(&transformed_deps) .env_clear() - .envs(env_vars.iter().map(|&(ref k, ref v)| (k, v))) + .envs(env_vars.iter().map(|(k, v)| (k, v))) .current_dir(cwd); if log_enabled!(Trace) { @@ -134,7 +134,7 @@ impl CCompilerImpl for Nvhpc { //NVHPC doesn't support disabling line info when outputing to console cmd.arg("-E") .env_clear() - .envs(env_vars.iter().map(|&(ref k, ref v)| (k, v))) + .envs(env_vars.iter().map(|(k, v)| (k, v))) .current_dir(cwd); if log_enabled!(Trace) { trace!("preprocess: {:?}", cmd); diff --git a/src/compiler/rust.rs b/src/compiler/rust.rs index 853b2a678..b9e1b9155 100644 --- a/src/compiler/rust.rs +++ b/src/compiler/rust.rs @@ -1326,7 +1326,7 @@ where // source files for this crate. let filtered_arguments = os_string_arguments .iter() - .filter_map(|&(ref arg, ref val)| { + .filter_map(|(arg, val)| { if arg == "--emit" || arg == "--out-dir" { None } else { @@ -1391,15 +1391,15 @@ where // These contain paths which aren't relevant to the output, and the compiler inputs // in those paths (rlibs and static libs used in the compilation) are used as hash // inputs below. - .filter(|&&(ref arg, _)| !(arg == "--extern" || arg == "-L" || arg == "--out-dir")) + .filter(|&(arg, _)| !(arg == "--extern" || arg == "-L" || arg == "--out-dir")) // A few argument types were not passed in a deterministic order // by older versions of cargo: --extern, -L, --cfg. We'll filter the rest of those // out, sort them, and append them to the rest of the arguments. - .partition(|&&(ref arg, _)| arg == "--cfg"); + .partition(|&(arg, _)| arg == "--cfg"); sortables.sort(); rest.into_iter() .chain(sortables) - .flat_map(|&(ref arg, ref val)| iter::once(arg).chain(val.as_ref())) + .flat_map(|(arg, val)| iter::once(arg).chain(val.as_ref())) .fold(OsString::new(), |mut a, b| { a.push(b); a @@ -1420,7 +1420,7 @@ where // output. Additionally also has all environment variables starting with `CARGO_`, // since those are not listed in dep-info but affect cacheability. env_deps.sort(); - for &(ref var, ref val) in env_deps.iter() { + for (var, val) in env_deps.iter() { var.hash(&mut HashToDigest { digest: &mut m }); m.update(b"="); val.hash(&mut HashToDigest { digest: &mut m }); @@ -1433,7 +1433,7 @@ where .cloned() .collect(); env_vars.sort(); - for &(ref var, ref val) in env_vars.iter() { + for (var, val) in env_vars.iter() { // CARGO_MAKEFLAGS will have jobserver info which is extremely non-cacheable. if var.starts_with("CARGO_") && var != "CARGO_MAKEFLAGS" { var.hash(&mut HashToDigest { digest: &mut m }); @@ -1485,8 +1485,8 @@ where // only the rlib is printed. let rlibs: HashSet<_> = outputs .iter() + .filter(|&p| p.ends_with(".rlib")) .cloned() - .filter(|p| p.ends_with(".rlib")) .collect(); for lib in rlibs { let rmeta = lib.replacen(".rlib", ".rmeta", 1); diff --git a/src/compiler/tasking_vx.rs b/src/compiler/tasking_vx.rs index 4ea06ca9c..6c540c9c9 100644 --- a/src/compiler/tasking_vx.rs +++ b/src/compiler/tasking_vx.rs @@ -301,7 +301,7 @@ where .args(&parsed_args.preprocessor_args) .args(&parsed_args.common_args) .env_clear() - .envs(env_vars.iter().map(|&(ref k, ref v)| (k, v))) + .envs(env_vars.iter().map(|(k, v)| (k, v))) .current_dir(cwd); if log_enabled!(Trace) { @@ -331,7 +331,7 @@ where .args(&parsed_args.preprocessor_args) .args(&parsed_args.common_args) .env_clear() - .envs(env_vars.iter().map(|&(ref k, ref v)| (k, v))) + .envs(env_vars.iter().map(|(k, v)| (k, v))) .current_dir(cwd); if log_enabled!(Trace) { diff --git a/src/server.rs b/src/server.rs index 342ced1cd..0acb0cb3e 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1006,7 +1006,7 @@ where let opt = match me1.compilers.read().await.get(&resolved_compiler_path) { // It's a hit only if the mtime and dist archive data matches. - Some(&Some(ref entry)) => { + Some(Some(entry)) => { if entry.mtime == mtime && entry.dist_info == dist_info { Some(entry.compiler.box_clone()) } else { @@ -1154,7 +1154,7 @@ where ) { let force_recache = env_vars .iter() - .any(|&(ref k, ref _v)| k.as_os_str() == OsStr::new("SCCACHE_RECACHE")); + .any(|(k, _v)| k.as_os_str() == OsStr::new("SCCACHE_RECACHE")); let cache_control = if force_recache { CacheControl::ForceRecache } else { @@ -1563,16 +1563,8 @@ impl ServerStats { self.dist_errors, "Failed distributed compilations" ); - let name_width = stats_vec - .iter() - .map(|&(ref n, _, _)| n.len()) - .max() - .unwrap(); - let stat_width = stats_vec - .iter() - .map(|&(_, ref s, _)| s.len()) - .max() - .unwrap(); + let name_width = stats_vec.iter().map(|(n, _, _)| n.len()).max().unwrap(); + let stat_width = stats_vec.iter().map(|(_, s, _)| s.len()).max().unwrap(); for (name, stat, suffix_len) in stats_vec { println!( "{:stat_width$}", diff --git a/src/util.rs b/src/util.rs index ee2d75128..ed00a6504 100644 --- a/src/util.rs +++ b/src/util.rs @@ -421,7 +421,7 @@ impl<'a> Hasher for HashToDigest<'a> { /// Turns a slice of environment var tuples into the type expected by Command::envs. pub fn ref_env(env: &[(OsString, OsString)]) -> impl Iterator { - env.iter().map(|&(ref k, ref v)| (k, v)) + env.iter().map(|(k, v)| (k, v)) } /// Pipe `cmd`'s stdio to `/dev/null`, unless a specific env var is set. diff --git a/tests/system.rs b/tests/system.rs index 34e18f763..304437207 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -254,7 +254,7 @@ fn test_msvc_responsefile(compiler: Compiler, tempdir: &Path) { let out_file = tempdir.join(OUTPUT); let cmd_file_name = "test_msvc.rsp"; { - let mut file = File::create(&tempdir.join(cmd_file_name)).unwrap(); + let mut file = File::create(tempdir.join(cmd_file_name)).unwrap(); let content = format!("-c {INPUT} -Fo{OUTPUT}"); file.write_all(content.as_bytes()).unwrap(); }