Skip to content

Commit

Permalink
Fix some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Oct 18, 2023
1 parent be14a49 commit eb929d1
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"="[..]);
Expand Down
18 changes: 6 additions & 12 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>()
);
let mut output_paths: Vec<PathBuf> = vec![];
Expand Down Expand Up @@ -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 {
Expand All @@ -903,10 +898,9 @@ impl PartialEq<CompileResult> 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,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ fn preprocess_cmd<T>(
.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);
}
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/nvcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/nvhpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 });
Expand All @@ -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 });
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/tasking_vx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 4 additions & 12 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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!(
"{:<name_width$} {:>stat_width$}",
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = (&OsString, &OsString)> {
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.
Expand Down
2 changes: 1 addition & 1 deletion tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit eb929d1

Please sign in to comment.