Skip to content

Commit d01bd19

Browse files
committed
Fix missing unsafe block for target arch wasm32
1 parent 3afadaa commit d01bd19

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

library/std/src/thread/local.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,17 @@ pub mod statik {
377377
}
378378

379379
pub unsafe fn get(&self, init: fn() -> T) -> Option<&'static T> {
380-
let value = match self.inner.get() {
381-
Some(ref value) => value,
382-
None => self.inner.initialize(init),
380+
// SAFETY: The caller must ensure no reference is ever handed out to
381+
// the inner cell nor mutable reference to the Option<T> inside said
382+
// cell. This make it safe to hand a reference, though the lifetime
383+
// of 'static is itself unsafe, making the get method unsafe.
384+
let value = unsafe {
385+
match self.inner.get() {
386+
Some(ref value) => value,
387+
None => self.inner.initialize(init),
388+
}
383389
};
390+
384391
Some(value)
385392
}
386393
}

0 commit comments

Comments
 (0)