]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/issue-43733-2.rs
Rollup merge of #69697 - GuillaumeGomez:explanation-e0380, r=Dylan-DPC
[rust.git] / src / test / compile-fail / issue-43733-2.rs
1 #![feature(cfg_target_thread_local, thread_local_internals)]
2
3 // On platforms *without* `#[thread_local]`, use
4 // a custom non-`Sync` type to fake the same error.
5 #[cfg(not(target_thread_local))]
6 struct Key<T> {
7     _data: std::cell::UnsafeCell<Option<T>>,
8     _flag: std::cell::Cell<()>,
9 }
10
11 #[cfg(not(target_thread_local))]
12 impl<T> Key<T> {
13     const fn new() -> Self {
14         Key {
15             _data: std::cell::UnsafeCell::new(None),
16             _flag: std::cell::Cell::new(()),
17         }
18     }
19 }
20
21 #[cfg(target_thread_local)]
22 use std::thread::__FastLocalKeyInner as Key;
23
24 static __KEY: Key<()> = Key::new();
25 //~^ ERROR `std::cell::UnsafeCell<std::option::Option<()>>` cannot be shared between threads
26 //~| ERROR cannot be shared between threads safely [E0277]
27
28 fn main() {}