-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for RFC 2514, "Union initialization and Drop" #55149
Comments
This comment has been minimized.
This comment has been minimized.
Is there anything else tracked in #32836 that is not covered here? Does implementing this RFC mean fully stabilizing the |
@SimonSapin I just make the issues, so I'll leave the question up to @RalfJung :) |
Stabilization is separate, right? It has its own checkmark above. :) Implementing the RFC means restricting unions with non- I am not fully aware of everything that exists behind the Quoting from the other tracking issue:
This is answered by this RFC.
The RFC doesn't say anything about that, but I think indeed the answer should be "all variants".
This is topic of a future unsafe code guidelines discussion, and unrelated to this RFC. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This is the part that needs to be changed: rust/src/librustc/middle/stability.rs Lines 768 to 773 in 757d6cc
Turns out... I was wrong from the start, adt_def.non_enum_variant().fields.iter().any(|field| {
self.tcx.type_of(field.did).needs_drop(self.tcx, param_env)
}) Also, this shouldn't be nested in the |
Behavior if the check failed should then also change from "require feature flag" to "hard error". |
This comment has been minimized.
This comment has been minimized.
… r=RalfJung Change untagged_unions to not allow union fields with drop This is a rebase of rust-lang#56440, massaged to solve merge conflicts and make the test suite pass. Change untagged_unions to not allow union fields with drop Union fields may now never have a type with attached destructor. This for example allows unions to use arbitrary field types only by wrapping them in `ManuallyDrop` (or similar). The stable rule remains, that union fields must be `Copy`. We use the new rule for the `untagged_union` feature. Tracking issue: rust-lang#55149
… r=RalfJung Change untagged_unions to not allow union fields with drop This is a rebase of rust-lang#56440, massaged to solve merge conflicts and make the test suite pass. Change untagged_unions to not allow union fields with drop Union fields may now never have a type with attached destructor. This for example allows unions to use arbitrary field types only by wrapping them in `ManuallyDrop` (or similar). The stable rule remains, that union fields must be `Copy`. We use the new rule for the `untagged_union` feature. Tracking issue: rust-lang#55149
#62330 has landed. Are there remaining changes specified in the RFC that are not implemented yet? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
It sounds like this has been fully implemented, and the current state of unions is roughly where we want them to be. We'd like to close the remainder of this, and just not allow non-Copy union fields in general, changing that from a feature gate to an error. @rfcbot close |
Team member @joshtriplett has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
FWIW, when the |
In #97995 I am suggesting to allow a few more types for union fields on stable (specifically: mutable references), before we entirely remove the |
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
…Simulacrum allow unions with mutable references and tuples of allowed types We currently allow shared references in unions, but not mutable references. That seems somewhat inconsistent. So let's allow all references, and while we are at it, let's make sure the set of allowed types is closed under tuples. This will need T-lang FCP (at least). Then remove the `tagged_unions` feature, since we do not plan to stabilize any more of it. Closes rust-lang#55149
…Simulacrum allow unions with mutable references and tuples of allowed types We currently allow shared references in unions, but not mutable references. That seems somewhat inconsistent. So let's allow all references, and while we are at it, let's make sure the set of allowed types is closed under tuples. This will need T-lang FCP (at least). Then remove the `tagged_unions` feature, since we do not plan to stabilize any more of it. Closes rust-lang#55149
@joshtriplett @RalfJung I think removing this has exposed an overlooked use case that should work, but now doesn't.
This now fails to compile with
|
Never inspecting the fields of a In this case, it seems like the struct and union are in the same crate? Possibly an exception could be made for that case, though it would be an extension of the RFC. Please open a feature request issue. |
@RalfJung thanks for the quick reply. The struct and union are in the same crate and both are private too it, as well. If versions are correctly used, then a future version of the struct should then cause failure. I won't be opening a feature request. |
This is a tracking issue for the RFC "Union initialization and Drop" (rust-lang/rfcs#2514).
Successor of #32836.
Steps:
Unresolved questions:
There should be more tests in particular for all move-related behaviors (1, 2, 3, 4). Done in unions: test move behavior of non-Copy fields #75559.
Should we try to avoid the
DerefMut
-related pitfall? And if yes, should we maybe try harder, e.g. lint against using*
below a union type when describing a place? That would make people writelet v = &mut u.f; *v = Vec::new();
. It is not clear that this helps in terms of pointing out that an automatic drop may be happening. (Implementation at do not apply DerefMut on union field #75584.)We could allow moving out of a union field even if the union implements
Drop
. That would have the effect of making the union considered uninitialized, i.e., it would not be dropped implicitly when it goes out of scope. However, it might be useful to not let people do this accidentally. The same effect can always be achieved by having a dropless union wrapped in a newtypestruct
with the desiredDrop
.Should we allow
impl Copy for Union
even when the union has non-Copy
fields? (Proposed here.)Implementation history
DerefMut
in unionsManuallyDrop<_>
union fieldsThe text was updated successfully, but these errors were encountered: