Skip to content

Commit fae40c5

Browse files
committed
Suggest to specify a target triple when eh_personality lang item is missing
1 parent 6d6d089 commit fae40c5

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

compiler/rustc_passes/src/weak_lang_items.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,16 @@ fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) {
6767
} else if item == LangItem::Oom {
6868
if !tcx.features().default_alloc_error_handler {
6969
tcx.sess.err("`#[alloc_error_handler]` function required, but not found");
70-
tcx.sess.note_without_error("Use `#![feature(default_alloc_error_handler)]` for a default error handler");
70+
tcx.sess.note_without_error("use `#![feature(default_alloc_error_handler)]` for a default error handler");
7171
}
7272
} else {
73-
tcx.sess.err(&format!("language item required, but not found: `{}`", name));
73+
tcx
74+
.sess
75+
.diagnostic()
76+
.struct_err(&format!("language item required, but not found: `{}`", name))
77+
.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))
78+
.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))
79+
.emit();
7480
}
7581
}
7682
}

src/test/ui/extern-flag/empty-extern-arg.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
error: extern location for std does not exist:
22

33
error: language item required, but not found: `eh_personality`
4+
|
5+
= 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
6+
= 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`
47

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

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
error: `#[alloc_error_handler]` function required, but not found
22

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

55
error: aborting due to previous error
66

src/test/ui/panic-handler/weak-lang-item.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ LL | extern crate core as other_core;
1111
|
1212

1313
error: language item required, but not found: `eh_personality`
14+
|
15+
= 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
16+
= 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`
1417

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

0 commit comments

Comments
 (0)