Skip to content

Commit e5e86c3

Browse files
committed
Provide a more actionable error message when a toolchain is not selected
Builds on top of previous commit. Fixes #2915.
1 parent ae7247f commit e5e86c3

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

src/errors.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::path::PathBuf;
88
use thiserror::Error as ThisError;
99
use url::Url;
1010

11+
use crate::currentprocess::process;
1112
use crate::dist::manifest::{Component, Manifest};
1213

1314
const TOOLSTATE_MSG: &str =
@@ -88,7 +89,11 @@ pub enum RustupError {
8889
ToolchainNotInstallable(String),
8990
#[error("toolchain '{0}' is not installed")]
9091
ToolchainNotInstalled(String),
91-
#[error("no override and no default toolchain set")]
92+
#[error(
93+
"rustup could not choose a version of {} to run, because one wasn't specified explicitly, and no default is configured.\n{}",
94+
process().name().unwrap_or_else(|| "Rust".into()),
95+
"help: run 'rustup default stable' to download the latest stable release of Rust and set it as your default toolchain."
96+
)]
9297
ToolchainNotSelected,
9398
#[error("toolchain '{}' does not contain component {}{}{}", .name, .component, if let Some(suggestion) = .suggestion {
9499
format!("; did you mean '{}'?", suggestion)

tests/cli-exact.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,9 @@ fn default_none() {
599599
config,
600600
&["rustc", "--version"],
601601
"",
602-
"error: no override and no default toolchain set\n",
602+
"error: rustup could not choose a version of rustc to run, because one wasn't specified explicitly, and no default is configured.
603+
help: run 'rustup default stable' to download the latest stable release of Rust and set it as your default toolchain.
604+
",
603605
);
604606
})
605607
}

tests/cli-rustup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,7 @@ fn rust_toolchain_toml() {
21792179
expect_err(
21802180
config,
21812181
&["rustc", "--version"],
2182-
"no override and no default toolchain set",
2182+
"rustup could not choose a version of rustc to run",
21832183
);
21842184

21852185
let cwd = config.current_dir();

tests/cli-v1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn rustc_no_default_toolchain() {
2222
expect_err(
2323
config,
2424
&["rustc"],
25-
"no override and no default toolchain set",
25+
"rustup could not choose a version of rustc to run",
2626
);
2727
});
2828
}
@@ -305,7 +305,7 @@ fn remove_override_no_default() {
305305
expect_err(
306306
config,
307307
&["rustc"],
308-
"no override and no default toolchain set",
308+
"rustup could not choose a version of rustc to run",
309309
);
310310
});
311311
});

tests/cli-v2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn rustc_no_default_toolchain() {
3030
expect_err(
3131
config,
3232
&["rustc"],
33-
"no override and no default toolchain set",
33+
"rustup could not choose a version of rustc to run",
3434
);
3535
});
3636
}
@@ -477,7 +477,7 @@ fn remove_override_no_default() {
477477
expect_err(
478478
config,
479479
&["rustc"],
480-
"no override and no default toolchain set",
480+
"rustup could not choose a version of rustc to run",
481481
);
482482
});
483483
});

0 commit comments

Comments
 (0)