1
Fork 0

reject projecting to fields whose offset we cannot compute

This commit is contained in:
Ralf Jung 2023-12-02 12:43:56 +01:00
parent b1613ebc43
commit 9ef1e35166
7 changed files with 85 additions and 75 deletions

View file

@ -174,12 +174,15 @@ where
};
(base_meta, offset.align_to(align))
}
None => {
// For unsized types with an extern type tail we perform no adjustments.
// NOTE: keep this in sync with `PlaceRef::project_field` in the codegen backend.
assert!(matches!(base_meta, MemPlaceMeta::None));
None if offset == Size::ZERO => {
// If the offset is 0, then rounding it up to alignment wouldn't change anything,
// so we can do this even for types where we cannot determine the alignment.
(base_meta, offset)
}
None => {
// We don't know the alignment of this field, so we cannot adjust.
throw_unsup_format!("`extern type` does not have a known offset")
}
}
} else {
// base_meta could be present; we might be accessing a sized field of an unsized