rust-lang / rust-lang/rfcs

Unions with unsized variants

Open
#3,041 36 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the proposal and the linked RFC #1151 comment, then trace the stated unsizing cases for trait objects and slices. Determine whether a union with at most one unsized variant is sound, including any missing constraints, and document a clear conclusion or the remaining blockers for an RFC change.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.