2 // dont-check-compiler-stderr
3 #![feature(cfg_target_thread_local, thread_local_internals)]
5 // On platforms *without* `#[thread_local]`, use
6 // a custom non-`Sync` type to fake the same error.
7 #[cfg(not(target_thread_local))]
9 _data: std::cell::UnsafeCell<Option<T>>,
10 _flag: std::cell::Cell<()>,
13 #[cfg(not(target_thread_local))]
15 const fn new() -> Self {
17 _data: std::cell::UnsafeCell::new(None),
18 _flag: std::cell::Cell::new(()),
23 #[cfg(target_thread_local)]
24 use std::thread::__FastLocalKeyInner as Key;
26 static __KEY: Key<()> = Key::new();
27 //~^ ERROR `UnsafeCell<Option<()>>` cannot be shared between threads
28 //~| ERROR cannot be shared between threads safely [E0277]