Skip to content

Commit af20d03

Browse files
committed
Simplify Toolchain::from_local()
1 parent c1768a7 commit af20d03

File tree

4 files changed

+16
-31
lines changed

4 files changed

+16
-31
lines changed

src/toolchain/distributable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use super::{
2727
/// An official toolchain installed on the local disk
2828
#[derive(Debug)]
2929
pub(crate) struct DistributableToolchain<'a> {
30-
toolchain: Toolchain<'a>,
30+
pub(super) toolchain: Toolchain<'a>,
3131
cfg: &'a Cfg<'a>,
3232
desc: ToolchainDesc,
3333
}

src/toolchain/toolchain.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,20 @@ impl<'a> Toolchain<'a> {
4343
install_if_missing: bool,
4444
cfg: &'a Cfg<'a>,
4545
) -> anyhow::Result<Toolchain<'a>> {
46-
match toolchain_name {
47-
LocalToolchainName::Named(ToolchainName::Official(desc)) => {
48-
match DistributableToolchain::new(cfg, desc.clone()) {
49-
Err(RustupError::ToolchainNotInstalled(_)) => {
50-
if install_if_missing {
51-
DistributableToolchain::install(
52-
cfg,
53-
desc,
54-
&[],
55-
&[],
56-
cfg.get_profile()?,
57-
true,
58-
)
59-
.await?;
60-
}
61-
}
62-
o => {
63-
o?;
64-
}
65-
}
66-
}
67-
n => {
68-
if !Self::exists(cfg, n)? {
69-
return Err(RustupError::ToolchainNotInstallable(n.to_string()).into());
70-
}
46+
match Self::new(cfg, toolchain_name.clone()) {
47+
Ok(tc) => Ok(tc),
48+
Err(RustupError::ToolchainNotInstalled(ToolchainName::Official(desc)))
49+
if install_if_missing =>
50+
{
51+
Ok(
52+
DistributableToolchain::install(cfg, &desc, &[], &[], cfg.get_profile()?, true)
53+
.await?
54+
.1
55+
.toolchain,
56+
)
7157
}
58+
Err(e) => Err(e.into()),
7259
}
73-
74-
Ok(Self::new(cfg, toolchain_name.clone())?)
7560
}
7661

7762
pub(crate) async fn from_partial(

tests/suite/cli_exact.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ fn undefined_linked_toolchain() {
685685
config.expect_err_ex(
686686
&["cargo", "+bogus", "test"],
687687
r"",
688-
"error: toolchain 'bogus' is not installable\n",
688+
"error: toolchain 'bogus' is not installed\n",
689689
);
690690
})
691691
});

tests/suite/cli_rustup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,7 +2450,7 @@ fn non_utf8_toolchain() {
24502450
[OsStr::from_bytes(b"+\xc3\x28")],
24512451
&[("RUST_BACKTRACE", "1")],
24522452
);
2453-
assert!(out.stderr.contains("toolchain '�(' is not installable"));
2453+
assert!(out.stderr.contains("toolchain '�(' is not installed"));
24542454
})
24552455
});
24562456
}
@@ -2469,7 +2469,7 @@ fn non_utf8_toolchain() {
24692469
[OsString::from_wide(&[u16::from(b'+'), 0xd801, 0xd801])],
24702470
&[("RUST_BACKTRACE", "1")],
24712471
);
2472-
assert!(out.stderr.contains("toolchain '��' is not installable"));
2472+
assert!(out.stderr.contains("toolchain '��' is not installed"));
24732473
})
24742474
});
24752475
}

0 commit comments

Comments
 (0)