-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Tracking issue for RFC 2514, "Union initialization and Drop" #55149
Copy link
Copy link
Closed
Labels
B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Approved by a merged RFC and implemented but not stabilized.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-untagged_unions`#![feature(untagged_unions)]``#![feature(untagged_unions)]`T-langRelevant to the language teamRelevant to the language teamdisposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.This PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Metadata
Metadata
Assignees
Labels
B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Approved by a merged RFC and implemented but not stabilized.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-untagged_unions`#![feature(untagged_unions)]``#![feature(untagged_unions)]`T-langRelevant to the language teamRelevant to the language teamdisposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.This PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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 newtypestructwith the desiredDrop.Should we allow
impl Copy for Unioneven when the union has non-Copyfields? (Proposed here.)Implementation history
DerefMutin unionsManuallyDrop<_>union fields