File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed
library/std/src/sys/thread_local/native Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -109,9 +109,10 @@ unsafe extern "C" fn destroy<T>(ptr: *mut u8) {
109
109
abort_on_dtor_unwind ( || {
110
110
let storage = unsafe { & * ( ptr as * const Storage < T , ( ) > ) } ;
111
111
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.
115
116
unsafe {
116
117
crate :: ptr:: drop_in_place ( storage. value . get ( ) . cast :: < T > ( ) ) ;
117
118
}
You can’t perform that action at this time.
0 commit comments