We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d0d5d19 commit 6457f4dCopy full SHA for 6457f4d
std/src/sys/thread_local/native/lazy.rs
@@ -84,8 +84,15 @@ where
84
// access to self.value and may replace it.
85
let mut old_value = unsafe { self.value.get().replace(MaybeUninit::new(v)) };
86
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.
90
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.
94
State::Alive => unsafe { old_value.assume_init_drop() },
95
96
State::Destroyed(_) => unreachable!(),
97
}
98
0 commit comments