From 8144afe535db7665155f1a9bfc1b1d6a73878129 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 15 Sep 2026 18:38:40 +0200 Subject: [PATCH 1/8] refactor(install): inline `InstallMethod::run()` --- src/install.rs | 61 ++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/src/install.rs b/src/install.rs index 20964cfba4..c66bbb259c 100644 --- a/src/install.rs +++ b/src/install.rs @@ -50,8 +50,35 @@ impl InstallMethod<'_, '_> { _ => debug!("updating existing install for '{local_name}'"), } - debug!("toolchain directory: {}", self.dest_path().display()); - let updated = self.run(&self.dest_path(), manifest).await?; + let dest_path = &self.dest_path(); + debug!("toolchain directory: {}", dest_path.display()); + if dest_path.exists() { + // Don't uninstall first for Dist method + match self { + Self::Dist { .. } => {} + _ => { + uninstall(dest_path)?; + } + } + } + + let updated = match &self { + Self::Link { src, .. } => { + utils::symlink_dir(src, dest_path)?; + true + } + Self::Dist(opts) => { + let prefix = &InstallPrefix::from(dest_path.clone()); + let maybe_new_hash = opts.install_into(prefix, manifest).await?; + + if let Some(hash) = maybe_new_hash { + utils::write_file("update hash", &opts.update_hash, &hash)?; + true + } else { + false + } + } + }; let status = match updated { false => { @@ -79,36 +106,6 @@ impl InstallMethod<'_, '_> { } } - async fn run(&self, path: &Path, manifest: Option) -> anyhow::Result { - if path.exists() { - // Don't uninstall first for Dist method - match self { - InstallMethod::Dist { .. } => {} - _ => { - uninstall(path)?; - } - } - } - - match self { - InstallMethod::Link { src, .. } => { - utils::symlink_dir(src, path)?; - Ok(true) - } - InstallMethod::Dist(opts) => { - let prefix = &InstallPrefix::from(path.to_owned()); - let maybe_new_hash = opts.install_into(prefix, manifest).await?; - - if let Some(hash) = maybe_new_hash { - utils::write_file("update hash", &opts.update_hash, &hash)?; - Ok(true) - } else { - Ok(false) - } - } - } - } - fn cfg(&self) -> &Cfg<'_> { match self { InstallMethod::Link { cfg, .. } => cfg, From 5ad0501091b3c0035a4b3d028d4b3590bb3c17d6 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 15 Sep 2026 17:50:53 +0200 Subject: [PATCH 2/8] refactor(install): simplify pattern matching --- src/install.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/install.rs b/src/install.rs index c66bbb259c..aa79275d69 100644 --- a/src/install.rs +++ b/src/install.rs @@ -52,14 +52,8 @@ impl InstallMethod<'_, '_> { let dest_path = &self.dest_path(); debug!("toolchain directory: {}", dest_path.display()); - if dest_path.exists() { - // Don't uninstall first for Dist method - match self { - Self::Dist { .. } => {} - _ => { - uninstall(dest_path)?; - } - } + if dest_path.exists() && !matches!(self, Self::Dist { .. }) { + uninstall(dest_path)?; } let updated = match &self { From 0f507d6c679790f0209a737d8b90414684db8eba Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 15 Sep 2026 17:50:53 +0200 Subject: [PATCH 3/8] refactor(install): delay printing of debug messages --- src/install.rs | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/install.rs b/src/install.rs index aa79275d69..d8708c4f8f 100644 --- a/src/install.rs +++ b/src/install.rs @@ -75,29 +75,27 @@ impl InstallMethod<'_, '_> { }; let status = match updated { - false => { - debug!("toolchain is already up to date"); - UpdateStatus::Unchanged - } - true => { - debug!("toolchain {local_name} installed"); - match &self { - InstallMethod::Dist(DistOptions { - old_date_version: Some((_, v)), - .. - }) => UpdateStatus::Updated(v.clone()), - InstallMethod::Link { .. } | InstallMethod::Dist { .. } => { - UpdateStatus::Installed - } - } - } + false => UpdateStatus::Unchanged, + true => match &self { + InstallMethod::Dist(DistOptions { + old_date_version: Some((_, v)), + .. + }) => UpdateStatus::Updated(v.clone()), + InstallMethod::Link { .. } | InstallMethod::Dist { .. } => UpdateStatus::Installed, + }, }; // Final check, to ensure we're installed - match Toolchain::exists(self.cfg(), &local_name)? { - true => Ok(status), - false => Err(RustupError::ToolchainNotInstallable(local_name.to_string()).into()), + if !Toolchain::exists(self.cfg(), &local_name)? { + return Err(RustupError::ToolchainNotInstallable(local_name.to_string()).into()); } + + match &status { + UpdateStatus::Unchanged => debug!("toolchain is already up to date"), + _ => debug!("toolchain {local_name} installed"), + }; + + Ok(status) } fn cfg(&self) -> &Cfg<'_> { From d1d24662a67db2d559e930ca265af0e0d22101c4 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 15 Sep 2026 17:50:53 +0200 Subject: [PATCH 4/8] refactor(install): inline `updated` temporary --- src/install.rs | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/install.rs b/src/install.rs index d8708c4f8f..bc03e8a80e 100644 --- a/src/install.rs +++ b/src/install.rs @@ -56,32 +56,26 @@ impl InstallMethod<'_, '_> { uninstall(dest_path)?; } - let updated = match &self { + let status = match &self { Self::Link { src, .. } => { utils::symlink_dir(src, dest_path)?; - true + UpdateStatus::Installed } - Self::Dist(opts) => { - let prefix = &InstallPrefix::from(dest_path.clone()); - let maybe_new_hash = opts.install_into(prefix, manifest).await?; - - if let Some(hash) = maybe_new_hash { + Self::Dist(opts) => match opts + .install_into(&InstallPrefix::from(dest_path.clone()), manifest) + .await? + { + None => UpdateStatus::Unchanged, + Some(hash) => { utils::write_file("update hash", &opts.update_hash, &hash)?; - true - } else { - false + match opts { + DistOptions { + old_date_version: Some((_, v)), + .. + } => UpdateStatus::Updated(v.clone()), + _ => UpdateStatus::Installed, + } } - } - }; - - let status = match updated { - false => UpdateStatus::Unchanged, - true => match &self { - InstallMethod::Dist(DistOptions { - old_date_version: Some((_, v)), - .. - }) => UpdateStatus::Updated(v.clone()), - InstallMethod::Link { .. } | InstallMethod::Dist { .. } => UpdateStatus::Installed, }, }; From a294400b3b90be33dfa349059e64e246be3c6fe0 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 15 Sep 2026 18:07:34 +0200 Subject: [PATCH 5/8] refactor(install): inline `InstallMethod::dest_path()` --- src/install.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/install.rs b/src/install.rs index bc03e8a80e..c8b361f2d4 100644 --- a/src/install.rs +++ b/src/install.rs @@ -1,6 +1,6 @@ //! Installation and upgrade of both distribution-managed and local //! toolchains -use std::path::{Path, PathBuf}; +use std::path::Path; use tracing::debug; @@ -50,7 +50,7 @@ impl InstallMethod<'_, '_> { _ => debug!("updating existing install for '{local_name}'"), } - let dest_path = &self.dest_path(); + let dest_path = &self.cfg().toolchain_path(&self.local_name()); debug!("toolchain directory: {}", dest_path.display()); if dest_path.exists() && !matches!(self, Self::Dist { .. }) { uninstall(dest_path)?; @@ -107,10 +107,6 @@ impl InstallMethod<'_, '_> { }) => (*desc).clone().into(), } } - - fn dest_path(&self) -> PathBuf { - self.cfg().toolchain_path(&self.local_name()) - } } pub(crate) fn uninstall(path: &Path) -> anyhow::Result<()> { From c021921fce5c08f16d9eb3fbb08f9a8573b802aa Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 15 Sep 2026 19:07:33 +0200 Subject: [PATCH 6/8] refactor(install): inline `InstallMethod::local_name()` --- src/install.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/install.rs b/src/install.rs index c8b361f2d4..c3343786c8 100644 --- a/src/install.rs +++ b/src/install.rs @@ -40,7 +40,13 @@ impl InstallMethod<'_, '_> { let _ = rayon::ThreadPoolBuilder::new() .num_threads(self.cfg().process.io_thread_count()?.into()) .build_global(); - let local_name = self.local_name(); + + let local_name = match &self { + Self::Link { dest, .. } => (*dest).clone().into(), + Self::Dist(DistOptions { + toolchain: desc, .. + }) => (*desc).clone().into(), + }; match &self { InstallMethod::Link { .. } | InstallMethod::Dist(DistOptions { @@ -50,7 +56,7 @@ impl InstallMethod<'_, '_> { _ => debug!("updating existing install for '{local_name}'"), } - let dest_path = &self.cfg().toolchain_path(&self.local_name()); + let dest_path = &self.cfg().toolchain_path(&local_name); debug!("toolchain directory: {}", dest_path.display()); if dest_path.exists() && !matches!(self, Self::Dist { .. }) { uninstall(dest_path)?; @@ -98,15 +104,6 @@ impl InstallMethod<'_, '_> { InstallMethod::Dist(DistOptions { cfg, .. }) => cfg, } } - - fn local_name(&self) -> LocalToolchainName { - match self { - InstallMethod::Link { dest, .. } => (*dest).clone().into(), - InstallMethod::Dist(DistOptions { - toolchain: desc, .. - }) => (*desc).clone().into(), - } - } } pub(crate) fn uninstall(path: &Path) -> anyhow::Result<()> { From e458c2d1ff80b401df52c49dc8359217b9b1be35 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 15 Sep 2026 18:13:44 +0200 Subject: [PATCH 7/8] refactor(install): join adjacent `match`es --- src/install.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/install.rs b/src/install.rs index c3343786c8..900ffdbdaf 100644 --- a/src/install.rs +++ b/src/install.rs @@ -8,7 +8,7 @@ use crate::{ config::Cfg, dist::{DistOptions, manifest::ManifestWithHash, prefix::InstallPrefix}, errors::RustupError, - toolchain::{CustomToolchainName, LocalToolchainName, Toolchain}, + toolchain::{CustomToolchainName, Toolchain}, utils, }; @@ -42,19 +42,25 @@ impl InstallMethod<'_, '_> { .build_global(); let local_name = match &self { - Self::Link { dest, .. } => (*dest).clone().into(), + Self::Link { dest, .. } => { + let name = (*dest).clone().into(); + debug!("linking toolchain {name}"); + name + } Self::Dist(DistOptions { - toolchain: desc, .. - }) => (*desc).clone().into(), - }; - match &self { - InstallMethod::Link { .. } - | InstallMethod::Dist(DistOptions { - old_date_version: None, + toolchain: desc, + old_date_version, .. - }) => debug!("installing toolchain {local_name}",), - _ => debug!("updating existing install for '{local_name}'"), - } + }) => { + let name = (*desc).clone().into(); + if old_date_version.is_some() { + debug!("updating existing install for '{name}'"); + } else { + debug!("installing toolchain {name}"); + } + name + } + }; let dest_path = &self.cfg().toolchain_path(&local_name); debug!("toolchain directory: {}", dest_path.display()); From 325f6834281bcfff2d6b8a4e98c52125fe4df2d6 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 15 Sep 2026 18:16:06 +0200 Subject: [PATCH 8/8] refactor(install): inline `InstallMethod::cfg()` --- src/install.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/install.rs b/src/install.rs index 900ffdbdaf..784b27d409 100644 --- a/src/install.rs +++ b/src/install.rs @@ -35,10 +35,14 @@ impl InstallMethod<'_, '_> { self, manifest: Option, ) -> anyhow::Result { + let cfg = match self { + Self::Link { cfg, .. } | Self::Dist(DistOptions { cfg, .. }) => cfg, + }; + // Initialize rayon for use by the remove_dir_all crate limiting the number of threads. // This will error if rayon is already initialized but it's fine to ignore that. let _ = rayon::ThreadPoolBuilder::new() - .num_threads(self.cfg().process.io_thread_count()?.into()) + .num_threads(cfg.process.io_thread_count()?.into()) .build_global(); let local_name = match &self { @@ -62,7 +66,7 @@ impl InstallMethod<'_, '_> { } }; - let dest_path = &self.cfg().toolchain_path(&local_name); + let dest_path = &cfg.toolchain_path(&local_name); debug!("toolchain directory: {}", dest_path.display()); if dest_path.exists() && !matches!(self, Self::Dist { .. }) { uninstall(dest_path)?; @@ -92,7 +96,7 @@ impl InstallMethod<'_, '_> { }; // Final check, to ensure we're installed - if !Toolchain::exists(self.cfg(), &local_name)? { + if !Toolchain::exists(cfg, &local_name)? { return Err(RustupError::ToolchainNotInstallable(local_name.to_string()).into()); } @@ -103,13 +107,6 @@ impl InstallMethod<'_, '_> { Ok(status) } - - fn cfg(&self) -> &Cfg<'_> { - match self { - InstallMethod::Link { cfg, .. } => cfg, - InstallMethod::Dist(DistOptions { cfg, .. }) => cfg, - } - } } pub(crate) fn uninstall(path: &Path) -> anyhow::Result<()> {