Skip to content

Commit 032596e

Browse files
authored
Rollup merge of #120472 - Nilstrieb:die, r=compiler-errors
Make duplicate lang items fatal Prevents terminal spam.
2 parents 0313eb2 + 1f89e90 commit 032596e

File tree

5 files changed

+26
-64
lines changed

5 files changed

+26
-64
lines changed

compiler/rustc_passes/src/lang_items.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
149149
}
150150
};
151151

152-
self.tcx.dcx().emit_err(DuplicateLangItem {
152+
// When there's a duplicate lang item, something went very wrong and there's no value in recovering or doing anything.
153+
// Give the user the one message to let them debug the mess they created and then wish them farewell.
154+
self.tcx.dcx().emit_fatal(DuplicateLangItem {
153155
local_span: item_span,
154156
lang_item_name,
155157
crate_name,

tests/ui/lang-items/duplicate.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// normalize-stderr-test "loaded from .*libcore-.*.rlib" -> "loaded from SYSROOT/libcore-*.rlib"
2+
#![feature(lang_items)]
3+
4+
#[lang = "sized"]
5+
trait Sized {}
6+
//~^ ERROR: duplicate lang item
7+
8+
#[lang = "tuple_trait"]
9+
pub trait Tuple {}
10+
// no error

tests/ui/lang-items/duplicate.stderr

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0152]: found duplicate lang item `sized`
2+
--> $DIR/duplicate.rs:5:1
3+
|
4+
LL | trait Sized {}
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: the lang item is first defined in crate `core` (which `std` depends on)
8+
= note: first definition in `core` loaded from SYSROOT/libcore-*.rlib
9+
= note: second definition in the local crate (`duplicate`)
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0152`.

tests/ui/traits/issue-102989.rs

-15
This file was deleted.

tests/ui/traits/issue-102989.stderr

-48
This file was deleted.

0 commit comments

Comments
 (0)