Static thread_local! declarations are moved before Drop is called #140816
Labels
A-thread-locals
Area: Thread local storage (TLS)
C-discussion
Category: Discussion or questions that doesn't represent real issues.
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
Consider this piece of code:
I would expect the statically declared
FOO
to not move around after initialization. In fact,Foo
might be a type which may not be moved around after initialization at all, such as a type containingpthread_mutex_t
. However, we see that it does get moved before the drop:I believe the issue lies here:
rust/library/std/src/sys/thread_local/native/lazy.rs
Lines 95 to 98 in e964cca
This code should be changed to not use an enum but rather a separate state flag + cell, so that the value is not moved.
The text was updated successfully, but these errors were encountered: