Skip to content

Commit

Permalink
Make duplicate lang items fatal
Browse files Browse the repository at this point in the history
Prevents terminal spam.
  • Loading branch information
Noratrieb committed Jan 29, 2024
1 parent 88189a7 commit ad1e629
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 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
1 change: 0 additions & 1 deletion tests/ui/traits/issue-102989.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ 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
}
Expand Down
20 changes: 3 additions & 17 deletions tests/ui/traits/issue-102989.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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
--> $DIR/issue-102989.rs:10:13
|
LL | let x = x << 1;
| ^ help: a local variable with a similar name exists: `f`
Expand All @@ -28,21 +28,7 @@ LL | trait Sized { }
= 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
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0152, E0308, E0412, E0425.
Some errors have detailed explanations: E0152, E0412, E0425.
For more information about an error, try `rustc --explain E0152`.

0 comments on commit ad1e629

Please sign in to comment.