Skip to content

Commit

Permalink
refactor(config)!: return LocalToolchainName from `find_or_install_…
Browse files Browse the repository at this point in the history
…active_toolchain()`
  • Loading branch information
rami3l committed Aug 9, 2024
1 parent d2c9b1c commit 108138d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,10 +867,7 @@ async fn update(
}
} else if ensure_active_toolchain {
let (toolchain, reason) = cfg.find_or_install_active_toolchain(true).await?;
info!(
"the active toolchain `{}` has been installed",
toolchain.name()
);
info!("the active toolchain `{toolchain}` has been installed");
info!("it's active because: {reason}");
} else {
exit_code &= common::update_all_channels(cfg, self_update, opts.force).await?;
Expand Down
14 changes: 7 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,18 +741,18 @@ impl<'a> Cfg<'a> {

#[tracing::instrument(level = "trace", skip_all)]
pub(crate) async fn find_or_install_active_toolchain(
&'a self,
&self,
verbose: bool,
) -> Result<(Toolchain<'a>, ActiveReason)> {
) -> Result<(LocalToolchainName, ActiveReason)> {
match self.find_override_config()? {
Some((override_config, reason)) => match override_config {
OverrideCfg::PathBased(path_based_name) => {
let toolchain = Toolchain::with_reason(self, path_based_name.into(), &reason)?;
Ok((toolchain, reason))
Ok((toolchain.name().clone(), reason))
}
OverrideCfg::Custom(custom_name) => {
let toolchain = Toolchain::with_reason(self, custom_name.into(), &reason)?;
Ok((toolchain, reason))
Ok((toolchain.name().clone(), reason))
}
OverrideCfg::Official {
toolchain,
Expand All @@ -764,23 +764,23 @@ impl<'a> Cfg<'a> {
.ensure_installed(&toolchain, components, targets, profile, verbose)
.await?
.1;
Ok((toolchain, reason))
Ok((toolchain.name().clone(), reason))
}
},
None => match self.get_default()? {
None => Err(no_toolchain_error(self.process)),
Some(ToolchainName::Custom(custom_name)) => {
let reason = ActiveReason::Default;
let toolchain = Toolchain::with_reason(self, custom_name.into(), &reason)?;
Ok((toolchain, reason))
Ok((toolchain.name().clone(), reason))
}
Some(ToolchainName::Official(toolchain_desc)) => {
let reason = ActiveReason::Default;
let toolchain = self
.ensure_installed(&toolchain_desc, vec![], vec![], None, verbose)
.await?
.1;
Ok((toolchain, reason))
Ok((toolchain.name().clone(), reason))
}
},
}
Expand Down

0 comments on commit 108138d

Please sign in to comment.