about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorStuart Cook <Zalathar@users.noreply.github.com>2025-09-11 14:06:28 +1000
committerGitHub <noreply@github.com>2025-09-11 14:06:28 +1000
commitf38c788d84d35df675c92374efb17f8e401d653e (patch)
treeae8162fa41724b5377a82e593ee1459777dca37d /compiler
parentcc51a7efeb50752b21b4b935a02ab5bba423e8bc (diff)
parenteba09340e043262e30c80f2de12d7038389262ad (diff)
downloadrust-f38c788d84d35df675c92374efb17f8e401d653e.tar.gz
rust-f38c788d84d35df675c92374efb17f8e401d653e.zip
Rollup merge of #146347 - folkertdev:duplicate-symbol-panic, r=fee1-dead
report duplicate symbols added by the driver

The panic message did not mention what symbols were duplicates, which made the panic hard to debug. This came up in [#t-compiler/help > Easiest way to find offending duplicate symbols](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Easiest.20way.20to.20find.20offending.20duplicate.20symbols/with/538295740).

This behavior was introduced in https://github.com/rust-lang/rust/pull/138682.

r? ```@fee1-dead```
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_span/src/symbol.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index aedeb0e14ed..cdb0b5b58da 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -7,7 +7,7 @@ use std::ops::Deref;
 use std::{fmt, str};
 
 use rustc_arena::DroplessArena;
-use rustc_data_structures::fx::FxIndexSet;
+use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
 use rustc_data_structures::stable_hasher::{
     HashStable, StableCompare, StableHasher, ToStableHashKey,
 };
@@ -2871,11 +2871,20 @@ impl Interner {
         let byte_strs = FxIndexSet::from_iter(
             init.iter().copied().chain(extra.iter().copied()).map(|str| str.as_bytes()),
         );
-        assert_eq!(
-            byte_strs.len(),
-            init.len() + extra.len(),
-            "duplicate symbols in the rustc symbol list and the extra symbols added by the driver",
-        );
+
+        // The order in which duplicates are reported is irrelevant.
+        #[expect(rustc::potential_query_instability)]
+        if byte_strs.len() != init.len() + extra.len() {
+            panic!(
+                "duplicate symbols in the rustc symbol list and the extra symbols added by the driver: {:?}",
+                FxHashSet::intersection(
+                    &init.iter().copied().collect(),
+                    &extra.iter().copied().collect(),
+                )
+                .collect::<Vec<_>>()
+            )
+        }
+
         Interner(Lock::new(InternerInner { arena: Default::default(), byte_strs }))
     }