2022-10-14 06:27:12 +00:00
|
|
|
// ignore-wasm32
|
2021-03-14 19:11:37 +00:00
|
|
|
// revisions: mir thir
|
|
|
|
// [thir]compile-flags: -Z thir-unsafeck
|
2023-03-10 15:35:28 +00:00
|
|
|
// normalize-stderr-test: "__LocalKeyInner::<T>::get" -> "$$LOCALKEYINNER::<T>::get"
|
|
|
|
// normalize-stderr-test: "__LocalKeyInner::<T>::get" -> "$$LOCALKEYINNER::<T>::get"
|
2017-09-24 10:15:18 +00:00
|
|
|
#![feature(thread_local)]
|
2017-08-08 15:22:51 +00:00
|
|
|
#![feature(cfg_target_thread_local, thread_local_internals)]
|
|
|
|
|
2021-12-20 18:24:40 +00:00
|
|
|
use std::cell::RefCell;
|
|
|
|
|
2017-08-08 15:22:51 +00:00
|
|
|
type Foo = std::cell::RefCell<String>;
|
|
|
|
|
|
|
|
#[cfg(target_thread_local)]
|
2017-09-24 10:15:18 +00:00
|
|
|
#[thread_local]
|
2023-03-10 15:35:28 +00:00
|
|
|
static __KEY: std::thread::__LocalKeyInner<Foo> = std::thread::__LocalKeyInner::new();
|
2017-08-08 15:22:51 +00:00
|
|
|
|
|
|
|
#[cfg(not(target_thread_local))]
|
2023-03-10 15:35:28 +00:00
|
|
|
static __KEY: std::thread::__LocalKeyInner<Foo> = std::thread::__LocalKeyInner::new();
|
2017-08-08 15:22:51 +00:00
|
|
|
|
2021-12-20 18:24:40 +00:00
|
|
|
fn __getit(_: Option<&mut Option<RefCell<String>>>) -> std::option::Option<&'static Foo> {
|
2022-04-24 12:08:23 +00:00
|
|
|
__KEY.get(Default::default)
|
2022-04-26 10:43:00 +00:00
|
|
|
//[mir]~^ ERROR call to unsafe function is unsafe
|
2022-04-24 17:03:59 +00:00
|
|
|
//[thir]~^^ ERROR call to unsafe function `__
|
2017-08-08 15:22:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-14 19:11:37 +00:00
|
|
|
static FOO: std::thread::LocalKey<Foo> = std::thread::LocalKey::new(__getit);
|
2022-04-26 10:43:00 +00:00
|
|
|
//[mir]~^ ERROR call to unsafe function is unsafe
|
|
|
|
//[thir]~^^ ERROR call to unsafe function `LocalKey::<T>::new`
|
2017-08-08 15:22:51 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
FOO.with(|foo| println!("{}", foo.borrow()));
|
|
|
|
std::thread::spawn(|| {
|
|
|
|
FOO.with(|foo| *foo.borrow_mut() += "foo");
|
2021-03-14 19:11:37 +00:00
|
|
|
})
|
|
|
|
.join()
|
|
|
|
.unwrap();
|
2017-08-08 15:22:51 +00:00
|
|
|
FOO.with(|foo| println!("{}", foo.borrow()));
|
|
|
|
}
|