From a75895270cff1ce9b2855a52f64d809e60930ff1 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Thu, 10 Jul 2025 11:25:16 +0200 Subject: [PATCH] Fix all new clippy lints since Rust 1.88 This makes the CI in both PRs/pushes and the nightly runs happy again. While at it, I've replaced some `to_string()` calls with a format string which should be ever so slightly more efficient by saving on an allocation. --- compile/src/lib.rs | 25 ++++++++++++++----------- compile/src/opt.rs | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/compile/src/lib.rs b/compile/src/lib.rs index 73852e2f7..3a41a642d 100644 --- a/compile/src/lib.rs +++ b/compile/src/lib.rs @@ -473,14 +473,14 @@ impl Config { // The ispc compiler crashes if we give -O0 and --cpu=generic, // see https://github.com/ispc/ispc/issues/1223 if *c != CPU::Generic || (*c == CPU::Generic && opt_level != 0) { - ispc_args.push(String::from("-O") + &opt_level.to_string()); + ispc_args.push(format!("-O{opt_level}")); } else { self.print( &"cargo:warning=ispc-rs: Omitting -O0 on CPU::Generic target, ispc bug 1223", ); } } else { - ispc_args.push(String::from("-O") + &opt_level.to_string()); + ispc_args.push(format!("-O{opt_level}")); } // If we're on Unix we need position independent code @@ -495,10 +495,10 @@ impl Config { } else if target.starts_with("aarch64") { ispc_args.push(String::from("--arch=aarch64")); } - for d in &self.defines { - match d.1 { - Some(ref v) => ispc_args.push(format!("-D{}={}", d.0, v)), - None => ispc_args.push(format!("-D{}", d.0)), + for (name, value) in &self.defines { + match value { + Some(value) => ispc_args.push(format!("-D{name}={value}")), + None => ispc_args.push(format!("-D{name}")), } } ispc_args.push(self.math_lib.to_string()); @@ -506,7 +506,7 @@ impl Config { ispc_args.push(s.to_string()); } if let Some(ref f) = self.force_alignment { - ispc_args.push(String::from("--force-alignment=") + &f.to_string()); + ispc_args.push(format!("--force-alignment={f}")); } for o in &self.optimization_opts { ispc_args.push(o.to_string()); @@ -543,9 +543,12 @@ impl Config { } if let Some(ref t) = self.target_isa { let mut isa_str = String::from("--target="); - isa_str.push_str(&t[0].to_string()); - for isa in t.iter().skip(1) { - isa_str.push_str(&format!(",{}", isa)); + for (i, isa) in t.iter().enumerate() { + if i > 0 { + isa_str.push(','); + } + use std::fmt::Write as _; + let _ = write!(isa_str, "{isa}"); } ispc_args.push(isa_str); } else if target.starts_with("aarch64") { @@ -584,7 +587,7 @@ impl Config { /// env("DEBUG") fn get_debug(&self) -> bool { self.debug - .unwrap_or_else(|| env::var("DEBUG").map(|x| x == "true").unwrap()) + .unwrap_or_else(|| env::var("DEBUG").unwrap() == "true") } /// Returns the user-set optimization level if they've set one, otherwise /// returns env("OPT_LEVEL") diff --git a/compile/src/opt.rs b/compile/src/opt.rs index 075f8eb7e..4b3ab0bd0 100644 --- a/compile/src/opt.rs +++ b/compile/src/opt.rs @@ -226,7 +226,7 @@ impl std::fmt::Display for OptimizationOpt { OptimizationOpt::ForceAlignedMemory => "force-aligned-memory", OptimizationOpt::ResetFTZDaz => "reset-ftz-daz", }; - write!(f, "--opt={}", option_str) + write!(f, "--opt={option_str}") } }