Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
david-boles opened this issue Mar 5, 2024 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@david-boles
Copy link

david-boles commented Mar 5, 2024

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

@david-boles david-boles added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 5, 2024
@david-boles david-boles changed the title Help text "consider downloading the target with `rustup target add..." only works for the default toolchain. Help text "consider downloading the target with `rustup target add..." only works for the default-active toolchain. Mar 5, 2024
@wcampbell0x2a
Copy link
Contributor

Is it possible for rustc to know what rustup toolchain it was invoked with? I only see CFG_RELEASE_CHANNEL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants