Skip to content

Improve error message for rustup target add invalid-target #3318

@jyn514

Description

@jyn514

Problem you are trying to solve

Consider this error:

; rustup target add wasm
error: toolchain 'nightly-x86_64-unknown-linux-gnu' does not contain component 'rust-std' for target 'wasm'
note: not all platforms have the standard library pre-compiled: https://doc.rust-lang.org/nightly/rustc/platform-support.html
help: consider using `cargo build -Z build-std` instead

The pointer to platform-support.html is good and helpful, but the rest of these messages are a bit misleading. The problem is that wasm isn't a target, I need to pick a specific version of wasm:

; rustc --print=target-list | grep wasm
wasm32-unknown-emscripten
wasm32-unknown-unknown
wasm32-wasi
wasm64-unknown-unknown

Solution you'd like

Have rustup check the output of rustc --print=target-list for the specified toolchain and give a more helpful error if it doesn't have the target. Maybe something like this:

; rustup target add wasm
error: toolchain 'nightly-x86_64-unknown-linux-gnu' does not support target 'wasm'
note: you can see a list of supported targets with `rustc --print=target-list`
note: if you are adding support for a new target to rustc itself, see https://rustc-dev-guide.rust-lang.org/building/new-target.html

Notes

No response

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions