In other words, is this function safe?
#![feature(negative_bounds)]
use std::mem;
use std::thread::LocalKey;
pub fn get_thread_local_static_ref<T>(key: &'static LocalKey<T>) -> &'static T
where
T: !Sync,
{
key.with(|value| unsafe { mem::transmute(value) })
}
If T
is !Sync
, &T
is !Send
, so although &'static T
have static lifetime, you can only use it in the current thread.