Auto merge of #11448 - RalfJung:DefaultUnionRepresentation, r=blyxyas

DefaultUnionRepresentation: explain why we only warn about unions with at least 2 non-ZST fields

changelog: none
This commit is contained in:
bors 2023-09-02 10:14:33 +00:00
commit 7cf96dabb7

View File

@ -69,6 +69,9 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
}
/// Returns true if the given item is a union with at least two non-ZST fields.
/// (ZST fields having an arbitrary offset is completely inconsequential, and
/// if there is only one field left after ignoring ZST fields then the offset
/// of that field does not matter either.)
fn is_union_with_two_non_zst_fields(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
if let ItemKind::Union(data, _) = &item.kind {
data.fields().iter().filter(|f| !is_zst(cx, f.ty)).count() >= 2