Skip to content

Commit

Permalink
Make rustup default not error if no default
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
majaha authored and rami3l committed May 8, 2024
1 parent ac3fc5b commit 8d81ef7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
13 changes: 9 additions & 4 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,15 @@ fn default_(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
}
}
} 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))
Expand Down
7 changes: 7 additions & 0 deletions tests/suite/cli_exact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
"",
Expand Down
7 changes: 0 additions & 7 deletions tests/suite/cli_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/cli_rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 8d81ef7

Please sign in to comment.