]> git.lizzy.rs Git - rust.git/blob - tests/ui/threads-sendsync/issue-43733-2.rs
Rollup merge of #106670 - albertlarsan68:check-docs-in-pr-ci, r=Mark-Simulacrum
[rust.git] / tests / ui / threads-sendsync / issue-43733-2.rs
1 // ignore-wasm32
2 // dont-check-compiler-stderr
3 #![feature(cfg_target_thread_local, thread_local_internals)]
4
5 // On platforms *without* `#[thread_local]`, use
6 // a custom non-`Sync` type to fake the same error.
7 #[cfg(not(target_thread_local))]
8 struct Key<T> {
9     _data: std::cell::UnsafeCell<Option<T>>,
10     _flag: std::cell::Cell<()>,
11 }
12
13 #[cfg(not(target_thread_local))]
14 impl<T> Key<T> {
15     const fn new() -> Self {
16         Key {
17             _data: std::cell::UnsafeCell::new(None),
18             _flag: std::cell::Cell::new(()),
19         }
20     }
21 }
22
23 #[cfg(target_thread_local)]
24 use std::thread::__FastLocalKeyInner as Key;
25
26 static __KEY: Key<()> = Key::new();
27 //~^ ERROR `UnsafeCell<Option<()>>` cannot be shared between threads
28 //~| ERROR cannot be shared between threads safely [E0277]
29
30 fn main() {}