From 39c23c5edf48037fd25f619429d2e7a303a59e84 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 13 Sep 2020 15:32:31 -0400 Subject: [PATCH] Give a better error message when a component isn't installed for a custom toolchain This re-orders imports because rustfmt really wants them to change. --- src/errors.rs | 6 +++++- src/toolchain.rs | 7 ++++++- tests/cli-misc.rs | 8 ++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index eb411de371..480a8533b2 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,10 +1,10 @@ #![allow(clippy::large_enum_variant)] #![allow(deprecated)] // because of `Error::description` deprecation in `error_chain` -use crate::component_for_bin; use crate::dist::dist::Profile; use crate::dist::manifest::{Component, Manifest}; use crate::dist::temp; +use crate::{component_for_bin, Toolchain}; use error_chain::error_chain; use std::ffi::OsString; use std::io::{self, Write}; @@ -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 "\nnote: this is a custom toolchain, which cannot use `rustup component add`\n\ + 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(); + } match component_for_bin(bin) { Some(c) => format!("\nTo install, run `rustup component add {}{}`", c, { if is_default { diff --git a/src/toolchain.rs b/src/toolchain.rs index d73d970982..d1bb62102a 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -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) diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index 0adcf3ccfd..916eb65252 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -370,14 +370,10 @@ fn rustup_failed_path_search_toolchain() { expect_ok(config, &["rustup", "default", "custom-2"]); let broken = &["rustup", "run", "custom-1", "cargo-miri"]; - expect_err( - config, - broken, - "rustup component add miri --toolchain custom-1", - ); + expect_err(config, broken, "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 });