Skip to content

Commit ad1e629

Browse files
committed
Make duplicate lang items fatal
Prevents terminal spam.
1 parent 88189a7 commit ad1e629

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
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/traits/issue-102989.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ trait Sized { } //~ ERROR found duplicate lang item `sized`
77
fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
88
//~^ ERROR `self` parameter is only allowed in associated functions
99
//~| ERROR cannot find type `Struct` in this scope
10-
//~| ERROR mismatched types
1110
let x = x << 1;
1211
//~^ ERROR cannot find value `x` in this scope
1312
}

tests/ui/traits/issue-102989.stderr

+3-17
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
1313
| ^^^^^^ not found in this scope
1414

1515
error[E0425]: cannot find value `x` in this scope
16-
--> $DIR/issue-102989.rs:11:13
16+
--> $DIR/issue-102989.rs:10:13
1717
|
1818
LL | let x = x << 1;
1919
| ^ help: a local variable with a similar name exists: `f`
@@ -28,21 +28,7 @@ LL | trait Sized { }
2828
= note: first definition in `core` loaded from SYSROOT/libcore-*.rlib
2929
= note: second definition in the local crate (`issue_102989`)
3030

31-
error[E0308]: mismatched types
32-
--> $DIR/issue-102989.rs:7:42
33-
|
34-
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
35-
| ---------- ^^^^ expected `&u32`, found `()`
36-
| |
37-
| implicitly returns `()` as its body has no tail or `return` expression
38-
|
39-
help: consider returning the local binding `f`
40-
|
41-
LL ~ let x = x << 1;
42-
LL + f
43-
|
44-
45-
error: aborting due to 5 previous errors
31+
error: aborting due to 4 previous errors
4632

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

0 commit comments

Comments
 (0)