Skip to main content

is_or_contains_union

Function is_or_contains_union 

Source
fn is_or_contains_union<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool
where Ty: TyAbiInterface<'a, C> + Copy, C: HasDataLayout,
Expand description

Whether layout is or contains a union.

homogeneous_aggregate merges the fields of a union, so it cannot tell a union from a structure. This walks the layout a second time; keep the array handling here in sync with homogeneous_aggregate. ZSTs are ignored entirely, as both GCC and Clang do.

This does not look at enums that are represented as unions at the ABI level (e.g. a #[repr(C)] enum with fields). That does not matter here: enums can only have integer discriminants, and is_homogeneous_aggregate rejects anything containing an integer, so an enum can never be a float or vector homogeneous aggregate.