2022-10-14 01:27:12 -05:00
|
|
|
// ignore-wasm32
|
2021-03-14 14:11:37 -05:00
|
|
|
// revisions: mir thir
|
|
|
|
// [thir]compile-flags: -Z thir-unsafeck
|
2017-09-24 05:15:18 -05:00
|
|
|
#![feature(thread_local)]
|
2017-08-08 10:22:51 -05:00
|
|
|
#![feature(cfg_target_thread_local, thread_local_internals)]
|
|
|
|
|
2021-12-20 12:24:40 -06:00
|
|
|
use std::cell::RefCell;
|
|
|
|
|
2017-08-08 10:22:51 -05:00
|
|
|
type Foo = std::cell::RefCell<String>;
|
|
|
|
|
|
|
|
#[cfg(target_thread_local)]
|
2017-09-24 05:15:18 -05:00
|
|
|
#[thread_local]
|
2023-04-26 14:02:56 -05:00
|
|
|
static __KEY: std::thread::local_impl::Key<Foo> = std::thread::local_impl::Key::new();
|
2017-08-08 10:22:51 -05:00
|
|
|
|
|
|
|
#[cfg(not(target_thread_local))]
|
2023-04-26 14:02:56 -05:00
|
|
|
static __KEY: std::thread::local_impl::Key<Foo> = std::thread::local_impl::Key::new();
|
2017-08-08 10:22:51 -05:00
|
|
|
|
2021-12-20 12:24:40 -06:00
|
|
|
fn __getit(_: Option<&mut Option<RefCell<String>>>) -> std::option::Option<&'static Foo> {
|
2022-04-24 07:08:23 -05:00
|
|
|
__KEY.get(Default::default)
|
2022-04-26 05:43:00 -05:00
|
|
|
//[mir]~^ ERROR call to unsafe function is unsafe
|
2023-04-26 14:02:56 -05:00
|
|
|
//[thir]~^^ ERROR call to unsafe function `Key::<T>::get`
|
2017-08-08 10:22:51 -05:00
|
|
|
}
|
|
|
|
|
2021-03-14 14:11:37 -05:00
|
|
|
static FOO: std::thread::LocalKey<Foo> = std::thread::LocalKey::new(__getit);
|
2022-04-26 05:43:00 -05:00
|
|
|
//[mir]~^ ERROR call to unsafe function is unsafe
|
|
|
|
//[thir]~^^ ERROR call to unsafe function `LocalKey::<T>::new`
|
2017-08-08 10:22:51 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
FOO.with(|foo| println!("{}", foo.borrow()));
|
|
|
|
std::thread::spawn(|| {
|
|
|
|
FOO.with(|foo| *foo.borrow_mut() += "foo");
|
2021-03-14 14:11:37 -05:00
|
|
|
})
|
|
|
|
.join()
|
|
|
|
.unwrap();
|
2017-08-08 10:22:51 -05:00
|
|
|
FOO.with(|foo| println!("{}", foo.borrow()));
|
|
|
|
}
|