From 23aacf6f67409014486afc6fc669452ce6fe4e0a Mon Sep 17 00:00:00 2001 From: rami3l Date: Fri, 10 Jul 2026 16:31:13 +0200 Subject: [PATCH] refactor: replace `cfg_if!{}` with `cfg_select!{}` --- Cargo.lock | 1 - Cargo.toml | 1 - src/bin/rustup-init.rs | 10 +++------- src/cli/self_update.rs | 10 +++------- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7d0ba728bb..465fb49261 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2047,7 +2047,6 @@ dependencies = [ "anstyle", "anyhow", "cc", - "cfg-if 1.0.4", "chrono", "clap", "clap-cargo", diff --git a/Cargo.toml b/Cargo.toml index 1680cf7dd4..65d7976be9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,6 @@ anstream = "1" anstyle = "1.0.11" anyhow = "1.0.69" cc = "1" -cfg-if = "1.0" chrono = { version = "0.4", default-features = false, features = ["std"] } clap = { version = "4", features = ["derive", "wrap_help", "string"] } clap-cargo = "0.18.3" diff --git a/src/bin/rustup-init.rs b/src/bin/rustup-init.rs index e844ddc19e..a0d408abc8 100644 --- a/src/bin/rustup-init.rs +++ b/src/bin/rustup-init.rs @@ -16,7 +16,6 @@ use std::process::ExitCode; use anyhow::{Context, Result, anyhow}; -use cfg_if::cfg_if; // Public macros require availability of the internal symbols use rs_tracing::{ close_trace_file, close_trace_file_internal, open_trace_file, trace_to_file_internal, @@ -105,12 +104,9 @@ async fn run_rustup_inner( Some(n) if n.starts_with("rustup-gc-") => { // This is the final uninstallation stage on windows where // rustup deletes its own exe - cfg_if! { - if #[cfg(windows)] { - self_update::complete_windows_uninstall(process) - } else { - unreachable!("Attempted to use Windows-specific code on a non-Windows platform. Aborting.") - } + cfg_select! { + windows => self_update::complete_windows_uninstall(process), + _ => unreachable!("Attempted to use Windows-specific code on a non-Windows platform. Aborting."), } } Some(n) => { diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 59d791f5a7..edb255fac0 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -43,7 +43,6 @@ use std::{fmt, fs}; use anstyle::Style; use anyhow::{Context, Result, anyhow}; -use cfg_if::cfg_if; use clap::ValueEnum; use clap::builder::PossibleValue; use clap_cargo::style::{GOOD, WARN}; @@ -540,12 +539,9 @@ fn canonical_cargo_home(process: &Process) -> Result> { .unwrap_or_else(|| PathBuf::from(".")) .join(".cargo"); Ok(if default_cargo_home == path { - cfg_if! { - if #[cfg(windows)] { - r"%USERPROFILE%\.cargo".into() - } else { - "$HOME/.cargo".into() - } + cfg_select! { + windows => r"%USERPROFILE%\.cargo".into(), + _ => "$HOME/.cargo".into(), } } else { path.to_string_lossy().into_owned().into()