Skip to content

refactor(toolchain)!: remove multiple components at once - #5080

Merged
rami3l merged 7 commits into
rust-lang:mainfrom
rami3l:refactor/dist-remove-mutliple-single-tx
Sep 18, 2026
Merged

rami3l merged 7 commits into
rust-lang:mainfrom
rami3l:refactor/dist-remove-mutliple-single-tx

Conversation

@rami3l

@rami3l rami3l commented Sep 15, 2026

Copy link
Copy Markdown
Member

Part of rust-lang/goals#736.

Currently, a new transaction is set up when removing every component, which is clearly unnecessary.

This PR addresses that issue by removing multiple components at once.

Comment thread src/cli/rustup_mode.rs Outdated
@rami3l
rami3l force-pushed the refactor/dist-remove-mutliple-single-tx branch 2 times, most recently from 8d6b848 to ad53fac Compare September 15, 2026 13:09
@rami3l
rami3l marked this pull request as ready for review September 15, 2026 13:23
@rami3l
rami3l requested a review from djc September 15, 2026 13:23
@rami3l
rami3l force-pushed the refactor/dist-remove-mutliple-single-tx branch from ad53fac to 57d1d7d Compare September 15, 2026 13:55

@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.

I think this direction is okay? But I'd like smaller commits, and I'd probably move DistributableToolchain::remove_components() out of DistributableToolchain into rustup_mode as a first step.

If we're going to pass an IntoIterator<Item = Component> into it, then it doesn't really make sense to me in terms of program flow (as opposed to performance) to allocate a Vec for it upfront, then iterate over it to check some stuff, then transform the Vec into an iterator again.

So I'd like to challenge you to rethink this code a bit more than you're currently doing.

View changes since this review

@rami3l

rami3l commented Sep 16, 2026

Copy link
Copy Markdown
Member Author

I'd probably move DistributableToolchain::remove_components() out of DistributableToolchain into rustup_mode as a first step.

@djc I'm not sure to have fully understood your suggestion here. As it currently stands, DistributableToolchain::remove_components() is really a distributable-level abstraction that powers both rustup component remove and rustup target remove, both of which have a dispatch function in rustup_mode.rs that contains the specific validation and user-facing displaying logic (which involves converting Vec<> from clap to real component lists). That looks quite reasonable to me as the function organization pattern?

What I'm doing in the current patch is really making the underlying implementation accept multiple components at once, so that the dispatching functions don't need to call it in a loop.

If you agree with that, then in terms of argument parsing and history rewriting of course I can reevaluate my decisions.

@rami3l
rami3l force-pushed the refactor/dist-remove-mutliple-single-tx branch from 57d1d7d to d1d66a8 Compare September 16, 2026 13:53
@rustbot

This comment has been minimized.

@rami3l
rami3l force-pushed the refactor/dist-remove-mutliple-single-tx branch from d1d66a8 to 77abbd6 Compare September 16, 2026 13:54
@rami3l rami3l changed the title refactor(toolchain/distributable)!: remove multiple components at once refactor(toolchain)!: remove multiple components at once Sep 16, 2026
@rami3l
rami3l force-pushed the refactor/dist-remove-mutliple-single-tx branch from 77abbd6 to 50cdc5e Compare September 16, 2026 13:59
@rami3l

rami3l commented Sep 16, 2026

Copy link
Copy Markdown
Member Author

If we're going to pass an IntoIterator<Item = Component> into it, then it doesn't really make sense to me in terms of program flow (as opposed to performance) to allocate a Vec for it upfront, then iterate over it to check some stuff, then transform the Vec into an iterator again.

So I'd like to challenge you to rethink this code a bit more than you're currently doing.

@djc But looking back, what you have pointed out here makes a lot of sense actually. I should have tucked the allocation into the clap layer so the flow will be cleaner on our side. I'll try to do that instead.

Comment thread src/cli/rustup_mode.rs
@rami3l
rami3l force-pushed the refactor/dist-remove-mutliple-single-tx branch 3 times, most recently from 85346b2 to 9020f9b Compare September 17, 2026 09:28
@rustbot

rustbot commented Sep 17, 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.

@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.

LGTM, nice!

For the future, suggest doing the rightward drift reduction before the changes to do multi-component removal because it likely makes the latter change easier to review.

View changes since this review

Comment thread src/dist/mod.rs
@rami3l
rami3l force-pushed the refactor/dist-remove-mutliple-single-tx branch from 9020f9b to e229af3 Compare September 18, 2026 08:37
@rami3l
rami3l force-pushed the refactor/dist-remove-mutliple-single-tx branch from e229af3 to 367c94a Compare September 18, 2026 08:40
@rami3l
rami3l enabled auto-merge September 18, 2026 08:41
@rami3l
rami3l added this pull request to the merge queue Sep 18, 2026
Comment thread src/cli/rustup_mode.rs
Comment on lines +1525 to +1528
if targets.contains(&cfg.default_host_tuple()?) {
warn!(
"removing the default host target; proc-macros and build scripts might no longer build"
);

@FranciscoTGouveia FranciscoTGouveia Sep 18, 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.

Nit: Shouldn't we print this after confirming the removal succeeded? I know the phrasing is "removing" and not "removed", but still, a command like rustup target rm <host> non-existent would give the warning and fail without removing anything.

Maybe we could move this to after the actual removal?

View changes since the review

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.

Oops, I was looking into the code and did not see that this was already queued. Apologies :)

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.

Feedback is still useful!

@rami3l rami3l Sep 18, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nit: Shouldn't we print this after confirming the removal succeeded? I know the phrasing is "removing" and not "removed", but still, a command like rustup target rm <host> non-existent would give the warning and fail without removing anything.

@FranciscoTGouveia Thanks for the feedback!

I'd like to clarify that since #4797, rustup target rm <host> non-existent will cause <host> to be removed, only AFTER which the warning about non-existent will surface (same thing even if you put non-existent before <host>, if you are thinking about that), so we are quite unlikely to encounter false positives here merely due to user input. If the command execution really fails in the middle, I would still like to warn the user at first.

Merged via the queue into rust-lang:main with commit 615e345 Sep 18, 2026
32 checks passed
@rami3l
rami3l deleted the refactor/dist-remove-mutliple-single-tx branch September 18, 2026 09:29
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