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

This commit is contained in:
Ralf Jung 2023-09-02 11:36:34 +02:00
parent a8b5245ea3
commit 79e31cb80e

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