Skip to content

Commit d5deaef

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

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1088,9 +1088,9 @@ async fn which_asking_uninstalled_toolchain() {
10881088
)
10891089
.await;
10901090
cx.config
1091-
.expect_err(
1091+
.expect_stdout_ok(
10921092
&["rustup", "which", "--toolchain=nightly", "rustc"],
1093-
for_host!("toolchain 'nightly-{}' is not installed"),
1093+
for_host!("toolchains/nightly-{0}/bin/rustc"),
10941094
)
10951095
.await;
10961096
}

tests/suite/cli_v2.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,9 @@ 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(
357+
.expect_err_env(
358358
&["rustc", "+beta"],
359+
&[("RUSTUP_AUTO_INSTALL", "0")],
359360
for_host!("toolchain 'beta-{0}' is not installed"),
360361
)
361362
.await;
@@ -776,8 +777,9 @@ async fn upgrade_v2_to_v1() {
776777
async fn list_targets_no_toolchain() {
777778
let cx = CliTestContext::new(Scenario::SimpleV2).await;
778779
cx.config
779-
.expect_err(
780+
.expect_err_env(
780781
&["rustup", "target", "list", "--toolchain=nightly"],
782+
&[("RUSTUP_AUTO_INSTALL", "0")],
781783
for_host!("toolchain 'nightly-{0}' is not installed"),
782784
)
783785
.await;
@@ -962,18 +964,20 @@ async fn remove_target_by_component_remove() {
962964
async fn add_target_no_toolchain() {
963965
let cx = CliTestContext::new(Scenario::SimpleV2).await;
964966
cx.config
965-
.expect_err(
967+
.expect_err_env(
966968
&[
967969
"rustup",
968970
"target",
969971
"add",
970972
CROSS_ARCH1,
971973
"--toolchain=nightly",
972974
],
975+
&[("RUSTUP_AUTO_INSTALL", "0")],
973976
for_host!("toolchain 'nightly-{0}' is not installed"),
974977
)
975978
.await;
976979
}
980+
977981
#[tokio::test]
978982
async fn add_target_bogus() {
979983
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
@@ -1120,14 +1124,15 @@ async fn remove_target_not_installed() {
11201124
async fn remove_target_no_toolchain() {
11211125
let cx = CliTestContext::new(Scenario::SimpleV2).await;
11221126
cx.config
1123-
.expect_err(
1127+
.expect_err_env(
11241128
&[
11251129
"rustup",
11261130
"target",
11271131
"remove",
11281132
CROSS_ARCH1,
11291133
"--toolchain=nightly",
11301134
],
1135+
&[("RUSTUP_AUTO_INSTALL", "0")],
11311136
for_host!("toolchain 'nightly-{0}' is not installed"),
11321137
)
11331138
.await;

0 commit comments

Comments
 (0)