Skip to content

Restore old behaviour for rustup show active-toolchain #4221

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

Merged
merged 1 commit into from
Mar 4, 2025
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
22 changes: 14 additions & 8 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,18 +1085,24 @@ fn show_active_toolchain(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode
match cfg.find_active_toolchain()? {
Some((toolchain_name, reason)) => {
let toolchain = Toolchain::with_reason(cfg, toolchain_name.clone(), &reason)?;
writeln!(
cfg.process.stdout().lock(),
"{}\nactive because: {}",
toolchain.name(),
reason
)?;
if verbose {
writeln!(
cfg.process.stdout().lock(),
"compiler: {}\npath: {}",
"{}\nactive because: {}\ncompiler: {}\npath: {}",
toolchain.name(),
reason,
toolchain.rustc_version(),
toolchain.path().display(),
toolchain.path().display()
)?;
} else {
writeln!(
cfg.process.stdout().lock(),
"{} ({})",
toolchain.name(),
match reason {
ActiveReason::Default => &"default" as &dyn fmt::Display,
_ => &reason,
}
)?;
}
}
Expand Down
33 changes: 31 additions & 2 deletions tests/suite/cli_rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ async fn show_active_toolchain() {
cx.config
.expect_ok_ex(
&["rustup", "show", "active-toolchain"],
for_host!("nightly-{0}\nactive because: it's the default toolchain\n"),
for_host!("nightly-{0} (default)\n"),
r"",
)
.await;
Expand Down Expand Up @@ -1260,7 +1260,36 @@ async fn show_active_toolchain_with_override() {
cx.config
.expect_stdout_ok(
&["rustup", "show", "active-toolchain"],
for_host!("stable-{0}\nactive because: directory override for"),
for_host!("stable-{0}"),
)
.await;
}

#[tokio::test]
async fn show_active_toolchain_with_override_verbose() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config.expect_ok(&["rustup", "default", "stable"]).await;
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
cx.config
.expect_ok(&["rustup", "override", "set", "stable"])
.await;
cx.config
.expect_ok_ex(
&["rustup", "show", "active-toolchain", "--verbose"],
for_host!(
r"stable-{0}
active because: directory override for '{1}'
compiler: 1.1.0 (hash-stable-1.1.0)
path: {2}
",
cx.config.current_dir().display(),
cx.config
.rustupdir
.join("toolchains")
.join(for_host!("stable-{0}"))
.display(),
),
r"",
)
.await;
}
Expand Down