diff --git a/src/command_helpers.rs b/src/command_helpers.rs index a34067f4..89dc1a33 100644 --- a/src/command_helpers.rs +++ b/src/command_helpers.rs @@ -46,7 +46,7 @@ impl CargoOutput { warnings: true, output: OutputKind::Forward, debug: match std::env::var_os("CC_ENABLE_DEBUG_OUTPUT") { - Some(v) => v != "0" && v != "false" && v != "", + Some(v) => v != "0" && v != "false" && !v.is_empty(), None => false, }, checked_dbg_var: Arc::new(AtomicBool::new(false)), diff --git a/src/flags.rs b/src/flags.rs index ed552e6e..91e9470a 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -185,7 +185,7 @@ impl<'this> RustcCodegenFlags<'this> { }; let clang_or_gnu = - matches!(family, ToolFamily::Clang { .. }) || matches!(family, ToolFamily::Gnu { .. }); + matches!(family, ToolFamily::Clang { .. }) || matches!(family, ToolFamily::Gnu); // Flags shared between clang and gnu if clang_or_gnu { @@ -315,7 +315,7 @@ impl<'this> RustcCodegenFlags<'this> { } } } - ToolFamily::Gnu { .. } => {} + ToolFamily::Gnu => {} ToolFamily::Msvc { .. } => { // https://learn.microsoft.com/en-us/cpp/build/reference/guard-enable-control-flow-guard if let Some(value) = self.control_flow_guard { diff --git a/src/parallel/job_token.rs b/src/parallel/job_token.rs index 5528e1f8..c07fd94b 100644 --- a/src/parallel/job_token.rs +++ b/src/parallel/job_token.rs @@ -80,7 +80,7 @@ mod inherited_jobserver { pub(super) struct JobServer { /// Implicit token for this process which is obtained and will be - /// released in parent. Since JobTokens only give back what they got, + /// released in parent. Since `JobTokens` only give back what they got, /// there should be at most one global implicit token in the wild. /// /// Since Rust does not execute any `Drop` for global variables, @@ -164,7 +164,7 @@ mod inherited_jobserver { helper_thread: Option, } - impl<'a> ActiveJobServer<'a> { + impl ActiveJobServer<'_> { pub(super) async fn acquire(&mut self) -> Result { let mut has_requested_token = false; @@ -233,19 +233,14 @@ mod inprocess_jobserver { impl JobServer { pub(super) fn new() -> Self { // Use `NUM_JOBS` if set (it's configured by Cargo) and otherwise - // just fall back to a semi-reasonable number. - // - // Note that we could use `num_cpus` here but it's an extra - // dependency that will almost never be used, so - // it's generally not too worth it. - let mut parallelism = 4; - // TODO: Use std::thread::available_parallelism as an upper bound - // when MSRV is bumped. - if let Ok(amt) = var("NUM_JOBS") { - if let Ok(amt) = amt.parse() { - parallelism = amt; - } - } + // just fall back to the number of cores on the local machine, or a reasonable + // default if that cannot be determined. + + let parallelism = var("NUM_JOBS") + .ok() + .and_then(|j| j.parse::().ok()) + .or_else(|| Some(std::thread::available_parallelism().ok()?.get() as u32)) + .unwrap_or(4); Self(AtomicU32::new(parallelism)) } diff --git a/src/parallel/stderr.rs b/src/parallel/stderr.rs index 70186860..2e5b0544 100644 --- a/src/parallel/stderr.rs +++ b/src/parallel/stderr.rs @@ -1,5 +1,5 @@ #![cfg_attr(target_family = "wasm", allow(unused))] -/// Helpers functions for [ChildStderr]. +/// Helpers functions for [`ChildStderr`]. use std::{convert::TryInto, process::ChildStderr}; use crate::{Error, ErrorKind}; diff --git a/src/target/parser.rs b/src/target/parser.rs index 72b06e4c..a04aaf51 100644 --- a/src/target/parser.rs +++ b/src/target/parser.rs @@ -475,13 +475,13 @@ mod tests { let (full_arch, _rest) = target.split_once('-').expect("target to have arch"); let mut target = TargetInfo { - full_arch: full_arch.into(), - arch: "invalid-none-set".into(), - vendor: "invalid-none-set".into(), - os: "invalid-none-set".into(), - env: "invalid-none-set".into(), + full_arch, + arch: "invalid-none-set", + vendor: "invalid-none-set", + os: "invalid-none-set", + env: "invalid-none-set", // Not set in older Rust versions - abi: "".into(), + abi: "", }; for cfg in cfgs.lines() { diff --git a/tests/cc_env.rs b/tests/cc_env.rs index 7eed9542..65015f78 100644 --- a/tests/cc_env.rs +++ b/tests/cc_env.rs @@ -117,7 +117,7 @@ fn clang_cl() { for exe_suffix in ["", ".exe"] { let test = Test::clang(); let bin = format!("clang{exe_suffix}"); - env::set_var("CC", &format!("{bin} --driver-mode=cl")); + env::set_var("CC", format!("{bin} --driver-mode=cl")); let test_compiler = |build: cc::Build| { let compiler = build.get_compiler(); assert_eq!(compiler.path(), Path::new(&*bin)); diff --git a/tests/test.rs b/tests/test.rs index d1c11e93..bcac1002 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -532,8 +532,8 @@ fn gnu_apple_sysroot() { test.shim("fake-gcc") .gcc() .compiler("fake-gcc") - .target(&target) - .host(&target) + .target(target) + .host(target) .file("foo.c") .compile("foo");