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.
The current implementation of RFC #1444 disallows the following:
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,
Foocan be represented asunion { f0: u8 }, with&foo.f1equivalent to&foo.