Skip to content

Unions with unsized variants #3041

Open
@mahkoh

Description

@mahkoh

I believe it would be technically feasible (easy, even) to have unions with at most one unsized variant.

Unsizing should be safe:

  1. T -> dyn U: The vtable contains 2 values relevant for the unsized union:

    1. The alignment: This is stored directly in the vtable of T, accessing it does not access the data pointer
    2. The size: Same.

    Note that drop_in_place is not relevant because unions do not drop their contents.

  2. [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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions