-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Allow recursive untagged unions #1804
Copy link
Copy link
Closed
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.
Description
The current implementation of RFC #1444 disallows the following:
#![feature(untagged_unions)]
union Foo {
f0: u8,
f1: Foo,
}error[E0072]: recursive type `Foo` has infinite size
--> <anon>:3:1
|
3 | union Foo {
| ^ recursive type has infinite size
|
= help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `Foo` representable
Unlike structs, since all fields of a union exist in the same space, a union whose definition involves infinite recursion can be represented in finite space. In this case, Foo can be represented as union { f0: u8 }, with &foo.f1 equivalent to &foo.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.
Type
Fields
Give feedbackNo fields configured for issues without a type.