Skip to content

Commit

Permalink
Rollup merge of rust-lang#120472 - Nilstrieb:die, r=compiler-errors
Browse files Browse the repository at this point in the history
Make duplicate lang items fatal

Prevents terminal spam.
  • Loading branch information
Nadrieril authored Jan 31, 2024
2 parents f4c8ab5 + 1f89e90 commit 1187855
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 64 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_passes/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
}
};

self.tcx.dcx().emit_err(DuplicateLangItem {
// When there's a duplicate lang item, something went very wrong and there's no value in recovering or doing anything.
// Give the user the one message to let them debug the mess they created and then wish them farewell.
self.tcx.dcx().emit_fatal(DuplicateLangItem {
local_span: item_span,
lang_item_name,
crate_name,
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/lang-items/duplicate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// normalize-stderr-test "loaded from .*libcore-.*.rlib" -> "loaded from SYSROOT/libcore-*.rlib"
#![feature(lang_items)]

#[lang = "sized"]
trait Sized {}
//~^ ERROR: duplicate lang item

#[lang = "tuple_trait"]
pub trait Tuple {}
// no error
13 changes: 13 additions & 0 deletions tests/ui/lang-items/duplicate.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0152]: found duplicate lang item `sized`
--> $DIR/duplicate.rs:5:1
|
LL | trait Sized {}
| ^^^^^^^^^^^^^^
|
= note: the lang item is first defined in crate `core` (which `std` depends on)
= note: first definition in `core` loaded from SYSROOT/libcore-*.rlib
= note: second definition in the local crate (`duplicate`)

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0152`.
15 changes: 0 additions & 15 deletions tests/ui/traits/issue-102989.rs

This file was deleted.

48 changes: 0 additions & 48 deletions tests/ui/traits/issue-102989.stderr

This file was deleted.

0 comments on commit 1187855

Please sign in to comment.