-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Unions with unsized variants #3041
Copy link
Copy link
Open
Description
I believe it would be technically feasible (easy, even) to have unions with at most one unsized variant.
Unsizing should be safe:
-
T -> dyn U: The vtable contains 2 values relevant for the unsized union:- The alignment: This is stored directly in the vtable of T, accessing it does not access the data pointer
- The size: Same.
Note that
drop_in_placeis not relevant because unions do not drop their contents. -
[T; N] -> [T]: The metadata consists of the array length which is statically known and does not require accessing the variant.
@eddyb: In the last paragraph here you wrote that there is a problem with unsized unions but I haven't been able to figure it out. Maybe you were talking about unions with more than one unsized variant?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.