From 01d298e9337c8de8e91c55583b8789f67f6c346e Mon Sep 17 00:00:00 2001 From: rami3l Date: Mon, 15 Jul 2024 10:08:43 +0800 Subject: [PATCH 1/3] fix(rustup-mode)!: don't install toolchain on `rustup --version` Co-authored-by: kellda <59569234+kellda@users.noreply.github.com> --- src/cli/rustup_mode.rs | 10 +++++++--- src/config.rs | 11 +++++------ tests/suite/cli_misc.rs | 6 +++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 54845b007f..3439e416c6 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -547,9 +547,13 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result info!("The currently active `rustc` version is `{}`", version), - Err(err) => trace!("Wanted to tell you the current rustc version, too, but ran into this error: {}", err), + match cfg.active_rustc_version() { + Ok(Some(version)) => info!("The currently active `rustc` version is `{}`", version), + Ok(None) => info!("No `rustc` is currently active"), + Err(err) => trace!( + "Wanted to tell you the current rustc version, too, but ran into this error: {}", + err + ), } return Ok(utils::ExitCode(0)); } diff --git a/src/config.rs b/src/config.rs index 2b4cb873ae..067da9db01 100644 --- a/src/config.rs +++ b/src/config.rs @@ -694,17 +694,16 @@ impl<'a> Cfg<'a> { } #[tracing::instrument(level = "trace")] - pub(crate) async fn active_rustc_version(&mut self) -> Result { + pub(crate) fn active_rustc_version(&mut self) -> Result> { if let Some(t) = self.process.args().find(|x| x.starts_with('+')) { trace!("Fetching rustc version from toolchain `{}`", t); self.set_toolchain_override(&ResolvableToolchainName::try_from(&t[1..])?); } - Ok(self - .find_or_install_active_toolchain() - .await? - .0 - .rustc_version()) + let Some((name, _)) = self.find_active_toolchain()? else { + return Ok(None); + }; + Ok(Some(Toolchain::new(self, name)?.rustc_version())) } pub(crate) async fn resolve_toolchain( diff --git a/tests/suite/cli_misc.rs b/tests/suite/cli_misc.rs index 3dee46f337..e536901cf9 100644 --- a/tests/suite/cli_misc.rs +++ b/tests/suite/cli_misc.rs @@ -21,13 +21,17 @@ async fn smoke_test() { #[tokio::test] async fn version_mentions_rustc_version_confusion() { - let cx = CliTestContext::new(Scenario::SimpleV2).await; + let mut cx = CliTestContext::new(Scenario::SimpleV2).await; let out = cx.config.run("rustup", vec!["--version"], &[]).await; assert!(out.ok); assert!(out .stderr .contains("This is the version for the rustup toolchain manager")); + cx.config + .expect_ok(&["rustup", "toolchain", "install", "nightly"]) + .await; + let out = cx .config .run("rustup", vec!["+nightly", "--version"], &[]) From 88c7ca68e2c4c8217ad601634c6d333ba23f38bc Mon Sep 17 00:00:00 2001 From: rami3l Date: Mon, 15 Jul 2024 10:12:23 +0800 Subject: [PATCH 2/3] fix(rustup-mode): refine output for `rustup --version` --- src/cli/rustup_mode.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 3439e416c6..5d482e046c 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -548,12 +548,9 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result info!("The currently active `rustc` version is `{}`", version), + Ok(Some(version)) => info!("The currently active `rustc` version is `{version}`"), Ok(None) => info!("No `rustc` is currently active"), - Err(err) => trace!( - "Wanted to tell you the current rustc version, too, but ran into this error: {}", - err - ), + Err(err) => trace!("Failed to display the current `rustc` version: {err}"), } return Ok(utils::ExitCode(0)); } From d0d9bdbf927f1c00d6253b74a272a941e6389836 Mon Sep 17 00:00:00 2001 From: rami3l Date: Mon, 15 Jul 2024 10:34:41 +0800 Subject: [PATCH 3/3] test(cli-misc): simplify `version_mentions_rustc_version_confusion()` --- tests/suite/cli_misc.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/suite/cli_misc.rs b/tests/suite/cli_misc.rs index e536901cf9..e8f3588d73 100644 --- a/tests/suite/cli_misc.rs +++ b/tests/suite/cli_misc.rs @@ -22,24 +22,24 @@ async fn smoke_test() { #[tokio::test] async fn version_mentions_rustc_version_confusion() { let mut cx = CliTestContext::new(Scenario::SimpleV2).await; - let out = cx.config.run("rustup", vec!["--version"], &[]).await; - assert!(out.ok); - assert!(out - .stderr - .contains("This is the version for the rustup toolchain manager")); + + cx.config + .expect_stderr_ok( + &["rustup", "--version"], + "This is the version for the rustup toolchain manager", + ) + .await; cx.config .expect_ok(&["rustup", "toolchain", "install", "nightly"]) .await; - let out = cx - .config - .run("rustup", vec!["+nightly", "--version"], &[]) + cx.config + .expect_stderr_ok( + &["rustup", "+nightly", "--version"], + "The currently active `rustc` version is `1.3.0", + ) .await; - assert!(out.ok); - assert!(out - .stderr - .contains("The currently active `rustc` version is `1.3.0")); } #[tokio::test]