If this is implemented using the same infrastructure as C++ static initializers, then the infrastructure they would run on wouldn’t depend on allocation or anything else in
std. It could even still run without the rust initialization in
If it would work out of box that would be ideal, but I believe it leaves concerns for dependency on
std as some statics may need memory allocations and friends.
It is been a while since I looked at Rust runtime, but most likely panics would be UB in this case, but heap allocations are still should be allowed(need to check at which step global allocator is et up)
std::mem::uninitialized()is non-const, so I don’t think it’s possible at all to do this?
I believe a better support for global constructors would require it to become const, let say as extra feature. While it is true we can use
Option and friends, it is overhead.
In short ideally we need
const way to have uninitialized static for global constructor to initialize