Skip to content

Commit 4b961f6

Browse files
committed
fix(errors)!: improve error messages for RustupError::ToolchainNotInstalled
1 parent 4b52f5c commit 4b961f6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/errors.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,16 @@ pub enum RustupError {
9898
#[error(
9999
"toolchain '{name}' is not installed{}",
100100
if let ToolchainName::Official(t) = name {
101-
format!("\nhelp: run `rustup toolchain install {t}` to install it")
101+
let t = if *is_active { "" } else { &format!(" {t}") };
102+
format!("\nhelp: run `rustup toolchain install{t}` to install it")
102103
} else {
103104
String::new()
104105
},
105106
)]
106-
ToolchainNotInstalled { name: ToolchainName },
107+
ToolchainNotInstalled {
108+
name: ToolchainName,
109+
is_active: bool,
110+
},
107111
#[error("path '{0}' not found")]
108112
PathToolchainNotInstalled(PathBasedToolchainName),
109113
#[error(

src/toolchain.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl<'a> Toolchain<'a> {
5353
Ok(tc) => Ok(tc),
5454
Err(RustupError::ToolchainNotInstalled {
5555
name: ToolchainName::Official(desc),
56+
..
5657
}) if install_if_missing => {
5758
Ok(
5859
DistributableToolchain::install(cfg, &desc, &[], &[], cfg.get_profile()?, true)
@@ -107,7 +108,10 @@ impl<'a> Toolchain<'a> {
107108
let path = cfg.toolchain_path(&name);
108109
if !Toolchain::exists(cfg, &name)? {
109110
return Err(match name {
110-
LocalToolchainName::Named(name) => RustupError::ToolchainNotInstalled { name },
111+
LocalToolchainName::Named(name) => {
112+
let is_active = matches!(cfg.active_toolchain(), Ok(Some((t, _))) if t == name);
113+
RustupError::ToolchainNotInstalled { name, is_active }
114+
}
111115
LocalToolchainName::Path(name) => RustupError::PathToolchainNotInstalled(name),
112116
});
113117
}

0 commit comments

Comments
 (0)