From 6613e05363adf020c028e78cea2569d9716aac1d Mon Sep 17 00:00:00 2001 From: rami3l Date: Sun, 20 Aug 2023 13:44:22 +0800 Subject: [PATCH] Delete suggestions of removing the relevant component from `component_unavailable_msg` After digging into the codebase, I realized that the message generated by `component_unavailable_msg` is used only when: - Some components are missing from the toolchain so that the installation can no longer proceed; - We are not installing these components as a part of a toolchain-wide operation (e.g. updating the existing `nightly`), which is covered by `components_missing_msg` by catching the `RustupError::RequestedComponentsUnavailable` and re-throwing it as a `DistError::ToolchainComponentsMissing` (see for more info). Thus, I decided to remove the `rustup component remove` suggestion altogether. --- src/dist/manifestation/tests.rs | 88 +++++++++++++++++++++++++-------- src/errors.rs | 51 +++---------------- 2 files changed, 76 insertions(+), 63 deletions(-) diff --git a/src/dist/manifestation/tests.rs b/src/dist/manifestation/tests.rs index 7dd91805258..cfe81562cfb 100644 --- a/src/dist/manifestation/tests.rs +++ b/src/dist/manifestation/tests.rs @@ -772,8 +772,17 @@ fn unavailable_component() { ) .unwrap_err(); match err.downcast::() { - Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => { - assert!(e.to_string().contains("rustup component remove --toolchain nightly --target x86_64-apple-darwin bonus")); + Ok(RustupError::RequestedComponentsUnavailable { + components, + manifest, + toolchain, + }) => { + assert_eq!(toolchain, "nightly"); + let descriptions = components + .iter() + .map(|c| c.description(&manifest)) + .collect::>(); + assert_eq!(descriptions, ["'bonus' for target 'x86_64-apple-darwin'"]) } _ => panic!(), } @@ -833,8 +842,17 @@ fn unavailable_component_from_profile() { ) .unwrap_err(); match err.downcast::() { - Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => { - assert!(e.to_string().contains("rustup component remove --toolchain nightly --target x86_64-apple-darwin rustc")); + Ok(RustupError::RequestedComponentsUnavailable { + components, + manifest, + toolchain, + }) => { + assert_eq!(toolchain, "nightly"); + let descriptions = components + .iter() + .map(|c| c.description(&manifest)) + .collect::>(); + assert_eq!(descriptions, ["'rustc' for target 'x86_64-apple-darwin'"]) } _ => panic!(), } @@ -913,8 +931,17 @@ fn removed_component() { ) .unwrap_err(); match err.downcast::() { - Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => { - assert!(e.to_string().contains("rustup component remove --toolchain nightly --target x86_64-apple-darwin bonus")); + Ok(RustupError::RequestedComponentsUnavailable { + components, + manifest, + toolchain, + }) => { + assert_eq!(toolchain, "nightly"); + let descriptions = components + .iter() + .map(|c| c.description(&manifest)) + .collect::>(); + assert_eq!(descriptions, ["'bonus' for target 'x86_64-apple-darwin'"]) } _ => panic!(), } @@ -992,13 +1019,24 @@ fn unavailable_components_is_target() { ) .unwrap_err(); match err.downcast::() { - Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => { - let err_str = e.to_string(); - assert!(err_str - .contains("rustup target remove --toolchain nightly i686-apple-darwin")); - assert!(err_str.contains( - "rustup target remove --toolchain nightly i686-unknown-linux-gnu" - )); + Ok(RustupError::RequestedComponentsUnavailable { + components, + manifest, + toolchain, + }) => { + assert_eq!(toolchain, "nightly"); + let descriptions = components + .iter() + .map(|c| c.description(&manifest)) + .collect::>(); + assert_eq!( + descriptions, + [ + "'rust-std' for target 'x86_64-apple-darwin'", + "'rust-std' for target 'i686-apple-darwin'", + "'rust-std' for target 'i686-unknown-linux-gnu'" + ] + ); } _ => panic!(), } @@ -1071,13 +1109,23 @@ fn unavailable_components_with_same_target() { ) .unwrap_err(); match err.downcast::() { - Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => { - let err_str = e.to_string(); - assert!(err_str - .contains("rustup target remove --toolchain nightly x86_64-apple-darwin")); - assert!(err_str.contains( - "rustup component remove --toolchain nightly --target x86_64-apple-darwin rustc" - )); + Ok(RustupError::RequestedComponentsUnavailable { + components, + manifest, + toolchain, + }) => { + assert_eq!(toolchain, "nightly"); + let descriptions = components + .iter() + .map(|c| c.description(&manifest)) + .collect::>(); + assert_eq!( + descriptions, + [ + "'rustc' for target 'x86_64-apple-darwin'", + "'rust-std' for target 'x86_64-apple-darwin'" + ] + ); } _ => panic!(), } diff --git a/src/errors.rs b/src/errors.rs index e6014cdb3f1..63d2ad806d8 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -19,14 +19,6 @@ use crate::{ toolchain::names::{PathBasedToolchainName, ToolchainName}, }; -const TOOLSTATE_MSG: &str = - "If you require these components, please install and use the latest successful build version,\n\ - which you can find at .\n\nAfter determining \ - the correct date, install it with a command such as:\n\n \ - rustup toolchain install nightly-2018-12-27\n\n\ - Then you can use the toolchain with commands such as:\n\n \ - cargo +nightly-2018-12-27 build"; - /// A type erasing thunk for the retry crate to permit use with anyhow. See #[derive(Debug, ThisError)] #[error(transparent)] @@ -147,29 +139,6 @@ fn suggest_message(suggestion: &Option) -> String { } } -fn remove_component_msg(cs: &Component, manifest: &Manifest, toolchain: &str) -> String { - if cs.short_name_in_manifest() == "rust-std" { - // We special-case rust-std as it's the stdlib so really you want to do - // rustup target remove - format!( - " rustup target remove --toolchain {} {}", - toolchain, - cs.target.as_deref().unwrap_or(toolchain) - ) - } else { - format!( - " rustup component remove --toolchain {}{} {}", - toolchain, - if let Some(target) = cs.target.as_ref() { - format!(" --target {target}") - } else { - String::default() - }, - cs.short_name(manifest) - ) - } -} - fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &str) -> String { assert!(!cs.is_empty()); @@ -188,11 +157,6 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: & "Sometimes not all components are available in any given nightly. " ); } - let _ = write!( - buf, - "If you don't need the component, you can remove it with:\n\n{}", - remove_component_msg(&cs[0], manifest, toolchain) - ); } else { // More than one component @@ -212,16 +176,17 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: & .join(", ") }; - let remove_msg = cs - .iter() - .map(|c| remove_component_msg(c, manifest, toolchain)) - .collect::>() - .join("\n"); let _ = write!( buf, - "some components unavailable for download for channel '{toolchain}': {cs_str}\n\ - If you don't need the components, you can remove them with:\n\n{remove_msg}\n\n{TOOLSTATE_MSG}", + "some components unavailable for download for channel '{toolchain}': {cs_str}", ); + + if toolchain.starts_with("nightly") { + _ = write!( + buf, + "Sometimes not all components are available in any given nightly. " + ); + } } String::from_utf8(buf).unwrap()