rust-lang / rust-lang/rust

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

Open
#122,006 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the diagnostic in compiler/rustc_metadata/messages.ftl at lines 34-35, then reproduce the reported cargo build with a non-default toolchain and target. Update the help text so it identifies the toolchain being used and its target-install command, and verify the diagnostic output covers this mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.