rust-lang / rust-lang/rust

`thread_local!` doesn’t like types whose definitions cannot be written more than once

Open
#147,103 4 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.