Skip to content

Commit 07b13c8

Browse files
committed
Implement equality in clippy for UnnamedField
1 parent b951e6c commit 07b13c8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/tools/clippy/clippy_utils/src/ast_utils.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,18 @@ pub fn eq_struct_field(l: &FieldDef, r: &FieldDef) -> bool {
371371
match (&l.variant, &r.variant) {
372372
(FieldVariant::Named(NamedField{ident: l_ident, ty: l_ty}),
373373
FieldVariant::Named(NamedField{ident: r_ident, ty: r_ty})) =>
374-
both(l_ident, r_ident, |l, r| eq_id(*l, *r))
375-
&& eq_ty(l_ty, r_ty),
376-
// FIXME: Compare two unnamed fields and check for equality
377-
(FieldVariant::Unnamed(_),
378-
FieldVariant::Named(_)) => false,
374+
both(l_ident, r_ident, |l, r| eq_id(*l, *r)) && eq_ty(l_ty, r_ty),
375+
376+
(FieldVariant::Unnamed(UnnamedField::Struct(l_v)),
377+
FieldVariant::Unnamed(UnnamedField::Struct(r_v)))
378+
| (FieldVariant::Unnamed(UnnamedField::Union(l_v)),
379+
FieldVariant::Unnamed(UnnamedField::Union(r_v))) =>
380+
l_v.iter().zip(r_v.iter()).all(|(l_f, r_f)| eq_struct_field(l_f, r_f)),
381+
382+
(FieldVariant::Unnamed(UnnamedField::Type(l_ty)),
383+
FieldVariant::Unnamed(UnnamedField::Type(r_ty))) =>
384+
eq_ty(l_ty, r_ty),
385+
379386
_ => false
380387
}
381388
}

0 commit comments

Comments
 (0)