From 8d81ef76d8b2fe4d650765d861a082672d92020f Mon Sep 17 00:00:00 2001 From: Matt Harding Date: Fri, 8 Dec 2023 12:06:55 +0000 Subject: [PATCH] Make `rustup default` not error if no default `rustup default` will no longer error and print to stderr if there is no default toolchain configured. It will print to stdout and exit successfully instead. --- src/cli/rustup_mode.rs | 13 +++++++++---- tests/suite/cli_exact.rs | 7 +++++++ tests/suite/cli_misc.rs | 7 ------- tests/suite/cli_rustup.rs | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 8403a30234b..425666ac33d 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -872,10 +872,15 @@ fn default_(cfg: &Cfg, m: &ArgMatches) -> Result { } } } else { - let default_toolchain = cfg - .get_default()? - .ok_or_else(|| anyhow!("no default toolchain configured"))?; - writeln!(process().stdout().lock(), "{default_toolchain} (default)")?; + match cfg.get_default()? { + Some(default_toolchain) => { + writeln!(process().stdout().lock(), "{default_toolchain} (default)")?; + } + None => writeln!( + process().stdout().lock(), + "no default toolchain is configured" + )?, + } } Ok(utils::ExitCode(0)) diff --git a/tests/suite/cli_exact.rs b/tests/suite/cli_exact.rs index fc92c22ade9..383d8f5bb1a 100644 --- a/tests/suite/cli_exact.rs +++ b/tests/suite/cli_exact.rs @@ -577,6 +577,13 @@ fn default_none() { &["rustup", "default", "none"], "info: default toolchain unset", ); + + config.expect_ok_ex( + &["rustup", "default"], + "no default toolchain is configured\n", + "", + ); + config.expect_err_ex( &["rustc", "--version"], "", diff --git a/tests/suite/cli_misc.rs b/tests/suite/cli_misc.rs index 1a3e60dcf35..63e1720e974 100644 --- a/tests/suite/cli_misc.rs +++ b/tests/suite/cli_misc.rs @@ -477,13 +477,6 @@ fn toolchains_are_resolved_early() { }); } -#[test] -fn no_panic_on_default_toolchain_missing() { - setup(&|config| { - config.expect_err(&["rustup", "default"], "no default toolchain configured"); - }); -} - // #190 #[test] fn proxies_pass_empty_args() { diff --git a/tests/suite/cli_rustup.rs b/tests/suite/cli_rustup.rs index a07f2954b0e..89d4f85a9fb 100644 --- a/tests/suite/cli_rustup.rs +++ b/tests/suite/cli_rustup.rs @@ -2482,7 +2482,7 @@ fn check_unix_settings_fallback() { test(&|config| { config.with_scenario(Scenario::SimpleV2, &|config| { // No default toolchain specified yet - config.expect_err(&["rustup", "default"], r"no default toolchain configured"); + config.expect_stdout_ok(&["rustup", "default"], "no default toolchain is configured"); // Default toolchain specified in fallback settings file let mock_settings_file = config.current_dir().join("mock_fallback_settings.toml");