We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 13bce27 commit 8785f7bCopy full SHA for 8785f7b
library/std/src/sys/thread_local/native/lazy.rs
@@ -57,12 +57,18 @@ where
57
if let State::Alive = self.state.get() {
58
self.value.get().cast()
59
} else {
60
- self.get_or_init_slow(i, f)
+ unsafe { self.get_or_init_slow(i, f) }
61
}
62
63
64
+ /// # Safety
65
+ /// The `self` reference must remain valid until the TLS destructor is run.
66
#[cold]
- 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 {
72
match self.state.get() {
73
State::Uninitialized => {}
74
State::Alive => return self.value.get().cast(),
0 commit comments