Closed
Description
#![forbid(unsafe_op_in_unsafe_fn)]
use std::cell::Cell;
thread_local! {
pub static FOO: Cell<u32> = const { Cell::new(1) };
}
I expected to see this happen: Compiles without error.
Instead, this happened: Fails to build with this error:
error[E0453]: deny(unsafe_op_in_unsafe_fn) incompatible with previous forbid
--> src/lib.rs:5:1
|
1 | #![forbid(unsafe_op_in_unsafe_fn)]
| ---------------------- `forbid` level set here
...
5 | / thread_local! {
6 | | pub static FOO: Cell<u32> = const { Cell::new(1) };
7 | | }
| |_^ overruled by previous forbid
|
= note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0453`.
It seems https://github.com/rust-lang/rust/blob/master/library/std/src/sys/pal/common/thread_local/os_local.rs is using #[deny(unsafe_op_in_unsafe_fn)]
. But the existence of forbid
makes somewhat problematic in a macro.
Meta
Occurs on rustc 1.76.0 (07dca489a 2024-02-04)
and rustc 1.78.0-nightly (3406ada96 2024-02-21)
.
Metadata
Metadata
Assignees
Labels
Area: Lints (warnings about flaws in source code) such as unused_mut.Category: This is a bug.Lint: unsafe_op_in_unsafe_fnStatus: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.