about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2024-01-29 20:03:14 +0100
committerNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2024-01-29 20:03:14 +0100
commitad1e6298ed785ad0d327231725db501be00f14c5 (patch)
tree775ade521f90ce9bd4f48fb3c617a4d15aeec76d
parent88189a71e4e4376eea82ac61db6a539612eb200a (diff)
downloadrust-ad1e6298ed785ad0d327231725db501be00f14c5.tar.gz
rust-ad1e6298ed785ad0d327231725db501be00f14c5.zip
Make duplicate lang items fatal
Prevents terminal spam.
-rw-r--r--compiler/rustc_passes/src/lang_items.rs4
-rw-r--r--tests/ui/traits/issue-102989.rs1
-rw-r--r--tests/ui/traits/issue-102989.stderr20
3 files changed, 6 insertions, 19 deletions
diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs
index 6aeaa8945fb..9a21397789d 100644
--- a/compiler/rustc_passes/src/lang_items.rs
+++ b/compiler/rustc_passes/src/lang_items.rs
@@ -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,
diff --git a/tests/ui/traits/issue-102989.rs b/tests/ui/traits/issue-102989.rs
index f1ecee0a552..216cd78e56f 100644
--- a/tests/ui/traits/issue-102989.rs
+++ b/tests/ui/traits/issue-102989.rs
@@ -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
 }
diff --git a/tests/ui/traits/issue-102989.stderr b/tests/ui/traits/issue-102989.stderr
index 40e49df2b2d..e17df556d8d 100644
--- a/tests/ui/traits/issue-102989.stderr
+++ b/tests/ui/traits/issue-102989.stderr
@@ -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`
@@ -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`.