diff options
| author | Alexis Bourget <alexis.bourget@gmail.com> | 2020-09-21 23:08:48 +0200 |
|---|---|---|
| committer | Alexis Bourget <alexis.bourget@gmail.com> | 2020-09-21 23:09:12 +0200 |
| commit | d01bd19573a14d53a035bae704bdcdab0680a283 (patch) | |
| tree | 8def2a543a8e42bde1b0e3826188b26374ea3abb /library/std/src | |
| parent | 3afadaad4f087c86b1a8509109f544214ecad45f (diff) | |
| download | rust-d01bd19573a14d53a035bae704bdcdab0680a283.tar.gz rust-d01bd19573a14d53a035bae704bdcdab0680a283.zip | |
Fix missing unsafe block for target arch wasm32
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/thread/local.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs index cc9cad2162b..7226692fa0c 100644 --- a/library/std/src/thread/local.rs +++ b/library/std/src/thread/local.rs @@ -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) } } |
