Fix missing unsafe block for target arch wasm32

This commit is contained in:
Alexis Bourget 2020-09-21 23:08:48 +02:00
parent 3afadaad4f
commit d01bd19573
1 changed files with 10 additions and 3 deletions

View File

@ -377,10 +377,17 @@ pub mod statik {
}
pub unsafe fn get(&self, init: fn() -> T) -> Option<&'static T> {
let value = match self.inner.get() {
Some(ref value) => value,
None => self.inner.initialize(init),
// SAFETY: The caller must ensure no reference is ever handed out to
// the inner cell nor mutable reference to the Option<T> inside said
// cell. This make it safe to hand a reference, though the lifetime
// of 'static is itself unsafe, making the get method unsafe.
let value = unsafe {
match self.inner.get() {
Some(ref value) => value,
None => self.inner.initialize(init),
}
};
Some(value)
}
}