Skip to content

Commit f70cf59

Browse files
committed
Improve safety comment, double-drop is not relevant here
1 parent b0f6b69 commit f70cf59

File tree

1 file changed

+4
-3
lines changed
  • library/std/src/sys/thread_local/native

1 file changed

+4
-3
lines changed

library/std/src/sys/thread_local/native/lazy.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ unsafe extern "C" fn destroy<T>(ptr: *mut u8) {
109109
abort_on_dtor_unwind(|| {
110110
let storage = unsafe { &*(ptr as *const Storage<T, ()>) };
111111
if let State::Alive = storage.state.replace(State::Destroyed(())) {
112-
// SAFETY: we ensured the state was Alive, and prevented running the destructor
113-
// twice by updating the state to Destroyed. This is necessary as the destructor
114-
// may attempt to access the variable.
112+
// SAFETY: we ensured the state was Alive so the value was initialized.
113+
// We also updated the state to Destroyed to prevent the destructor
114+
// from accessing the thread-local variable, as this would violate
115+
// the exclusive access provided by &mut T in Drop::drop.
115116
unsafe {
116117
crate::ptr::drop_in_place(storage.value.get().cast::<T>());
117118
}

0 commit comments

Comments
 (0)