Skip to content

Commit 87216b8

Browse files
committed
Move Toolchain::from_partial() to Cfg
1 parent dc83fed commit 87216b8

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/cli/rustup_mode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ async fn doc(
14461446
mut topic: Option<&str>,
14471447
doc_page: &DocPage,
14481448
) -> Result<utils::ExitCode> {
1449-
let toolchain = Toolchain::from_partial(toolchain, cfg).await?;
1449+
let toolchain = cfg.toolchain_from_partial(toolchain).await?;
14501450

14511451
if let Ok(distributable) = DistributableToolchain::try_from(&toolchain) {
14521452
if let [_] = distributable
@@ -1507,7 +1507,7 @@ async fn man(
15071507
command: &str,
15081508
toolchain: Option<PartialToolchainDesc>,
15091509
) -> Result<utils::ExitCode> {
1510-
let toolchain = Toolchain::from_partial(toolchain, cfg).await?;
1510+
let toolchain = cfg.toolchain_from_partial(toolchain).await?;
15111511
let mut path = toolchain.path().to_path_buf();
15121512
path.push("share");
15131513
path.push("man");

src/config.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tracing::trace;
1414
use crate::{
1515
cli::self_update::SelfUpdateMode,
1616
currentprocess::Process,
17-
dist::{self, download::DownloadCfg, temp, Profile, ToolchainDesc},
17+
dist::{self, download::DownloadCfg, temp, PartialToolchainDesc, Profile, ToolchainDesc},
1818
errors::RustupError,
1919
fallback_settings::FallbackSettings,
2020
install::UpdateStatus,
@@ -490,6 +490,19 @@ impl<'a> Cfg<'a> {
490490
.transpose()?)
491491
}
492492

493+
pub(crate) async fn toolchain_from_partial(
494+
&self,
495+
toolchain: Option<PartialToolchainDesc>,
496+
) -> anyhow::Result<Toolchain<'_>> {
497+
match toolchain.map(|it| ResolvableToolchainName::from(&it)) {
498+
Some(toolchain) => {
499+
let desc = toolchain.resolve(&self.get_default_host_triple()?)?;
500+
Ok(Toolchain::new(self, desc.into())?)
501+
}
502+
None => Ok(self.find_or_install_active_toolchain().await?.0),
503+
}
504+
}
505+
493506
pub(crate) fn find_active_toolchain(
494507
&self,
495508
) -> Result<Option<(LocalToolchainName, ActiveReason)>> {

src/toolchain/distributable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'a> DistributableToolchain<'a> {
3838
cfg: &'a Cfg<'a>,
3939
) -> anyhow::Result<Self> {
4040
Ok(Self::try_from(
41-
&Toolchain::from_partial(toolchain, cfg).await?,
41+
&cfg.toolchain_from_partial(toolchain).await?,
4242
)?)
4343
}
4444

src/toolchain/toolchain.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::{
2626

2727
use super::{
2828
distributable::DistributableToolchain,
29-
names::{LocalToolchainName, ResolvableToolchainName, ToolchainName},
29+
names::{LocalToolchainName, ToolchainName},
3030
};
3131

3232
/// A toolchain installed on the local disk
@@ -59,19 +59,6 @@ impl<'a> Toolchain<'a> {
5959
}
6060
}
6161

62-
pub(crate) async fn from_partial(
63-
toolchain: Option<PartialToolchainDesc>,
64-
cfg: &'a Cfg<'a>,
65-
) -> anyhow::Result<Self> {
66-
match toolchain.map(|it| ResolvableToolchainName::from(&it)) {
67-
Some(toolchain) => {
68-
let desc = toolchain.resolve(&cfg.get_default_host_triple()?)?;
69-
Ok(Toolchain::new(cfg, desc.into())?)
70-
}
71-
None => Ok(cfg.find_or_install_active_toolchain().await?.0),
72-
}
73-
}
74-
7562
/// Calls Toolchain::new(), but augments the error message with more context
7663
/// from the ActiveReason if the toolchain isn't installed.
7764
pub(crate) fn with_reason(

0 commit comments

Comments
 (0)