Skip to content

Commit

Permalink
Fix missing unsafe block for target arch wasm32
Browse files Browse the repository at this point in the history
  • Loading branch information
poliorcetics committed Sep 21, 2020
1 parent 3afadaa commit d01bd19
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions library/std/src/thread/local.rs
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit d01bd19

Please sign in to comment.