Annotate panic! reasons during enum layout
Add some reasons to the panics, and use more exhaustive matches.
This commit is contained in:
parent
c722d5191c
commit
0e9d400587
@ -382,7 +382,7 @@ struct TmpLayout<FieldIdx: Idx, VariantIdx: Idx> {
|
|||||||
*offset += this_offset;
|
*offset += this_offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
FieldsShape::Primitive | FieldsShape::Array { .. } | FieldsShape::Union(..) => {
|
||||||
panic!("Layout of fields should be Arbitrary for variants")
|
panic!("Layout of fields should be Arbitrary for variants")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -600,7 +600,9 @@ struct TmpLayout<FieldIdx: Idx, VariantIdx: Idx> {
|
|||||||
variant.size = new_ity_size;
|
variant.size = new_ity_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => panic!(),
|
FieldsShape::Primitive | FieldsShape::Array { .. } | FieldsShape::Union(..) => {
|
||||||
|
panic!("encountered a non-arbitrary layout during enum layout")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -628,7 +630,7 @@ struct TmpLayout<FieldIdx: Idx, VariantIdx: Idx> {
|
|||||||
let mut common_prim_initialized_in_all_variants = true;
|
let mut common_prim_initialized_in_all_variants = true;
|
||||||
for (field_layouts, layout_variant) in iter::zip(variants, &layout_variants) {
|
for (field_layouts, layout_variant) in iter::zip(variants, &layout_variants) {
|
||||||
let FieldsShape::Arbitrary { ref offsets, .. } = layout_variant.fields else {
|
let FieldsShape::Arbitrary { ref offsets, .. } = layout_variant.fields else {
|
||||||
panic!();
|
panic!("encountered a non-arbitrary layout during enum layout");
|
||||||
};
|
};
|
||||||
// We skip *all* ZST here and later check if we are good in terms of alignment.
|
// We skip *all* ZST here and later check if we are good in terms of alignment.
|
||||||
// This lets us handle some cases involving aligned ZST.
|
// This lets us handle some cases involving aligned ZST.
|
||||||
@ -681,7 +683,7 @@ struct TmpLayout<FieldIdx: Idx, VariantIdx: Idx> {
|
|||||||
assert_eq!(memory_index.raw, [0, 1]);
|
assert_eq!(memory_index.raw, [0, 1]);
|
||||||
offsets
|
offsets
|
||||||
}
|
}
|
||||||
_ => panic!(),
|
_ => panic!("encountered a non-arbitrary layout during enum layout"),
|
||||||
};
|
};
|
||||||
if pair_offsets[FieldIdx::new(0)] == Size::ZERO
|
if pair_offsets[FieldIdx::new(0)] == Size::ZERO
|
||||||
&& pair_offsets[FieldIdx::new(1)] == *offset
|
&& pair_offsets[FieldIdx::new(1)] == *offset
|
||||||
@ -758,7 +760,9 @@ struct TmpLayout<FieldIdx: Idx, VariantIdx: Idx> {
|
|||||||
Variants::Multiple { tag, tag_encoding, tag_field, .. } => {
|
Variants::Multiple { tag, tag_encoding, tag_field, .. } => {
|
||||||
Variants::Multiple { tag, tag_encoding, tag_field, variants: best_layout.variants }
|
Variants::Multiple { tag, tag_encoding, tag_field, variants: best_layout.variants }
|
||||||
}
|
}
|
||||||
_ => panic!(),
|
Variants::Single { .. } => {
|
||||||
|
panic!("encountered a single-variant enum during multi-variant layout")
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Some(best_layout.layout)
|
Some(best_layout.layout)
|
||||||
}
|
}
|
||||||
@ -1154,7 +1158,11 @@ fn univariant<
|
|||||||
assert_eq!(memory_index.raw, [0, 1]);
|
assert_eq!(memory_index.raw, [0, 1]);
|
||||||
offsets
|
offsets
|
||||||
}
|
}
|
||||||
_ => panic!(),
|
FieldsShape::Primitive
|
||||||
|
| FieldsShape::Array { .. }
|
||||||
|
| FieldsShape::Union(..) => {
|
||||||
|
panic!("encountered a non-arbitrary layout during enum layout")
|
||||||
|
}
|
||||||
};
|
};
|
||||||
if offsets[i] == pair_offsets[FieldIdx::new(0)]
|
if offsets[i] == pair_offsets[FieldIdx::new(0)]
|
||||||
&& offsets[j] == pair_offsets[FieldIdx::new(1)]
|
&& offsets[j] == pair_offsets[FieldIdx::new(1)]
|
||||||
|
Loading…
Reference in New Issue
Block a user