Skip to content

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

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

14elias wants to merge 4 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 Outdated
Comment on lines +149 to +152
fn other_channel_toolchains<'a>(
cfg: &'a Cfg<'a>,
desc: &ChannelToolchainName,
) -> impl Iterator<Item = (ChannelToolchainName, ChannelToolchain<'a>)> {

@rami3l rami3l Oct 28, 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.

Nit: It looks like you are mimicking Cfg::list_channels() but that function is probably not the best abstraction, because:

  1. Cfg::list_channels() is choosing only tracking channels, which might make its current name imprecise.
  2. ChannelToolchainName can be fetched from ChannelToolchain::desc(), and there should be no point in storing both?
  3. other_channel_toolchains() is doing another kind of filtering but over mostly the same collection.

Could we do some refactoring actions upfront so this looks even nicer?

View changes since the review

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.

What do you think about making Cfg::list_channels() return all installed channel toolchains, then reusing it in both Cfg::list_tracking_channels() and other_channel_toolchains() to apply their respective filters? on top of PR #5175.

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 Yeah something like that would be cool, probably list_channels() returning an iterator could be worth investigating in the meantime.

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 2 times, most recently from 571a7ab to d166b47 Compare November 1, 2026 10:23
@14elias
14elias force-pushed the feature/component-add-suggestion branch from d166b47 to a0d2415 Compare November 1, 2026 11:25

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