`#[unsafe(no_mangle)]` erroneously accepted inside `thread_local!`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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 https://github.com/rust-lang/rust/issues/146557#issuecomment-3294496645 for root cause
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 by compiling the provided thread_local! reproducer and inspect its macro expansion, especially how #[unsafe(no_mangle)] reaches the generated const item. Trace the attribute handling in the compiler's macro and attribute diagnostics, then verify that the example produces the expected error without changing valid thread_local! uses.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100