1
Fork 0

Enums in offset_of: update based on est31, scottmcm & llogiq review

This commit is contained in:
George Bateman 2023-08-15 22:32:55 +01:00
parent e936416a8d
commit d995bd61e7
No known key found for this signature in database
GPG key ID: C417AA9C4039EFCF
15 changed files with 150 additions and 140 deletions

View file

@ -250,29 +250,24 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
Ty::is_transparent(self)
}
pub fn offset_of_subfield<C>(self, cx: &C, indices: impl Iterator<Item = OffsetOfIdx>) -> Size
pub fn offset_of_subfield<C, I>(self, cx: &C, indices: I) -> Size
where
Ty: TyAbiInterface<'a, C>,
I: Iterator<Item = (VariantIdx, FieldIdx)>,
{
let mut layout = self;
let mut offset = Size::ZERO;
for index in indices {
match index {
OffsetOfIdx::Field(field) => {
let index = field.index();
offset += layout.fields.offset(index);
layout = layout.field(cx, index);
assert!(
layout.is_sized(),
"offset of unsized field (type {:?}) cannot be computed statically",
layout.ty
);
}
OffsetOfIdx::Variant(variant) => {
layout = layout.for_variant(cx, variant);
}
}
for (variant, field) in indices {
layout = layout.for_variant(cx, variant);
let index = field.index();
offset += layout.fields.offset(index);
layout = layout.field(cx, index);
assert!(
layout.is_sized(),
"offset of unsized field (type {:?}) cannot be computed statically",
layout.ty
);
}
offset