`thread_local!` doesn’t like types whose definitions cannot be written more than once
Open
Nobody has claimed this yet.
A-const-generics
A-macros
A-thread-locals
C-bug
T-libs
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this (admittedly cursed) code:
thread_local! {
pub static FOO: [(); {
#[unsafe(no_mangle)]
fn dont_duplicate_me() {}
0
}] = [];
}
I expected to see this happen: It compiles, just like the non-thread_local! version would
Instead, this happened:
error: symbol `dont_duplicate_me` is already defined
--> src/lib.rs:4:9
|
4 | fn dont_duplicate_me() {}
| ^^^^^^^^^^^^^^^^^^^^^^
Meta
rustc --version:
1.92.0-nightly (2025-09-26 54a8a1db604e4caff93e)
@rustbot label T-libs A-macros A-thread-locals A-const-generics
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the src/lib.rs reproducer using thread_local! and the nested dont_duplicate_me function, then compare it with the equivalent non-thread_local! version. Trace how the thread_local! macro handles the const-generic type and confirm that the corrected behavior compiles without the duplicate-symbol error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100