Skip to content

Commit

Permalink
Rollup merge of rust-lang#91820 - rukai:help_with_personality_issues,…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
matthiaskrgr authored Dec 14, 2021
2 parents 0a98071 + fae40c5 commit 8309cb2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions compiler/rustc_passes/src/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) {
} else if item == LangItem::Oom {
if !tcx.features().default_alloc_error_handler {
tcx.sess.err("`#[alloc_error_handler]` function required, but not found");
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");
}
} else {
tcx.sess.err(&format!("language item required, but not found: `{}`", name));
tcx
.sess
.diagnostic()
.struct_err(&format!("language item required, but not found: `{}`", 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))
.help(&format!("you may be able to compile for a target that doesn't need `{}`, specify a target with `--target` or in `.cargo/config`", name))
.emit();
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/extern-flag/empty-extern-arg.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
error: extern location for std does not exist:

error: language item required, but not found: `eh_personality`
|
= note: this can occur when a binary crate with `#![no_std]` is compiled for a target where `eh_personality` is defined in the standard library
= help: you may be able to compile for a target that doesn't need `eh_personality`, specify a target with `--target` or in `.cargo/config`

error: `#[panic_handler]` function required, but not found

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/missing/missing-alloc_error_handler.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
error: `#[alloc_error_handler]` function required, but not found

note: Use `#![feature(default_alloc_error_handler)]` for a default error handler
note: use `#![feature(default_alloc_error_handler)]` for a default error handler

error: aborting due to previous error

3 changes: 3 additions & 0 deletions src/test/ui/panic-handler/weak-lang-item.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ LL | extern crate core as other_core;
|

error: language item required, but not found: `eh_personality`
|
= note: this can occur when a binary crate with `#![no_std]` is compiled for a target where `eh_personality` is defined in the standard library
= help: you may be able to compile for a target that doesn't need `eh_personality`, specify a target with `--target` or in `.cargo/config`

error: `#[panic_handler]` function required, but not found

Expand Down

0 comments on commit 8309cb2

Please sign in to comment.