Skip to content

Allow recursive untagged unions #1804

Description

@spinda

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions