Skip to content

Commit 880f928

Browse files
committed
feat(config)!: remove implicit installation from resolve_local_toolchain()
1 parent 23733ef commit 880f928

File tree

4 files changed

+39
-40
lines changed

4 files changed

+39
-40
lines changed

src/config.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,13 @@ impl<'a> Cfg<'a> {
731731
.transpose()?;
732732

733733
Ok(match local {
734-
Some(tc) => Toolchain::from_local(tc, false, self).await?,
735-
None => self.find_or_install_active_toolchain(false).await?.0,
734+
Some(tc) => Toolchain::new(self, tc)?,
735+
None => Toolchain::new(
736+
self,
737+
self.find_active_toolchain()?
738+
.ok_or_else(|| no_toolchain_error(self.process))?
739+
.0,
740+
)?,
736741
})
737742
}
738743

tests/suite/cli_rustup.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,7 +2133,7 @@ async fn file_override_toml_format_install_both_toolchain_and_components() {
21332133
cx.config.expect_ok(&["rustup", "default", "stable"]).await;
21342134
}
21352135

2136-
let cx = cx.with_dist_dir(Scenario::ArchivesV2_2015_01_01);
2136+
let mut cx = cx.with_dist_dir(Scenario::ArchivesV2_2015_01_01);
21372137
cx.config
21382138
.expect_stdout_ok(&["rustc", "--version"], "hash-stable-1.1.0")
21392139
.await;
@@ -2153,6 +2153,9 @@ components = [ "rust-src" ]
21532153
)
21542154
.unwrap();
21552155

2156+
cx.config
2157+
.expect_ok(&["rustup", "toolchain", "install"])
2158+
.await;
21562159
cx.config
21572160
.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-1")
21582161
.await;
@@ -2233,7 +2236,7 @@ components = [ "rust-bongo" ]
22332236

22342237
cx.config
22352238
.expect_stderr_ok(
2236-
&["rustc", "--version"],
2239+
&["rustup", "toolchain", "install"],
22372240
"warn: Force-skipping unavailable component 'rust-bongo",
22382241
)
22392242
.await;
@@ -2789,7 +2792,7 @@ async fn dont_warn_on_partial_build() {
27892792
/// Checks that `rust-toolchain.toml` files are considered
27902793
#[tokio::test]
27912794
async fn rust_toolchain_toml() {
2792-
let cx = CliTestContext::new(Scenario::SimpleV2).await;
2795+
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
27932796
cx.config
27942797
.expect_err(
27952798
&["rustc", "--version"],
@@ -2800,7 +2803,9 @@ async fn rust_toolchain_toml() {
28002803
let cwd = cx.config.current_dir();
28012804
let toolchain_file = cwd.join("rust-toolchain.toml");
28022805
raw::write_file(&toolchain_file, "[toolchain]\nchannel = \"nightly\"").unwrap();
2803-
2806+
cx.config
2807+
.expect_ok(&["rustup", "toolchain", "install"])
2808+
.await;
28042809
cx.config
28052810
.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-2")
28062811
.await;
@@ -2831,7 +2836,7 @@ async fn warn_on_duplicate_rust_toolchain_file() {
28312836

28322837
cx.config
28332838
.expect_stderr_ok(
2834-
&["rustc", "--version"],
2839+
&["rustup", "toolchain", "install"],
28352840
&format!(
28362841
"warn: both `{0}` and `{1}` exist. Using `{0}`",
28372842
toolchain_file_1.canonicalize().unwrap().display(),

tests/suite/cli_v1.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,6 @@ async fn remove_toolchain() {
169169
.await;
170170
}
171171

172-
#[tokio::test]
173-
async fn remove_default_toolchain_autoinstalls() {
174-
let mut cx = CliTestContext::new(Scenario::SimpleV1).await;
175-
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
176-
cx.config
177-
.expect_ok(&["rustup", "toolchain", "remove", "nightly"])
178-
.await;
179-
cx.config
180-
.expect_stderr_ok(&["rustc", "--version"], "info: installing component")
181-
.await;
182-
}
183-
184172
#[tokio::test]
185173
async fn remove_override_toolchain_err_handling() {
186174
let mut cx = CliTestContext::new(Scenario::SimpleV1).await;
@@ -194,7 +182,15 @@ async fn remove_override_toolchain_err_handling() {
194182
.expect_ok(&["rustup", "toolchain", "remove", "beta"])
195183
.await;
196184
cx.config
197-
.expect_stderr_ok(&["rustc", "--version"], "info: installing component")
185+
.expect_err_ex(
186+
&["rustc", "--version"],
187+
"",
188+
for_host!(
189+
r"error: toolchain 'beta-{0}' is not installed
190+
help: run `rustup toolchain install beta-{0}` to install it
191+
"
192+
),
193+
)
198194
.await;
199195
}
200196

tests/suite/cli_v2.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -311,18 +311,6 @@ async fn add_remove_multiple_toolchains() {
311311
}
312312
}
313313

314-
#[tokio::test]
315-
async fn remove_default_toolchain_autoinstalls() {
316-
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
317-
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
318-
cx.config
319-
.expect_ok(&["rustup", "toolchain", "remove", "nightly"])
320-
.await;
321-
cx.config
322-
.expect_stderr_ok(&["rustc", "--version"], "info: installing component")
323-
.await;
324-
}
325-
326314
#[tokio::test]
327315
async fn remove_override_toolchain_err_handling() {
328316
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
@@ -336,7 +324,15 @@ async fn remove_override_toolchain_err_handling() {
336324
.expect_ok(&["rustup", "toolchain", "remove", "beta"])
337325
.await;
338326
cx.config
339-
.expect_stderr_ok(&["rustc", "--version"], "info: installing component")
327+
.expect_err_ex(
328+
&["rustc", "--version"],
329+
"",
330+
for_host!(
331+
r"error: toolchain 'beta-{0}' is not installed
332+
help: run `rustup toolchain install beta-{0}` to install it
333+
"
334+
),
335+
)
340336
.await;
341337
}
342338

@@ -347,7 +343,10 @@ async fn file_override_toolchain_err_handling() {
347343
let toolchain_file = cwd.join("rust-toolchain");
348344
rustup::utils::raw::write_file(&toolchain_file, "beta").unwrap();
349345
cx.config
350-
.expect_stderr_ok(&["rustc", "--version"], "info: installing component")
346+
.expect_err(
347+
&["rustc", "--version"],
348+
for_host!("toolchain 'beta-{0}' is not installed"),
349+
)
351350
.await;
352351
}
353352

@@ -423,12 +422,6 @@ async fn bad_manifest() {
423422
&format!("error: could not parse manifest file: '{}'", path.display()),
424423
)
425424
.await;
426-
cx.config
427-
.expect_err(
428-
&["cargo", "--help"],
429-
&format!("error: could not parse manifest file: '{}'", path.display()),
430-
)
431-
.await;
432425
}
433426

434427
#[tokio::test]

0 commit comments

Comments
 (0)