Skip to content

feat: suggest rustup component add from another installed toolchain - #5139

Open
14elias wants to merge 6 commits into
rust-lang:mainfrom
14elias:feature/component-add-suggestion
Open

14elias wants to merge 6 commits into
rust-lang:mainfrom
14elias:feature/component-add-suggestion

Conversation

@14elias

@14elias 14elias commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

related #5098

This change improves component suggestions when a requested component is not available in the active toolchain.
Previously, rustup could suggest a component removal from another toolchain, but it did not handle the add case. This patch makes component suggestions action-aware and adds a toolchain-based suggestion for rustup component add.

Comment thread src/errors.rs Resolved
Comment thread src/errors.rs Resolved
Comment thread tests/suite/cli_v2.rs Resolved
@14elias
14elias force-pushed the feature/component-add-suggestion branch from 53d9b8c to ad63aa3 Compare October 12, 2026 22:26
Comment thread src/errors.rs Outdated
manifest: &Manifest,
cfg: &Cfg<'_>,
) -> Option<Self> {
Self::for_action(

@djc djc Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this callback solution isn't much better than the previous unabstracted solution. Suggest factoring out some helper functions instead.

View changes since the review

@14elias
14elias force-pushed the feature/component-add-suggestion branch 2 times, most recently from 39a0a0c to 951efbb Compare October 13, 2026 14:52
@14elias
14elias requested review from djc and rami3l October 14, 2026 19:24
@14elias

14elias commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

hi @rami3l @djc i think i have addressed all the feedback. whenever you have a moment could you take another look? Thanks!

@djc djc left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit history here currently does not make much sense to me.

View changes since this review

Comment thread src/errors.rs Outdated
candidate_name == component.name() || candidate_name == component.wildcard().name()
}

fn toolchain_has_installed_component(toolchain: &Toolchain<'_>, component: &Component) -> bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has a single caller, just inline it?

Comment thread src/errors.rs Outdated
.any(|installed| component_matches(component, installed.name()))
}

fn toolchain_has_available_component(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@14elias
14elias force-pushed the feature/component-add-suggestion branch 2 times, most recently from 53b8a1a to 0c480f7 Compare October 26, 2026 20:41
Comment thread src/errors.rs Resolved
Comment thread src/errors.rs Resolved
Comment thread src/errors.rs Resolved
Comment thread src/errors.rs Resolved
@14elias
14elias force-pushed the feature/component-add-suggestion branch from 0c480f7 to 119efc3 Compare October 31, 2026 18:41
@rustbot

rustbot commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@14elias
14elias force-pushed the feature/component-add-suggestion branch 3 times, most recently from d166b47 to a0d2415 Compare November 1, 2026 11:25
@14elias
14elias requested review from djc and rami3l November 9, 2026 12:58
@rami3l rami3l self-assigned this Nov 13, 2026

@rami3l rami3l left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely getting much better than before, I believe we are getting pretty close to getting this merged, thanks :)

PS: I'm so sorry for the late reply, it has been buried in my inbox for a while.

View changes since this review

Comment thread src/errors.rs Outdated
.filter(move |c| c.desc() != desc)
}

fn component_matches(component: &Component, candidate_name: &str) -> bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I believe this is a very specific use case and maybe should be inlined if this logic is not reused elsewhere. If you want to use the function name to explain the intended logic here, try using a comment instead..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I believe this is a very specific use case and maybe should be inlined if this logic is not reused elsewhere. If you want to use the function name to explain the intended logic here, try using a comment instead..

it is reused by both for_addition and for_removal methods. should i inline it ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@14elias Yes, please :)

Comment thread src/errors.rs
Comment on lines +123 to +147
pub(crate) fn for_addition(
desc: &ChannelToolchainName,
component: &Component,
config: &DistConfig,
manifest: &Manifest,
cfg: &Cfg<'_>,
) -> Option<Self> {
for channel_toolchain in other_channel_toolchains(desc, cfg) {
let Ok(components) = channel_toolchain.components() else {
continue;
};
if components.iter().any(|status| {
status.available && component_matches(component, &status.component.name())
}) {
return Some(Self::Toolchain {
name: channel_toolchain.desc().to_string(),
component: manifest.short_name(component).to_string(),
action: "add",
});
}
}

component_suggestion(desc, component, config, manifest, false).map(Self::Component)
}
}

@rami3l rami3l Nov 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are still doing two steps in one here. Suggest extracting for_addition() in a first commit, and then add the feature along with the test in a later commit.

@14elias
14elias force-pushed the feature/component-add-suggestion branch from a0d2415 to d8fb75c Compare November 18, 2026 08:22

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants