about summary refs log tree commit diff
path: root/library/std/src/sys/thread_local/native/lazy.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/sys/thread_local/native/lazy.rs')
-rw-r--r--library/std/src/sys/thread_local/native/lazy.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/library/std/src/sys/thread_local/native/lazy.rs b/library/std/src/sys/thread_local/native/lazy.rs
index c5e2618e10f..2eb1c981edb 100644
--- a/library/std/src/sys/thread_local/native/lazy.rs
+++ b/library/std/src/sys/thread_local/native/lazy.rs
@@ -57,12 +57,18 @@ where
         if let State::Alive = self.state.get() {
             self.value.get().cast()
         } 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]
-    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() {
             State::Uninitialized => {}
             State::Alive => return self.value.get().cast(),