Skip to content

Commit b374adc

Browse files
committed
Address review comments.
1 parent aff29df commit b374adc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,15 @@ where
8484
// access to self.value and may replace it.
8585
let mut old_value = unsafe { self.value.get().replace(MaybeUninit::new(v)) };
8686
match self.state.replace(State::Alive) {
87+
// If the variable is not being recursively initialized, register
88+
// the destructor. This might be a noop if the value does not need
89+
// destruction.
8790
State::Uninitialized => D::register_dtor(self),
91+
92+
// Recursive initialization, we only need to drop the old value
93+
// as we've already registered the destructor.
8894
State::Alive => unsafe { old_value.assume_init_drop() },
95+
8996
State::Destroyed(_) => unreachable!(),
9097
}
9198

tests/ui/threads-sendsync/tls-dont-move-after-init.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ run-pass
2-
#![allow(stable_features)]
32
//@ needs-threads
43

54
use std::cell::Cell;

0 commit comments

Comments
 (0)