We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3afadaa commit d01bd19Copy full SHA for d01bd19
library/std/src/thread/local.rs
@@ -377,10 +377,17 @@ pub mod statik {
377
}
378
379
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),
+ // 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
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
+ }
389
};
390
+
391
Some(value)
392
393
0 commit comments