]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-43733.rs
Rollup merge of #62337 - Mark-Simulacrum:fix-cpu-usage-script, r=alexcrichton
[rust.git] / src / test / ui / issues / issue-43733.rs
1 #![feature(const_fn)]
2 #![feature(thread_local)]
3 #![feature(cfg_target_thread_local, thread_local_internals)]
4
5 type Foo = std::cell::RefCell<String>;
6
7 #[cfg(target_thread_local)]
8 #[thread_local]
9 static __KEY: std::thread::__FastLocalKeyInner<Foo> =
10     std::thread::__FastLocalKeyInner::new();
11
12 #[cfg(not(target_thread_local))]
13 static __KEY: std::thread::__OsLocalKeyInner<Foo> =
14     std::thread::__OsLocalKeyInner::new();
15
16 fn __getit() -> std::option::Option<&'static Foo>
17 {
18     __KEY.get(Default::default) //~ ERROR call to unsafe function is unsafe
19 }
20
21 static FOO: std::thread::LocalKey<Foo> =
22     std::thread::LocalKey::new(__getit);
23 //~^ ERROR call to unsafe function is unsafe
24
25 fn main() {
26     FOO.with(|foo| println!("{}", foo.borrow()));
27     std::thread::spawn(|| {
28         FOO.with(|foo| *foo.borrow_mut() += "foo");
29     }).join().unwrap();
30     FOO.with(|foo| println!("{}", foo.borrow()));
31 }