Skip to content

Commit 7cf96da

Browse files
committed
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
2 parents a45feda + 79e31cb commit 7cf96da

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

clippy_lints/src/default_union_representation.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation {
6969
}
7070

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

0 commit comments

Comments
 (0)