Layout for enums does not match MIR (and types) very well #70399
Labels
A-layout
Area: Memory layout of types
A-MIR
Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
C-cleanup
Category: PRs that clean code up or issues documenting cleanup.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Enum layout computation entirely ignores ZST uninhabited ("absent") variants, which can lead to the layout being quite different in structure from the user-visible enum:
Variants::Multiple
is used.Variants::Single
is used.!
is used, so the entire thing ends up looking like a union with 0 fields.When actually asking for the layout of such an absent variant, it has to be made up "on the spot".
In terms of testing things like Miri (or anything else that needs to work with layout variants information), this leads to the "interesting" situation that we need an enum with at least 3 variants where 1 is "absent" to make sure that
Variants::Multiple
with absent variants is handled correctly.This could be improved by generalizing
Variants::Multiple
to also support "discriminants" of "type"()
and!
, thus uniformly handling all enums.Also see the second half of #69763 (comment), and discussion below #69763 (comment).
Cc @eddyb
The text was updated successfully, but these errors were encountered: