]> git.lizzy.rs Git - rust.git/blob - src/test/ui/threads-sendsync/issue-43733.rs
Auto merge of #94515 - estebank:tweak-move-error, r=davidtwco
[rust.git] / src / test / ui / threads-sendsync / issue-43733.rs
1 // revisions: mir thir
2 // [thir]compile-flags: -Z thir-unsafeck
3
4 #![feature(thread_local)]
5 #![feature(cfg_target_thread_local, thread_local_internals)]
6
7 use std::cell::RefCell;
8
9 type Foo = std::cell::RefCell<String>;
10
11 #[cfg(target_thread_local)]
12 #[thread_local]
13 static __KEY: std::thread::__FastLocalKeyInner<Foo> = std::thread::__FastLocalKeyInner::new();
14
15 #[cfg(not(target_thread_local))]
16 static __KEY: std::thread::__OsLocalKeyInner<Foo> = std::thread::__OsLocalKeyInner::new();
17
18 fn __getit(_: Option<&mut Option<RefCell<String>>>) -> std::option::Option<&'static Foo> {
19     __KEY.get(Default::default) //~ ERROR call to unsafe function is unsafe
20 }
21
22 static FOO: std::thread::LocalKey<Foo> = 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     })
30     .join()
31     .unwrap();
32     FOO.with(|foo| println!("{}", foo.borrow()));
33 }