-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Suggest to specify a target triple when lang item is missing #91820
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a sensible change, I've left some suggestions for the wording/style but otherwise looks good.
.sess | ||
.diagnostic() | ||
.struct_err(&format!("language item required, but not found: `{}`", name)) | ||
.note(&format!("This occurs when a binary crate with `#![no_std]` is compiled for a target that usually gets `{}` from the standard library.", name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.note(&format!("This occurs when a binary crate with `#![no_std]` is compiled for a target that usually gets `{}` from the standard library.", name)) | |
.note(&format!("this can occur when a binary crate with `#![no_std]` is compiled for a target where `{}` is defined in the standard library.", name)) |
nit: wording change + lowercase diagnostic message
.struct_err(&format!("language item required, but not found: `{}`", name)) | ||
.note(&format!("This occurs when a binary crate with `#![no_std]` is compiled for a target that usually gets `{}` from the standard library.", name)) | ||
.help(&format!( | ||
r#"If you want to compile for a specific target_triple that doesnt need `{}`, then make sure to run with `--target target_triple` or add the following to the crate's `.cargo/config` file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r#"If you want to compile for a specific target_triple that doesnt need `{}`, then make sure to run with `--target target_triple` or add the following to the crate's `.cargo/config` file: | |
"you may be able to compile for a target that doesn't need `{}`, specify a target with `--target` or in `.cargo/config`" |
nit: wording
I don't know if there are other diagnostics where we reference what to do in Cargo, might be worth checking if there is precedent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I searched for other references to .cargo/config
and didnt find any.
But I did stumble across this earlier:
rust/compiler/rustc_metadata/src/locator.rs
Lines 1151 to 1156 in 2ca9333
// NOTE: this suggests using rustup, even though the user may not have it installed. | |
// That's because they could choose to install it; or this may give them a hint which | |
// target they need to install from their distro. | |
if missing_core { | |
err.help(&format!( | |
"consider downloading the target with `rustup target add {}`", |
Which references what to do in rustup.
It also makes the case that its useful even when the user doesnt have rustup because it gives a hint what you would have to do in the equivalent tool.
In this case it hints that you should probably set the target in your build system of choice.
@@ -70,7 +70,19 @@ fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) { | |||
tcx.sess.note_without_error("Use `#![feature(default_alloc_error_handler)]` for a default error handler"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tcx.sess.note_without_error("Use `#![feature(default_alloc_error_handler)]` for a default error handler"); | |
tcx.sess.note_without_error("use `#![feature(default_alloc_error_handler)]` for a default error handler"); |
pre-existing: our diagnostics are typically always lowercase, could you add a commit changing this?
018d5ae
to
fae40c5
Compare
The suggested changes are a big improvement, thanks! |
@bors r+ |
📌 Commit fae40c5 has been approved by |
… r=davidtwco Suggest to specify a target triple when lang item is missing It is very common for newbies to embedded to hit this confusing error when forgetting to specify the target. Source: me googling this error many times. ## Possible changes * We could possibly restrict the note+help to only be included on eh_personality lang item if that helped reduce false positives, but its also possible doing so would just increase false negatives * Open to any suggestions on rewriting the messages * We could possibly remove the `.cargo/config` alternative to avoid the message getting too noisy but I think its valuable to have as its the correct approach for most embedded projects so that `cargo build` just works. r? rust-lang/diagnostics
…askrgr Rollup of 7 pull requests Successful merges: - rust-lang#91529 (add BinaryHeap::try_reserve and BinaryHeap::try_reserve_exact) - rust-lang#91820 (Suggest to specify a target triple when lang item is missing) - rust-lang#91851 (Make `MaybeUninit::zeroed` `const`) - rust-lang#91875 (Use try_normalize_erasing_regions in RevealAllVisitor) - rust-lang#91887 (Remove `in_band_lifetimes` from `rustc_const_eval`) - rust-lang#91892 (Fix HashStable implementation on InferTy) - rust-lang#91893 (Remove `in_band_lifetimes` from `rustc_hir`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
It is very common for newbies to embedded to hit this confusing error when forgetting to specify the target.
Source: me googling this error many times.
Possible changes
.cargo/config
alternative to avoid the message getting too noisy but I think its valuable to have as its the correct approach for most embedded projects so thatcargo build
just works.r? rust-lang/diagnostics