Skip to content

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

@Jules-Bertholet

Description

@Jules-Bertholet

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-thread-localsArea: Thread local storage (TLS)C-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions