Skip to content

Commit 8785f7b

Browse files
committed
Add same unsafe bound on get_or_init_slow
1 parent 13bce27 commit 8785f7b

File tree

1 file changed

+8
-2
lines changed
  • library/std/src/sys/thread_local/native

1 file changed

+8
-2
lines changed

library/std/src/sys/thread_local/native/lazy.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,18 @@ where
5757
if let State::Alive = self.state.get() {
5858
self.value.get().cast()
5959
} else {
60-
self.get_or_init_slow(i, f)
60+
unsafe { self.get_or_init_slow(i, f) }
6161
}
6262
}
6363

64+
/// # Safety
65+
/// The `self` reference must remain valid until the TLS destructor is run.
6466
#[cold]
65-
fn get_or_init_slow(&self, i: Option<&mut Option<T>>, f: impl FnOnce() -> T) -> *const T {
67+
unsafe fn get_or_init_slow(
68+
&self,
69+
i: Option<&mut Option<T>>,
70+
f: impl FnOnce() -> T,
71+
) -> *const T {
6672
match self.state.get() {
6773
State::Uninitialized => {}
6874
State::Alive => return self.value.get().cast(),

0 commit comments

Comments
 (0)