diff options
| author | Orson Peters <orsonpeters@gmail.com> | 2025-05-30 12:13:55 +0200 |
|---|---|---|
| committer | Orson Peters <orsonpeters@gmail.com> | 2025-05-30 12:14:27 +0200 |
| commit | b374adc9dbeec2cc969723dbfcb5c8ee990953bd (patch) | |
| tree | 113584e4e924c60ac3086bda5ce24011fae96324 | |
| parent | aff29df28e312e6ec247a62eaee5c50d431e7015 (diff) | |
| download | rust-b374adc9dbeec2cc969723dbfcb5c8ee990953bd.tar.gz rust-b374adc9dbeec2cc969723dbfcb5c8ee990953bd.zip | |
Address review comments.
| -rw-r--r-- | library/std/src/sys/thread_local/native/lazy.rs | 7 | ||||
| -rw-r--r-- | tests/ui/threads-sendsync/tls-dont-move-after-init.rs | 1 |
2 files changed, 7 insertions, 1 deletions
diff --git a/library/std/src/sys/thread_local/native/lazy.rs b/library/std/src/sys/thread_local/native/lazy.rs index a2bf8d8b968..b556dd9aa25 100644 --- a/library/std/src/sys/thread_local/native/lazy.rs +++ b/library/std/src/sys/thread_local/native/lazy.rs @@ -84,8 +84,15 @@ where // access to self.value and may replace it. let mut old_value = unsafe { self.value.get().replace(MaybeUninit::new(v)) }; match self.state.replace(State::Alive) { + // If the variable is not being recursively initialized, register + // the destructor. This might be a noop if the value does not need + // destruction. State::Uninitialized => D::register_dtor(self), + + // Recursive initialization, we only need to drop the old value + // as we've already registered the destructor. State::Alive => unsafe { old_value.assume_init_drop() }, + State::Destroyed(_) => unreachable!(), } diff --git a/tests/ui/threads-sendsync/tls-dont-move-after-init.rs b/tests/ui/threads-sendsync/tls-dont-move-after-init.rs index f986202ab89..54fcc32e9bd 100644 --- a/tests/ui/threads-sendsync/tls-dont-move-after-init.rs +++ b/tests/ui/threads-sendsync/tls-dont-move-after-init.rs @@ -1,5 +1,4 @@ //@ run-pass -#![allow(stable_features)] //@ needs-threads use std::cell::Cell; |
