2 #![feature(thread_local)]
3 #![feature(cfg_target_thread_local, thread_local_internals)]
5 type Foo = std::cell::RefCell<String>;
7 #[cfg(target_thread_local)]
9 static __KEY: std::thread::__FastLocalKeyInner<Foo> =
10 std::thread::__FastLocalKeyInner::new();
12 #[cfg(not(target_thread_local))]
13 static __KEY: std::thread::__OsLocalKeyInner<Foo> =
14 std::thread::__OsLocalKeyInner::new();
16 fn __getit() -> std::option::Option<&'static Foo>
18 __KEY.get(Default::default) //~ ERROR call to unsafe function is unsafe
21 static FOO: std::thread::LocalKey<Foo> =
22 std::thread::LocalKey::new(__getit);
23 //~^ ERROR call to unsafe function is unsafe
26 FOO.with(|foo| println!("{}", foo.borrow()));
27 std::thread::spawn(|| {
28 FOO.with(|foo| *foo.borrow_mut() += "foo");
30 FOO.with(|foo| println!("{}", foo.borrow()));