Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rustup-mode)!: don't install toolchain on rustup --version #3948

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,10 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
write!(process.stdout().lock(), "{err}")?;
info!("This is the version for the rustup toolchain manager, not the rustc compiler.");
let mut cfg = common::set_globals(current_dir, false, true, process)?;
match cfg.active_rustc_version().await {
Ok(version) => 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!("Failed to display the current `rustc` version: {err}"),
}
return Ok(utils::ExitCode(0));
}
Expand Down
11 changes: 5 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,17 +694,16 @@ impl<'a> Cfg<'a> {
}

#[tracing::instrument(level = "trace")]
pub(crate) async fn active_rustc_version(&mut self) -> Result<String> {
pub(crate) fn active_rustc_version(&mut self) -> Result<Option<String>> {
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(
Expand Down
30 changes: 17 additions & 13 deletions tests/suite/cli_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ async fn smoke_test() {

#[tokio::test]
async fn version_mentions_rustc_version_confusion() {
let 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"));
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;

let out = cx
.config
.run("rustup", vec!["+nightly", "--version"], &[])
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;

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]
Expand Down
Loading