diff options
| author | Ralf Jung <post@ralfj.de> | 2023-09-02 11:36:34 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-09-02 11:36:34 +0200 |
| commit | 79e31cb80ea78dbfe67597fcff2f2a5d4d172f8d (patch) | |
| tree | 3761922acddda80fa478b684c83d0130a398eb86 | |
| parent | a8b5245ea36bbfca48db5f4d77428dad2ca104fa (diff) | |
| download | rust-79e31cb80ea78dbfe67597fcff2f2a5d4d172f8d.tar.gz rust-79e31cb80ea78dbfe67597fcff2f2a5d4d172f8d.zip | |
DefaultUnionRepresentation: explain why we only warn about unions with at least 2 non-ZST fields
| -rw-r--r-- | clippy_lints/src/default_union_representation.rs | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/clippy_lints/src/default_union_representation.rs b/clippy_lints/src/default_union_representation.rs index 03b5a2d6d08..bbce6e1dd8f 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 |
