LocalKey
dropped after calling std::process::exit()
#127637
Labels
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
A-process
Area: `std::process` and `std::env`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Unlike normal static variables (or the differently implemented unstable
#[thread_local]
statics),thread_local!
/LocalKey
statics are still dropped after callingstd::process::exit()
.I tried this code:
Link to playground
I expected to see this happen: No output from
drop()
since the documentation forstd::process::exit()
makes a point of saying no destructors will be called and the program will exit immediately. When calling exit, I assumed that almost nothing happens after that.Instead, this happened: The static variable wrapped with
thread_local!
had its drop implementation called after callingstd::process::exit()
meanwhile a normal static variable and one with the unstable#[thread_local]
attribute did not.Other notes: The same behavior occurs where only the
thread_local!
value is dropped when normally exiting frommain()
.LocalKey's documentation sort of makes it sound like this is intentional behavior that the destructors are run even when exiting the main thread (See "Platform-specific behavior" 1.). If this is working as intended, it would be nice if the documentation were slightly clearer.
Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: