Repository navigation
Conversation
53d9b8c to
ad63aa3
Compare
| manifest: &Manifest, | ||
| cfg: &Cfg<'_>, | ||
| ) -> Option<Self> { | ||
| Self::for_action( |
There was a problem hiding this comment.
IMO this callback solution isn't much better than the previous unabstracted solution. Suggest factoring out some helper functions instead.
39a0a0c to
951efbb
Compare
| candidate_name == component.name() || candidate_name == component.wildcard().name() | ||
| } | ||
|
|
||
| fn toolchain_has_installed_component(toolchain: &Toolchain<'_>, component: &Component) -> bool { |
There was a problem hiding this comment.
This has a single caller, just inline it?
| .any(|installed| component_matches(component, installed.name())) | ||
| } | ||
|
|
||
| fn toolchain_has_available_component( |
53b8a1a to
0c480f7
Compare
0c480f7 to
119efc3
Compare
|
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. |
d166b47 to
a0d2415
Compare
| .filter(move |c| c.desc() != desc) | ||
| } | ||
|
|
||
| fn component_matches(component: &Component, candidate_name: &str) -> bool { |
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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 ?
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
a0d2415 to
d8fb75c
Compare
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.