We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9e6c4fd commit 538ddb0Copy full SHA for 538ddb0
library/std/src/sys/thread_local/mod.rs
@@ -91,13 +91,15 @@ mod lazy {
91
}
92
93
94
- /// The other methods hand out references while taking &self.
95
- /// As such, callers of this method must ensure no `&` and `&mut` are
96
- /// available and used at the same time.
+ /// Watch out: unsynchronized internal mutability!
+ ///
+ /// # Safety
97
+ /// Unsound if called while any `&'static T` is active.
98
#[allow(unused)]
- pub unsafe fn take(&mut self) -> Option<T> {
99
- // SAFETY: See doc comment for this method.
100
- unsafe { (*self.inner.get()).take() }
+ pub(crate) unsafe fn take(&self) -> Option<T> {
+ let mutable: *mut _ = UnsafeCell::get(&self.inner);
101
+ // SAFETY: That's the caller's problem.
102
+ unsafe { mutable.replace(None) }
103
104
105
0 commit comments