Skip to content

Help text "consider downloading the target with `rustup target add..." only works for the default-active toolchain. #122006

Open
@david-boles

Description

@david-boles

Code

fn main() {
    println!("Hello, world!");
}

Current output

$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/deb/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu (default)
1.70.0-x86_64-unknown-linux-gnu

...

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.75.0 (82e1608df 2023-12-21)

$ rustup target add x86_64-unknown-linux-musl
info: component 'rust-std' for target 'x86_64-unknown-linux-musl' is up to date
$ cargo +1.70.0 build --target x86_64-unknown-linux-musl
   Compiling temp v0.1.0 (/home/deb/Temp/temp)
error[E0463]: can't find crate for `std`
  |
  = note: the `x86_64-unknown-linux-musl` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-unknown-linux-musl`

error: cannot find macro `println` in this scope
 --> src/main.rs:2:5
  |
2 |     println!("Hello, world!");
  |     ^^^^^^^

error: requires `sized` lang_item

For more information about this error, try `rustc --explain E0463`.
error: could not compile `temp` (bin "temp") due to 3 previous errors

Desired output

$ cargo +1.70.0 build --target x86_64-unknown-linux-musl
   Compiling temp v0.1.0 (/home/deb/Temp/temp)
error[E0463]: can't find crate for `std`
  |
  = note: the `x86_64-unknown-linux-musl` target may not be installed for this toolchain
  = help: consider downloading the target with `rustup target install --toolchain 1.70.0 x86_64-unknown-linux-musl

Rationale and extra context

Might be a bit of an edge-case but I ran into this twice in a couple of months; it would be nice if the error message gave you the command to install it specifically for the toolchain being used. The first time I was manually specifying nightly when building wasm and the second I wasn't in my project's folder with a rust-toolchain file when I ran rustup target add x86_64-unknown-linux-musl (it seems like rustup uses the toolchain of your project; nice!).

Also relevant is #97685.

Other cases

No response

Rust Version

rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2

Looks the same on master: https://github.com/rust-lang/rust/blob/50e77f133f8eb1f745e05681163a0143d6c4dd7d/compiler/rustc_metadata/messages.ftl#L34-L35

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions