-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow types with destructors in static variables #1111
Comments
Another place this would be useful is os Dev. See http://scialex.github.io/reenix.pdf section 3.2.3 Often we have statics that hold global state that would make most sense as maps and the like. |
+1 for this. This shouldn't have soundness implications – you can already get an essentially-equivalent behaviour by rooting your dtor-ey struct in main and never returning (exiting by signal/ |
I am generally in favor. My only hesitation is that I vaguely remember finding a way that I would have been able to violate memory safety by abusing the fact that thread locals are |
|
Any update on this? |
#913 Maybe related. |
CC @nikomatsakis, could the lang team discuss this and decide? Thanks! (I’m in favor.) |
#1440 is a draft RFC allowing this, but it may need major revision or rewriting. |
On Tue, Mar 08, 2016 at 06:16:42AM -0800, Simon Sapin wrote:
I'm roughly in favor. I'll try to take a look at the pending RFC. |
Closing after having verified that everything works as expected. |
Currently, Rust forbids statics from containing types with destructors:
This was historically motivated by the question of when to run the destructor:
main()
for, eg, static variables due to them having historically caused trouble in, eg, C++ code bases.The conservative choice was to forbid such types outright until a decision could be reached.
However, a lot has happened since then:
main()
anymore.Informally, language semantic and idiomatic code now shifted into this position:
main()
, and all initialization/deinitialization needs to happen in it.Box<T> -> &'static T
)In keeping with that trend, the language semantic should be changed as follows:
The benefit would be more freedom around static variables.
As a concrete use case, this change would allow lazy_static to work without requiring a heap allocation. (It currently uses a raw pointer to a heap allocation in a mutable static to get around the destructor issue)
The text was updated successfully, but these errors were encountered: