From 79e31cb80ea78dbfe67597fcff2f2a5d4d172f8d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 2 Sep 2023 11:36:34 +0200 Subject: [PATCH] DefaultUnionRepresentation: explain why we only warn about unions with at least 2 non-ZST fields --- clippy_lints/src/default_union_representation.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clippy_lints/src/default_union_representation.rs b/clippy_lints/src/default_union_representation.rs index 03b5a2d6d..bbce6e1dd 100644 --- a/clippy_lints/src/default_union_representation.rs +++ b/clippy_lints/src/default_union_representation.rs @@ -69,6 +69,9 @@ impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation { } /// 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