diff options
| author | Orson Peters <orsonpeters@gmail.com> | 2025-05-28 14:51:52 +0200 |
|---|---|---|
| committer | Orson Peters <orsonpeters@gmail.com> | 2025-05-28 14:51:52 +0200 |
| commit | f70cf59fc19b7717397e9701b4783f744983275f (patch) | |
| tree | 52e9433a8b439d25cadb208b141a85e268e9bca5 | |
| parent | b0f6b69b813aae1b7525d222ca1d2ba9c1fa25f1 (diff) | |
| download | rust-f70cf59fc19b7717397e9701b4783f744983275f.tar.gz rust-f70cf59fc19b7717397e9701b4783f744983275f.zip | |
Improve safety comment, double-drop is not relevant here
| -rw-r--r-- | library/std/src/sys/thread_local/native/lazy.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/library/std/src/sys/thread_local/native/lazy.rs b/library/std/src/sys/thread_local/native/lazy.rs index 0cb7fa0ef24..7cf2ba5eed8 100644 --- a/library/std/src/sys/thread_local/native/lazy.rs +++ b/library/std/src/sys/thread_local/native/lazy.rs @@ -109,9 +109,10 @@ unsafe extern "C" fn destroy<T>(ptr: *mut u8) { abort_on_dtor_unwind(|| { let storage = unsafe { &*(ptr as *const Storage<T, ()>) }; if let State::Alive = storage.state.replace(State::Destroyed(())) { - // SAFETY: we ensured the state was Alive, and prevented running the destructor - // twice by updating the state to Destroyed. This is necessary as the destructor - // may attempt to access the variable. + // SAFETY: we ensured the state was Alive so the value was initialized. + // We also updated the state to Destroyed to prevent the destructor + // from accessing the thread-local variable, as this would violate + // the exclusive access provided by &mut T in Drop::drop. unsafe { crate::ptr::drop_in_place(storage.value.get().cast::<T>()); } |
