Skip to content

Commit 5d79406

Browse files
authored
Merge pull request #2487 from jyn514/custom-component
Give a better error message when a component isn't installed for a custom toolchain
2 parents 1e0af0b + 39c23c5 commit 5d79406

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/errors.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![allow(clippy::large_enum_variant)]
22
#![allow(deprecated)] // because of `Error::description` deprecation in `error_chain`
33

4-
use crate::component_for_bin;
54
use crate::dist::dist::Profile;
65
use crate::dist::manifest::{Component, Manifest};
76
use crate::dist::temp;
7+
use crate::{component_for_bin, Toolchain};
88
use error_chain::error_chain;
99
use std::ffi::OsString;
1010
use std::io::{self, Write};
@@ -444,6 +444,10 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &
444444
}
445445

446446
fn install_msg(bin: &str, toolchain: &str, is_default: bool) -> String {
447+
if Toolchain::is_custom_name(toolchain) {
448+
return "\nnote: this is a custom toolchain, which cannot use `rustup component add`\n\
449+
help: if you built this toolchain from source, and used `rustup component link`, then you may be able to build the component with `x.py`".to_string();
450+
}
447451
match component_for_bin(bin) {
448452
Some(c) => format!("\nTo install, run `rustup component add {}{}`", c, {
449453
if is_default {

src/toolchain.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,13 @@ impl<'a> Toolchain<'a> {
150150

151151
// Custom only
152152
pub fn is_custom(&self) -> bool {
153-
ToolchainDesc::from_str(&self.name).is_err()
153+
Toolchain::is_custom_name(&self.name)
154154
}
155+
156+
pub(crate) fn is_custom_name(name: &str) -> bool {
157+
ToolchainDesc::from_str(name).is_err()
158+
}
159+
155160
// Distributable only
156161
pub fn is_tracking(&self) -> bool {
157162
ToolchainDesc::from_str(&self.name)

tests/cli-misc.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,10 @@ fn rustup_failed_path_search_toolchain() {
370370
expect_ok(config, &["rustup", "default", "custom-2"]);
371371

372372
let broken = &["rustup", "run", "custom-1", "cargo-miri"];
373-
expect_err(
374-
config,
375-
broken,
376-
"rustup component add miri --toolchain custom-1",
377-
);
373+
expect_err(config, broken, "cannot use `rustup component add`");
378374

379375
let broken = &["rustup", "run", "custom-2", "cargo-miri"];
380-
expect_err(config, broken, "rustup component add miri");
376+
expect_err(config, broken, "cannot use `rustup component add`");
381377

382378
// Hardlink will be automatically cleaned up by test setup code
383379
});

0 commit comments

Comments
 (0)