]> git.lizzy.rs Git - rust.git/blob - src/test/ui/threads-sendsync/issue-43733.rs
Rollup merge of #98640 - cuviper:stable-rust-analyzer, r=Mark-Simulacrum
[rust.git] / src / test / ui / threads-sendsync / issue-43733.rs
1 // revisions: mir thir
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"
5
6 #![feature(thread_local)]
7 #![feature(cfg_target_thread_local, thread_local_internals)]
8
9 use std::cell::RefCell;
10
11 type Foo = std::cell::RefCell<String>;
12
13 #[cfg(target_thread_local)]
14 #[thread_local]
15 static __KEY: std::thread::__FastLocalKeyInner<Foo> = std::thread::__FastLocalKeyInner::new();
16
17 #[cfg(not(target_thread_local))]
18 static __KEY: std::thread::__OsLocalKeyInner<Foo> = std::thread::__OsLocalKeyInner::new();
19
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 `__
24 }
25
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`
29
30 fn main() {
31     FOO.with(|foo| println!("{}", foo.borrow()));
32     std::thread::spawn(|| {
33         FOO.with(|foo| *foo.borrow_mut() += "foo");
34     })
35     .join()
36     .unwrap();
37     FOO.with(|foo| println!("{}", foo.borrow()));
38 }