Skip to content

Commit bc1dd09

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

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-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

+4-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ impl<'a> Toolchain<'a> {
107107
let path = cfg.toolchain_path(&name);
108108
if !Toolchain::exists(cfg, &name)? {
109109
return Err(match name {
110-
LocalToolchainName::Named(name) => RustupError::ToolchainNotInstalled { name },
110+
LocalToolchainName::Named(name) => {
111+
let is_active = matches!(cfg.active_toolchain(), Ok(Some((t, _))) if t == name);
112+
RustupError::ToolchainNotInstalled { name, is_active }
113+
}
111114
LocalToolchainName::Path(name) => RustupError::PathToolchainNotInstalled(name),
112115
});
113116
}

0 commit comments

Comments
 (0)