Skip to content

#[unsafe(no_mangle)] erroneously accepted inside thread_local! #146557

Description

@Jules-Bertholet

I tried this code:

thread_local! {
    #[unsafe(no_mangle)]
    static FOO: () = const { () };
}

I expected to see this happen:

error: const items should never be `#[no_mangle]`

(The macro expands to a const item that has the #[unsafe(no_mangle)] applied to it.)

Instead, this happened:

It compiled successfully. The attribute is ignored

Meta

rustc --version --verbose:

rustc 1.91.0-nightly (02c7b1a7a 2025-09-13)
binary: rustc
commit-hash: 02c7b1a7ac1d739663878030510508372e46f254
commit-date: 2025-09-13
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.1

@rustbot label A-attributes A-macros T-compiler

Edit: see #146557 (comment) for root cause

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions