From 42d34e6b976e7ea4089cbc21a7420a64f8726d6e Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Sun, 14 Jun 2026 16:48:34 +0900 Subject: [PATCH] chore: gate platform-conditional code to silence dead-code warnings Building the `mise` binary on Windows (and one item on macOS) surfaced several dead_code / unused-import warnings from unix/linux-only helpers, a test-only enum construction, and a redundant trait import. Gate each item to the platform(s) that actually use it so the default `cargo check`/`cargo build` is warning-free on every target. - src/system/launchd.rs: cfg(unix) on current_uid_from + its test - src/ui/progress_report.rs: allow(dead_code) on ProgressIcon::Error for non-unix (matched everywhere, but constructed only by the unix brew package managers) - src/oci/layer.rs: cfg(unix) on the assert_layer_mode / assert_layer_entry_owner test helpers - src/plugins/core/erlang.rs: cfg(linux) on linux_precompiled_cache_name (also clears a pre-existing macOS dead_code warning) - src/config/config_file/mise_toml.rs: cfg(unix) on update_bootstrap_brew_tap / remove_bootstrap_brew_tap - src/backend/pkgx.rs: cfg(any(unix, test)) on shell_quote (used by the unix wrapper writer and by a non-gated unit test) - src/cmd.rs: drop the redundant CommandExt import (tokio's Command::raw_arg is an inherent method) Co-Authored-By: Claude Opus 4.8 (1M context) --- src/backend/pkgx.rs | 1 + src/cmd.rs | 3 ++- src/config/config_file/mise_toml.rs | 4 +++- src/oci/layer.rs | 2 ++ src/plugins/core/erlang.rs | 1 + src/system/launchd.rs | 2 ++ src/ui/progress_report.rs | 3 +++ 7 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/backend/pkgx.rs b/src/backend/pkgx.rs index dce852e3c4..25c420f10c 100644 --- a/src/backend/pkgx.rs +++ b/src/backend/pkgx.rs @@ -931,6 +931,7 @@ fn pkgx_arch_for_target(target: &PlatformTarget) -> String { } } +#[cfg(any(unix, test))] fn shell_quote(value: &str) -> String { format!("'{}'", value.replace('\'', "'\\''")) } diff --git a/src/cmd.rs b/src/cmd.rs index 7e160250e7..924f91f302 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -506,7 +506,8 @@ impl<'a> CmdLineRunner<'a> { /// and discussion #9355. #[cfg(windows)] pub fn raw_arg>(mut self, arg: S) -> Self { - use std::os::windows::process::CommandExt; + // tokio's `Command` exposes `raw_arg` as an inherent method, so the + // `std::os::windows::process::CommandExt` trait import is unnecessary. self.cmd.raw_arg(arg); self } diff --git a/src/config/config_file/mise_toml.rs b/src/config/config_file/mise_toml.rs index 7d5021a4b4..6943d962fa 100644 --- a/src/config/config_file/mise_toml.rs +++ b/src/config/config_file/mise_toml.rs @@ -547,7 +547,8 @@ impl MiseToml { } /// Set `[bootstrap.brew.taps]."/" = ""`, creating the - /// tables as needed. + /// tables as needed. Only used by the `#[cfg(unix)]` brew CLI commands. + #[cfg(unix)] pub fn update_bootstrap_brew_tap(&mut self, tap: &str, url: &str) -> eyre::Result<()> { self.bootstrap .get_or_insert_with(Default::default) @@ -579,6 +580,7 @@ impl MiseToml { Ok(()) } + #[cfg(unix)] pub fn remove_bootstrap_brew_tap(&mut self, tap: &str) -> eyre::Result<()> { if let Some(bootstrap) = &mut self.bootstrap { bootstrap.brew.taps.shift_remove(tap); diff --git a/src/oci/layer.rs b/src/oci/layer.rs index a95c8b0b4b..ad29703ea4 100644 --- a/src/oci/layer.rs +++ b/src/oci/layer.rs @@ -700,6 +700,7 @@ mod tests { assert!(entries_seen > 0, "expected at least one tar entry"); } + #[cfg(unix)] fn assert_layer_mode(blob: &LayerBlob, expected_path: &str, expected_mode: u32) { let decoder = flate2::read::GzDecoder::new(blob.bytes.as_slice()); let mut archive = tar::Archive::new(decoder); @@ -720,6 +721,7 @@ mod tests { panic!("expected layer entry {expected_path}"); } + #[cfg(unix)] fn assert_layer_entry_owner(blob: &LayerBlob, expected_path: &str, uid: u64, gid: u64) { let decoder = flate2::read::GzDecoder::new(blob.bytes.as_slice()); let mut archive = tar::Archive::new(decoder); diff --git a/src/plugins/core/erlang.rs b/src/plugins/core/erlang.rs index 569392397b..b8f27315c8 100644 --- a/src/plugins/core/erlang.rs +++ b/src/plugins/core/erlang.rs @@ -134,6 +134,7 @@ impl ErlangPlugin { )) } + #[cfg(linux)] fn linux_precompiled_cache_name(url: &str) -> String { url.strip_prefix("https://builds.hex.pm/builds/otp/") .unwrap_or(url) diff --git a/src/system/launchd.rs b/src/system/launchd.rs index 8347cb7e7a..5467d14349 100644 --- a/src/system/launchd.rs +++ b/src/system/launchd.rs @@ -301,6 +301,7 @@ fn current_uid() -> u32 { 0 } +#[cfg(unix)] fn current_uid_from(euid: u32, sudo_uid: Option<&str>) -> u32 { if euid == 0 && let Some(uid) = sudo_uid.and_then(|uid| uid.parse::().ok()) @@ -464,6 +465,7 @@ mod tests { assert!(plist_matches(&plist, &request)); } + #[cfg(unix)] #[test] fn test_current_uid_prefers_sudo_uid_for_root() { assert_eq!(current_uid_from(0, Some("501")), 501); diff --git a/src/ui/progress_report.rs b/src/ui/progress_report.rs index 76f402e820..9d749b2bf7 100644 --- a/src/ui/progress_report.rs +++ b/src/ui/progress_report.rs @@ -18,6 +18,9 @@ pub enum ProgressIcon { Skipped, #[allow(dead_code)] Warning, + // Constructed only by the brew package managers (`#[cfg(unix)]`), so it reads + // as never-constructed on the windows build. + #[cfg_attr(windows, allow(dead_code))] Error, }