Rollup merge of #120472 - Nilstrieb:die, r=compiler-errors

Make duplicate lang items fatal

Prevents terminal spam.
This commit is contained in:
Nadrieril 2024-01-31 12:10:52 +01:00 committed by GitHub
commit 032596e34c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 64 deletions

View file

@ -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,

View file

@ -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

View file

@ -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`.

View file

@ -1,15 +0,0 @@
// normalize-stderr-test "loaded from .*libcore-.*.rlib" -> "loaded from SYSROOT/libcore-*.rlib"
#![feature(lang_items)]
#[lang="sized"]
trait Sized { } //~ ERROR found duplicate lang item `sized`
fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
//~^ ERROR `self` parameter is only allowed in associated functions
//~| ERROR cannot find type `Struct` in this scope
//~| ERROR mismatched types
let x = x << 1;
//~^ ERROR cannot find value `x` in this scope
}
fn main() {}

View file

@ -1,48 +0,0 @@
error: `self` parameter is only allowed in associated functions
--> $DIR/issue-102989.rs:7:15
|
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
| ^^^^ not semantically valid as function parameter
|
= note: associated functions are those in `impl` or `trait` definitions
error[E0412]: cannot find type `Struct` in this scope
--> $DIR/issue-102989.rs:7:22
|
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
| ^^^^^^ not found in this scope
error[E0425]: cannot find value `x` in this scope
--> $DIR/issue-102989.rs:11:13
|
LL | let x = x << 1;
| ^ help: a local variable with a similar name exists: `f`
error[E0152]: found duplicate lang item `sized`
--> $DIR/issue-102989.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 (`issue_102989`)
error[E0308]: mismatched types
--> $DIR/issue-102989.rs:7:42
|
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
| ---------- ^^^^ expected `&u32`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
help: consider returning the local binding `f`
|
LL ~ let x = x << 1;
LL + f
|
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0152, E0308, E0412, E0425.
For more information about an error, try `rustc --explain E0152`.