about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorAlexis Bourget <alexis.bourget@gmail.com>2020-09-21 23:08:48 +0200
committerAlexis Bourget <alexis.bourget@gmail.com>2020-09-21 23:09:12 +0200
commitd01bd19573a14d53a035bae704bdcdab0680a283 (patch)
tree8def2a543a8e42bde1b0e3826188b26374ea3abb /library/std/src
parent3afadaad4f087c86b1a8509109f544214ecad45f (diff)
downloadrust-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.rs13
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)
         }
     }