diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index df833fd565..6b04527f3c 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -35,7 +35,7 @@ use crate::{ show_help, toolchain_help, toolchain_install_help, toolchain_link_help, topic_arg_help, update_help, }, - self_update::{self, SelfUpdateMode, check_rustup_update}, + self_update::{self, CFG_SELF_UPDATE, SelfUpdateMode, check_rustup_update}, topical_doc, }, command, component_for_bin, @@ -916,9 +916,8 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result { // Check for update only if rustup does **not** have the no-self-update feature, // and auto-self-update is configured to **enable** // and has **no** no-self-update parameter. - let self_update = !cfg!(feature = "no-self-update") - && self_update_mode == SelfUpdateMode::Enable - && !opts.no_self_update; + let self_update = + CFG_SELF_UPDATE && self_update_mode == SelfUpdateMode::Enable && !opts.no_self_update; if self_update && check_rustup_update(&DownloadCfg::new(cfg)).await? { update_available = true; @@ -941,9 +940,8 @@ async fn update( // Update only if rustup does **not** have the no-self-update feature, // and auto-self-update is configured to **enable** // and has **no** no-self-update parameter. - let self_update = !cfg!(feature = "no-self-update") - && self_update_mode == SelfUpdateMode::Enable - && !opts.no_self_update; + let self_update = + CFG_SELF_UPDATE && self_update_mode == SelfUpdateMode::Enable && !opts.no_self_update; let force_non_host = opts.force_non_host; cfg.profile_override = opts.profile; @@ -1023,13 +1021,15 @@ async fn update( cfg.tmp_cx.clean(); } - if !cfg!(feature = "no-self-update") && self_update_mode == SelfUpdateMode::CheckOnly { - check_rustup_update(&dl_cfg).await?; - } - - if cfg!(feature = "no-self-update") { - info!("self-update is disabled for this build of rustup"); - info!("any updates to rustup will need to be fetched with your system package manager") + match self_update_mode { + _ if !CFG_SELF_UPDATE => { + info!("self-update is disabled for this build of rustup"); + info!("any updates to rustup will need to be fetched with your system package manager"); + } + SelfUpdateMode::CheckOnly => { + check_rustup_update(&dl_cfg).await?; + } + _ => (), } Ok(exit_code) @@ -1828,7 +1828,7 @@ fn set_auto_self_update( cfg: &mut Cfg<'_>, auto_self_update_mode: SelfUpdateMode, ) -> Result { - if cfg!(feature = "no-self-update") { + if !CFG_SELF_UPDATE { let mut args = cfg.process.args_os(); let arg0 = args.next().map(PathBuf::from); let arg0 = arg0 diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index ee09c72537..251c2df6d9 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -979,12 +979,15 @@ async fn maybe_install_rust(opts: InstallOpts<'_>, cfg: &mut Cfg<'_>) -> Result< Ok(()) } +/// Whether the self-update functionality is enabled during compilation. +pub(crate) const CFG_SELF_UPDATE: bool = !cfg!(feature = "no-self-update"); + pub(crate) fn uninstall( no_prompt: bool, no_modify_path: bool, process: &Process, ) -> Result { - if cfg!(feature = "no-self-update") { + if !CFG_SELF_UPDATE { error!("self-uninstall is disabled for this build of rustup"); error!("you should probably use your system package manager to uninstall rustup"); return Ok(utils::ExitCode(1)); @@ -1169,10 +1172,10 @@ pub(crate) async fn update(cfg: &Cfg<'_>) -> Result { common::warn_if_host_is_emulated(cfg.process); use SelfUpdatePermission::*; - let update_permitted = if cfg!(feature = "no-self-update") { - HardFail - } else { + let update_permitted = if CFG_SELF_UPDATE { self_update_permitted(true)? + } else { + HardFail }; match update_permitted { HardFail => {