]>
Commit | Line | Data |
---|---|---|
2b03887a | 1 | // ignore-wasm32 |
5869c6ff | 2 | // dont-check-compiler-stderr |
3b2f2976 XL |
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>>, | |
dc9dc135 | 10 | _flag: std::cell::Cell<()>, |
3b2f2976 XL |
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), | |
dc9dc135 | 18 | _flag: std::cell::Cell::new(()), |
3b2f2976 XL |
19 | } |
20 | } | |
21 | } | |
22 | ||
23 | #[cfg(target_thread_local)] | |
24 | use std::thread::__FastLocalKeyInner as Key; | |
25 | ||
26 | static __KEY: Key<()> = Key::new(); | |
1b1a35ee | 27 | //~^ ERROR `UnsafeCell<Option<()>>` cannot be shared between threads |
dc9dc135 | 28 | //~| ERROR cannot be shared between threads safely [E0277] |
3b2f2976 XL |
29 | |
30 | fn main() {} |