Skip to content

Commit

Permalink
Give a better error message when a component isn't installed for a cu…
Browse files Browse the repository at this point in the history
…stom toolchain
  • Loading branch information
jyn514 committed Sep 13, 2020
1 parent 7d65512 commit 7f15622
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::large_enum_variant)]
#![allow(deprecated)] // because of `Error::description` deprecation in `error_chain`

use crate::component_for_bin;
use crate::{component_for_bin, Toolchain};
use crate::dist::dist::Profile;
use crate::dist::manifest::{Component, Manifest};
use crate::dist::temp;
Expand Down Expand Up @@ -444,6 +444,10 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &
}

fn install_msg(bin: &str, toolchain: &str, is_default: bool) -> String {
if Toolchain::is_custom_name(toolchain) {
return format!("\nnote: this is a custom toolchain, which cannot use `rustup component add`\n\
help: if you installed this toolchain from source with `rustup component link`, you can build the component with `x.py`");
}
match component_for_bin(bin) {
Some(c) => format!("\nTo install, run `rustup component add {}{}`", c, {
if is_default {
Expand Down
7 changes: 6 additions & 1 deletion src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,13 @@ impl<'a> Toolchain<'a> {

// Custom only
pub fn is_custom(&self) -> bool {
ToolchainDesc::from_str(&self.name).is_err()
Toolchain::is_custom_name(&self.name)
}

pub(crate) fn is_custom_name(name: &str) -> bool {
ToolchainDesc::from_str(name).is_err()
}

// Distributable only
pub fn is_tracking(&self) -> bool {
ToolchainDesc::from_str(&self.name)
Expand Down
4 changes: 2 additions & 2 deletions tests/cli-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,11 @@ fn rustup_failed_path_search_toolchain() {
expect_err(
config,
broken,
"rustup component add miri --toolchain custom-1",
"cannot use `rustup component add`",
);

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

// Hardlink will be automatically cleaned up by test setup code
});
Expand Down

0 comments on commit 7f15622

Please sign in to comment.