]> git.proxmox.com Git - rustc.git/blame - src/test/ui/threads-sendsync/issue-43733.rs
New upstream version 1.54.0+dfsg1
[rustc.git] / src / test / ui / threads-sendsync / issue-43733.rs
CommitLineData
17df50a5
XL
1// revisions: mir thir
2// [thir]compile-flags: -Z thir-unsafeck
3
ea8adc8c 4#![feature(thread_local)]
3b2f2976
XL
5#![feature(cfg_target_thread_local, thread_local_internals)]
6
7type Foo = std::cell::RefCell<String>;
8
9#[cfg(target_thread_local)]
ea8adc8c 10#[thread_local]
17df50a5 11static __KEY: std::thread::__FastLocalKeyInner<Foo> = std::thread::__FastLocalKeyInner::new();
3b2f2976
XL
12
13#[cfg(not(target_thread_local))]
17df50a5 14static __KEY: std::thread::__OsLocalKeyInner<Foo> = std::thread::__OsLocalKeyInner::new();
3b2f2976 15
17df50a5 16fn __getit() -> std::option::Option<&'static Foo> {
dc9dc135 17 __KEY.get(Default::default) //~ ERROR call to unsafe function is unsafe
3b2f2976
XL
18}
19
17df50a5 20static FOO: std::thread::LocalKey<Foo> = std::thread::LocalKey::new(__getit);
8faf50e0 21//~^ ERROR call to unsafe function is unsafe
3b2f2976
XL
22
23fn main() {
24 FOO.with(|foo| println!("{}", foo.borrow()));
25 std::thread::spawn(|| {
26 FOO.with(|foo| *foo.borrow_mut() += "foo");
17df50a5
XL
27 })
28 .join()
29 .unwrap();
3b2f2976
XL
30 FOO.with(|foo| println!("{}", foo.borrow()));
31}