-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
UnsafeCell allows types with destructors to end up in statics. #30667
Comments
Reference rust-lang/rfcs#913 and draft RFC on allowing destructors in statics - https://github.com/thepowersgang/rust-lang_rfcs/blob/drop-types-in-const/text/0000-drop-types-in-const.md |
Huh, so, I hadn't thought hard about this for a while, but it seems like, to preserve the spirit of the current rules, we need to be more conservative around some kinds of values. But it is kind of a pain. Basically:
By "type-based heuristcs", I mean rules that say "if this type potentially reaches something with a dtor, complain". But argh what a pain. It'd be nice if this "something with a dtor" was more cleanly reified as a language-level bound. |
This is somewhat intentional (TLS also relies on this ability). The way I rationalize it looks like:
Along those lines this seems ok to me (the issue as-is) personally. I'd also agree though that this probably wasn't given any hard though, and I haven't quite grasped how this connects to const fn just yet. |
@alexcrichton It's not unsafe to mutate e.g. a |
Ah yeah I basically just mean that unsafe is needed somewhere to put the dtor in a static (in this case it's hidden inside the mutex). I would personally be fine with types-with-destructors in statics just being specc'd as never having dtors run. |
On Mon, Jan 11, 2016 at 12:24:43AM -0800, Alex Crichton wrote:
I don't think there is necessarily a problem with |
Appears to be a part of/subsumed by #33156. |
Triage; wow this is an old issue! I believe that rust-lang/rfcs#1440 makes this fixed. #33156 was merged. So, closing! If we're still missing something here, please let me know! |
Apparently this has been used by
lazy-static
for a while now as a "nightly feature":This happens to work even when
$T
isVec<X>
orString
, which should not end up in astatic
, by the current rules.A potential fix would involve adding another constant qualification flag for "contains
UnsafeCell<D>
whereD
has a destructor" and deny that in astatic
.I would like to avoid reusing a combination of the existing flags, as that can result in false positives.
Another possible plan (requiring a new RFC) would be to:
Drop
in constant expressionsconst
items from holding values with destructors, but allowconst fn
to return themDrop
impl getting called, where they not in a constant contextcc @nikomatsakis @thepowersgang
The text was updated successfully, but these errors were encountered: