Skip to content

Commit 495a682

Browse files
committed
Give a better error when std is missing for a target
- Note that not all platforms have std pre-compiled - Suggestion `cargo build -Zbuild-std` on nightly
1 parent a738acd commit 495a682

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/errors.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,16 @@ error_chain! {
351351
}
352352
UnknownComponent(t: String, c: String, s: Option<String>) {
353353
description("toolchain does not contain component")
354-
display("toolchain '{}' does not contain component {}{}", t, c, if let Some(suggestion) = s {
355-
format!("; did you mean '{}'?", suggestion)
356-
} else {
357-
"".to_string()
358-
})
354+
display("toolchain '{}' does not contain component {}{}{}", t, c, if let Some(suggestion) = s {
355+
format!("; did you mean '{}'?", suggestion)
356+
} else {
357+
"".to_string()
358+
}, if c.contains("rust-std") {
359+
format!("\nnote: not all platforms have the standard library pre-compiled: https://doc.rust-lang.org/nightly/rustc/platform-support.html{}",
360+
if t.contains("nightly") { "\nhelp: consider using `cargo build -Z build-std` instead" } else { "" }
361+
)
362+
} else { "".to_string() }
363+
)
359364
}
360365
UnknownProfile(p: String) {
361366
description("unknown profile name")

tests/cli-v2.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,9 @@ fn add_target_bogus() {
784784
expect_err(
785785
config,
786786
&["rustup", "target", "add", "bogus"],
787-
"does not contain component 'rust-std' for target 'bogus'",
787+
"does not contain component 'rust-std' for target 'bogus'\n\
788+
note: not all platforms have the standard library pre-compiled: https://doc.rust-lang.org/nightly/rustc/platform-support.html\n\
789+
help: consider using `cargo build -Z build-std` instead",
788790
);
789791
});
790792
}

0 commit comments

Comments
 (0)