Unions with unsized variants
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:
-
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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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