2 // [thir]compile-flags: -Z thir-unsafeck
3 // normalize-stderr-test: "__FastLocalKeyInner::<T>::get" -> "$$LOCALKEYINNER::<T>::get"
4 // normalize-stderr-test: "__OsLocalKeyInner::<T>::get" -> "$$LOCALKEYINNER::<T>::get"
6 #![feature(thread_local)]
7 #![feature(cfg_target_thread_local, thread_local_internals)]
9 use std::cell::RefCell;
11 type Foo = std::cell::RefCell<String>;
13 #[cfg(target_thread_local)]
15 static __KEY: std::thread::__FastLocalKeyInner<Foo> = std::thread::__FastLocalKeyInner::new();
17 #[cfg(not(target_thread_local))]
18 static __KEY: std::thread::__OsLocalKeyInner<Foo> = std::thread::__OsLocalKeyInner::new();
20 fn __getit(_: Option<&mut Option<RefCell<String>>>) -> std::option::Option<&'static Foo> {
21 __KEY.get(Default::default)
22 //[mir]~^ ERROR call to unsafe function is unsafe
23 //[thir]~^^ ERROR call to unsafe function `__
26 static FOO: std::thread::LocalKey<Foo> = std::thread::LocalKey::new(__getit);
27 //[mir]~^ ERROR call to unsafe function is unsafe
28 //[thir]~^^ ERROR call to unsafe function `LocalKey::<T>::new`
31 FOO.with(|foo| println!("{}", foo.borrow()));
32 std::thread::spawn(|| {
33 FOO.with(|foo| *foo.borrow_mut() += "foo");
37 FOO.with(|foo| println!("{}", foo.borrow()));