Enums in offset_of: update based on est31, scottmcm & llogiq review
This commit is contained in:
parent
e936416a8d
commit
d995bd61e7
15 changed files with 150 additions and 140 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue