Skip to content

Commit bed004f

Browse files
committed
fix!(config): re-enable implicit toolchain installation in Cfg::local_toolchain() with optional opt-out
1 parent dd7d362 commit bed004f

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

src/config.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -784,16 +784,23 @@ impl<'a> Cfg<'a> {
784784
}
785785

786786
async fn local_toolchain(&self, name: Option<LocalToolchainName>) -> Result<Toolchain<'_>> {
787-
let toolchain = match name {
788-
Some(tc) => tc,
787+
match name {
788+
Some(tc) => {
789+
let install_if_missing = self
790+
.process
791+
.var("RUSTUP_AUTO_INSTALL")
792+
.map_or(true, |it| it != "0");
793+
Toolchain::from_local(tc, install_if_missing, self).await
794+
}
789795
None => {
790-
self.find_active_toolchain(None)
796+
let tc = self
797+
.find_active_toolchain(None)
791798
.await?
792799
.ok_or_else(|| no_toolchain_error(self.process))?
793-
.0
800+
.0;
801+
Ok(Toolchain::new(self, tc)?)
794802
}
795-
};
796-
Ok(Toolchain::new(self, toolchain)?)
803+
}
797804
}
798805

799806
#[tracing::instrument(level = "trace", skip_all)]

tests/suite/cli_exact.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,9 @@ info: installing component 'rust-std' for '{0}'
687687
async fn show_suggestion_for_missing_toolchain() {
688688
let cx = CliTestContext::new(Scenario::SimpleV2).await;
689689
cx.config
690-
.expect_err_ex(
690+
.expect_err_env(
691691
&["cargo", "+nightly", "fmt"],
692-
r"",
692+
&[("RUSTUP_AUTO_INSTALL", "0")],
693693
for_host!(
694694
r"error: toolchain 'nightly-{0}' is not installed
695695
help: run `rustup toolchain install nightly-{0}` to install it

tests/suite/cli_misc.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1073,24 +1073,17 @@ async fn which_asking_uninstalled_toolchain() {
10731073
cx.config
10741074
.expect_ok(&["rustup", "default", "custom-1"])
10751075
.await;
1076-
#[cfg(windows)]
10771076
cx.config
10781077
.expect_stdout_ok(
10791078
&["rustup", "which", "rustc"],
1080-
"\\toolchains\\custom-1\\bin\\rustc",
1079+
&["", "toolchains", "custom-1", "bin", "rustc"].join(std::path::MAIN_SEPARATOR_STR),
10811080
)
10821081
.await;
1083-
#[cfg(not(windows))]
10841082
cx.config
10851083
.expect_stdout_ok(
1086-
&["rustup", "which", "rustc"],
1087-
"/toolchains/custom-1/bin/rustc",
1088-
)
1089-
.await;
1090-
cx.config
1091-
.expect_err(
10921084
&["rustup", "which", "--toolchain=nightly", "rustc"],
1093-
for_host!("toolchain 'nightly-{}' is not installed"),
1085+
&["", "toolchains", for_host!("nightly-{0}"), "bin", "rustc"]
1086+
.join(std::path::MAIN_SEPARATOR_STR),
10941087
)
10951088
.await;
10961089
}

tests/suite/cli_v2.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,19 @@ async fn file_override_toolchain_err_handling() {
354354
async fn plus_override_toolchain_err_handling() {
355355
let cx = CliTestContext::new(Scenario::SimpleV2).await;
356356
cx.config
357-
.expect_err(
358-
&["rustc", "+beta"],
357+
.expect_err_env(
358+
&["rustc", "+beta", "--version"],
359+
&[("RUSTUP_AUTO_INSTALL", "0")],
359360
for_host!("toolchain 'beta-{0}' is not installed"),
360361
)
361362
.await;
363+
cx.config
364+
.expect_ok_contains(
365+
&["rustc", "+beta", "--version"],
366+
"1.2.0 (hash-beta-1.2.0)",
367+
"",
368+
)
369+
.await;
362370
}
363371

364372
#[tokio::test]
@@ -776,8 +784,9 @@ async fn upgrade_v2_to_v1() {
776784
async fn list_targets_no_toolchain() {
777785
let cx = CliTestContext::new(Scenario::SimpleV2).await;
778786
cx.config
779-
.expect_err(
787+
.expect_err_env(
780788
&["rustup", "target", "list", "--toolchain=nightly"],
789+
&[("RUSTUP_AUTO_INSTALL", "0")],
781790
for_host!("toolchain 'nightly-{0}' is not installed"),
782791
)
783792
.await;
@@ -962,18 +971,20 @@ async fn remove_target_by_component_remove() {
962971
async fn add_target_no_toolchain() {
963972
let cx = CliTestContext::new(Scenario::SimpleV2).await;
964973
cx.config
965-
.expect_err(
974+
.expect_err_env(
966975
&[
967976
"rustup",
968977
"target",
969978
"add",
970979
CROSS_ARCH1,
971980
"--toolchain=nightly",
972981
],
982+
&[("RUSTUP_AUTO_INSTALL", "0")],
973983
for_host!("toolchain 'nightly-{0}' is not installed"),
974984
)
975985
.await;
976986
}
987+
977988
#[tokio::test]
978989
async fn add_target_bogus() {
979990
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
@@ -1120,14 +1131,15 @@ async fn remove_target_not_installed() {
11201131
async fn remove_target_no_toolchain() {
11211132
let cx = CliTestContext::new(Scenario::SimpleV2).await;
11221133
cx.config
1123-
.expect_err(
1134+
.expect_err_env(
11241135
&[
11251136
"rustup",
11261137
"target",
11271138
"remove",
11281139
CROSS_ARCH1,
11291140
"--toolchain=nightly",
11301141
],
1142+
&[("RUSTUP_AUTO_INSTALL", "0")],
11311143
for_host!("toolchain 'nightly-{0}' is not installed"),
11321144
)
11331145
.await;

0 commit comments

Comments
 (0)