rustup icon indicating copy to clipboard operation
rustup copied to clipboard

Suggest another toolchain when removing a component unavailable to the current toolchain

Open rami3l opened this issue 2 months ago • 6 comments

Similar to the case in #4164:

  1. rustup update fails (unrelated to issue) Image
  2. rustup target remove wasm32-wasi fails Image
  3. rustup +target remove wasm32-wasi succeeds, as the default toolchain was nightly as specified in .rustup/settings.toml

... however the related error kind is RustupError::UnknownComponents which would be emitted during both rustup component add and rustup component rm (instead of the rustup target rm command shown above):

https://github.com/rust-lang/rustup/blob/2919b80da905d44cc731c01add014c2eb3648aed/src/errors.rs#L141-L145

... so we should be smarter in terms of suggestions. Or, as a simplification, if suggesting rustup component add turns out to be non trivial, we can do the rustup component rm case first.

Tasks

  • The rustup component rm case: https://github.com/rust-lang/rustup/pull/5130

rami3l avatar Sep 23 '26 07:09 rami3l

i think it can be solved by intercepting the error in the removal execution path and catch the RustupError::UnknownComponents variant.

14elias avatar Sep 23 '26 10:09 14elias

I'd like to take the component rm case, following the same approach #5094 used for targets.

While testing, I noticed that removing rust-src on a toolchain that doesn't have it panics with "component target should be known".

I can fix that as a separate commit in the same PR, or open it as its own PR if you'd prefer.

devtechedge avatar Oct 06 '26 13:10 devtechedge

@devtechedge Please do! For separate concerns, it is recommended to do this in separate PRs.

rami3l avatar Oct 06 '26 14:10 rami3l

@rami3l Following #5130 could we also suggest other toolchains for rustup component add by checking locally cached manifests?

14elias avatar Oct 10 '26 08:10 14elias

@14elias Sure, if you wanna take it please do!

rami3l avatar Oct 10 '26 08:10 rami3l

@rustbot claim

14elias avatar Oct 10 '26 09:10 14elias