-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Description
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:
- if there are more than 1 non-absent variants,
Variants::Multiple
is used. - if there is exactly 1 non-absent variant,
Variants::Single
is used. - if all variants are absent, the layout of
!
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