From ea129e9f2f34ed9a5c13d44162853e12ea230fd1 Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Sat, 8 Aug 2026 20:39:31 +0100 Subject: [PATCH] improve error message when default components are unavailable on a new toolchain fix clippy fmt --- src/dist/mod.rs | 13 +++++++++++++ src/errors.rs | 22 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/dist/mod.rs b/src/dist/mod.rs index f348188943..cf5fc01c44 100644 --- a/src/dist/mod.rs +++ b/src/dist/mod.rs @@ -84,6 +84,12 @@ fn components_missing_msg(cs: &[Component], manifest: &ManifestV2, toolchain: &s } } + let from_complete_profile = manifest + .profiles + .get(&Profile::Complete) + .map(|profile| cs.iter().all(|c| profile.contains(&c.pkg))) + .unwrap_or(false); + if toolchain.starts_with("nightly") { let _ = write!( buf, @@ -97,6 +103,13 @@ fn components_missing_msg(cs: &[Component], manifest: &ManifestV2, toolchain: &s help: then you can use the toolchain with commands such as:\n\ help: cargo +nightly-2018-12-27 build" ); + } else if from_complete_profile { + let _ = write!( + buf, + "\ +note: these were added as default components on another toolchain +help: run `rustup set profile minimal` to stop new toolchains from inheriting extra components" + ); } else if ["beta", "stable"].iter().any(|&p| toolchain.starts_with(p)) { let _ = write!( buf, diff --git a/src/errors.rs b/src/errors.rs index b9867dd875..009832f9e0 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -12,7 +12,7 @@ use url::Url; use crate::{ dist::{ - Channel, TargetTuple, ToolchainDesc, + Channel, Profile, TargetTuple, ToolchainDesc, manifest::{Component, Manifest}, }, toolchain::{PathBasedToolchainName, ToolchainName}, @@ -217,6 +217,8 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: & if toolchain.starts_with("nightly") { let _ = write!(buf, "{NIGHTLY_COMPONENT_NOTE}"); + } else { + write_nightly_profile_hint(&mut buf, cs, manifest); } } cs => { @@ -244,6 +246,8 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: & if toolchain.starts_with("nightly") { let _ = write!(buf, "{NIGHTLY_COMPONENT_NOTE}"); + } else { + write_nightly_profile_hint(&mut buf, cs, manifest); } } } @@ -251,6 +255,22 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: & String::from_utf8(buf).unwrap() } +fn write_nightly_profile_hint(buf: &mut Vec, cs: &[Component], manifest: &Manifest) { + let from_complete_profile = manifest + .profiles + .get(&Profile::Complete) + .map(|profile| cs.iter().all(|c| profile.contains(&c.pkg))) + .unwrap_or(false); + if from_complete_profile { + let _ = write!( + buf, + "\ +note: these were added as default components on another toolchain +help: run `rustup set profile minimal` to stop new toolchains from inheriting extra components" + ); + } +} + fn unknown_components_msg(desc: &ToolchainDesc, components: &[UnknownComponentInfo]) -> String { let mut buf = String::new();