Skip to content

Commit edb80dc

Browse files
authored
Merge pull request #3372 from hi-rustin/rustin-patch-err
Add suggest_message helper for errors
2 parents 120331b + 5b52dfe commit edb80dc

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/errors.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,7 @@ pub(crate) enum RustupError {
103103
"help: run 'rustup default stable' to download the latest stable release of Rust and set it as your default toolchain."
104104
)]
105105
ToolchainNotSelected,
106-
#[error("toolchain '{}' does not contain component {}{}{}", .desc, .component, if let Some(suggestion) = .suggestion {
107-
format!("; did you mean '{suggestion}'?")
108-
} else {
109-
"".to_string()
110-
}, if .component.contains("rust-std") {
106+
#[error("toolchain '{}' does not contain component {}{}{}", .desc, .component, suggest_message(.suggestion), if .component.contains("rust-std") {
111107
format!("\nnote: not all platforms have the standard library pre-compiled: https://doc.rust-lang.org/nightly/rustc/platform-support.html{}",
112108
if desc.channel == "nightly" { "\nhelp: consider using `cargo build -Z build-std` instead" } else { "" }
113109
)
@@ -120,22 +116,14 @@ pub(crate) enum RustupError {
120116
#[error("toolchain '{}' does not support target '{}'{}\n\
121117
note: you can see a list of supported targets with `rustc --print=target-list`\n\
122118
note: if you are adding support for a new target to rustc itself, see https://rustc-dev-guide.rust-lang.org/building/new-target.html", .desc, .target,
123-
if let Some(suggestion) = .suggestion {
124-
format!("; did you mean '{suggestion}'?")
125-
} else {
126-
"".to_string()
127-
})]
119+
suggest_message(.suggestion))]
128120
UnknownTarget {
129121
desc: ToolchainDesc,
130122
target: TargetTriple,
131123
suggestion: Option<String>,
132124
},
133125
#[error("toolchain '{}' does not have target '{}' installed{}\n", .desc, .target,
134-
if let Some(suggestion) = .suggestion {
135-
format!("; did you mean '{suggestion}'?")
136-
} else {
137-
"".to_string()
138-
})]
126+
suggest_message(.suggestion))]
139127
TargetNotInstalled {
140128
desc: ToolchainDesc,
141129
target: TargetTriple,
@@ -151,6 +139,14 @@ pub(crate) enum RustupError {
151139
IOError(#[from] std::io::Error),
152140
}
153141

142+
fn suggest_message(suggestion: &Option<String>) -> String {
143+
if let Some(suggestion) = suggestion {
144+
format!("; did you mean '{}'?", suggestion)
145+
} else {
146+
String::new()
147+
}
148+
}
149+
154150
fn remove_component_msg(cs: &Component, manifest: &Manifest, toolchain: &str) -> String {
155151
if cs.short_name_in_manifest() == "rust-std" {
156152
// We special-case rust-std as it's the stdlib so really you want to do

0 commit comments

Comments
 (0)