make no-variant types a dedicated Variants variant

This commit is contained in:
Ralf Jung
2024-12-01 17:33:01 +01:00
parent 21de42bf8d
commit e023590de4
53 changed files with 246 additions and 495 deletions

View File

@@ -1504,11 +1504,13 @@ impl BackendRepr {
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
pub enum Variants<FieldIdx: Idx, VariantIdx: Idx> {
/// A type with no valid variants. Must be uninhabited.
Empty,
/// Single enum variants, structs/tuples, unions, and all non-ADTs.
Single {
/// Always `Some(0)` for types without variants (i.e., everything except for `!`, enums, and
/// generators). `None` indicates an uninhabited type; this is used for zero-variant enums.
index: Option<VariantIdx>,
/// Always `0` for types that cannot have multiple variants.
index: VariantIdx,
},
/// Enum-likes with more than one variant: each variant comes with
@@ -1706,7 +1708,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
let size = scalar.size(cx);
let align = scalar.align(cx);
LayoutData {
variants: Variants::Single { index: Some(VariantIdx::new(0)) },
variants: Variants::Single { index: VariantIdx::new(0) },
fields: FieldsShape::Primitive,
backend_repr: BackendRepr::Scalar(scalar),
largest_niche,