Add same unsafe bound on get_or_init_slow

This commit is contained in:
Orson Peters
2025-05-28 17:09:15 +02:00
parent 13bce27e37
commit 8785f7b122

View File

@@ -57,12 +57,18 @@ where
if let State::Alive = self.state.get() { if let State::Alive = self.state.get() {
self.value.get().cast() self.value.get().cast()
} else { } else {
self.get_or_init_slow(i, f) unsafe { self.get_or_init_slow(i, f) }
} }
} }
/// # Safety
/// The `self` reference must remain valid until the TLS destructor is run.
#[cold] #[cold]
fn get_or_init_slow(&self, i: Option<&mut Option<T>>, f: impl FnOnce() -> T) -> *const T { unsafe fn get_or_init_slow(
&self,
i: Option<&mut Option<T>>,
f: impl FnOnce() -> T,
) -> *const T {
match self.state.get() { match self.state.get() {
State::Uninitialized => {} State::Uninitialized => {}
State::Alive => return self.value.get().cast(), State::Alive => return self.value.get().cast(),