2022-10-14 06:27:12 +00:00
|
|
|
// ignore-wasm32
|
2020-12-28 17:15:16 +00:00
|
|
|
// dont-check-compiler-stderr
|
2017-08-08 15:22:51 +00:00
|
|
|
#![feature(cfg_target_thread_local, thread_local_internals)]
|
|
|
|
|
|
|
|
// On platforms *without* `#[thread_local]`, use
|
|
|
|
// a custom non-`Sync` type to fake the same error.
|
|
|
|
#[cfg(not(target_thread_local))]
|
|
|
|
struct Key<T> {
|
|
|
|
_data: std::cell::UnsafeCell<Option<T>>,
|
2019-06-19 18:50:23 +00:00
|
|
|
_flag: std::cell::Cell<()>,
|
2017-08-08 15:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(target_thread_local))]
|
|
|
|
impl<T> Key<T> {
|
|
|
|
const fn new() -> Self {
|
|
|
|
Key {
|
|
|
|
_data: std::cell::UnsafeCell::new(None),
|
2019-06-19 18:50:23 +00:00
|
|
|
_flag: std::cell::Cell::new(()),
|
2017-08-08 15:22:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_thread_local)]
|
2023-03-10 15:35:28 +00:00
|
|
|
use std::thread::__LocalKeyInner as Key;
|
2017-08-08 15:22:51 +00:00
|
|
|
|
|
|
|
static __KEY: Key<()> = Key::new();
|
2020-09-02 07:40:56 +00:00
|
|
|
//~^ ERROR `UnsafeCell<Option<()>>` cannot be shared between threads
|
2019-06-19 18:50:23 +00:00
|
|
|
//~| ERROR cannot be shared between threads safely [E0277]
|
2017-08-08 15:22:51 +00:00
|
|
|
|
|
|
|
fn main() {}
|