1
Fork 0

fix detecting references to packed unsized fields

This commit is contained in:
Ralf Jung 2023-09-05 22:29:51 +02:00
parent ab45885dec
commit 8b3435c10f
3 changed files with 37 additions and 12 deletions

View file

@ -22,9 +22,11 @@ where
let ty = place.ty(local_decls, tcx).ty;
match tcx.layout_of(param_env.and(ty)) {
Ok(layout) if layout.align.abi <= pack => {
Ok(layout) if layout.align.abi <= pack && layout.is_sized() => {
// If the packed alignment is greater or equal to the field alignment, the type won't be
// further disaligned.
// However we need to ensure the field is sized; for unsized fields, `layout.align` is
// just an approximation.
debug!(
"is_disaligned({:?}) - align = {}, packed = {}; not disaligned",
place,