mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-05 01:24:03 +00:00
rustc_abi: Add `LayoutData::is_variant_uninhabited` method This is a cheaper alternative to `TyAndLayout::for_variant(_, idx).is_uninhabited()`, which avoids the extra work done by `TyAndLayout::for_variant`. EDIT: Let me expand on the motivation from this [comment](https://github.com/rust-lang/rust/pull/160398#issuecomment-5167761369): `TyAndLayout::for_variant` is a curious API: the resulting layout doesn't represent a Rust type in the strict sense (not even `pattern_type!(Enum is Variant { .. })`; instead, it only describes the "variant-specific" fields, and fields shared between variants (e.g. the enum tag or coroutine captures) are entirely missing. As such, I believe alternative APIs should be used instead to clarify intent, when possible. This PR deals with the simplest cases, and a future PR will add `TyAndLayout::variant_field(self, cx, variant_idx, field_idx)` to deal with the next-most common case of only needing a variant layout for field lookups.