diff --git a/c2rust-refactor/src/context.rs b/c2rust-refactor/src/context.rs index 3c4cd5f19d..4c29553ae6 100644 --- a/c2rust-refactor/src/context.rs +++ b/c2rust-refactor/src/context.rs @@ -1271,6 +1271,10 @@ impl<'a, 'tcx, 'b> TypeCompare<'a, 'tcx, 'b> { match (&ty1.kind(), &ty2.kind()) { (TyKind::Adt(def1, substs1), TyKind::Adt(def2, substs2)) => { + if def1.adt_kind() != def2.adt_kind() { + return false; + } + if substs1.types().count() != substs2.types().count() || !substs1 .types() @@ -1298,13 +1302,21 @@ impl<'a, 'tcx, 'b> TypeCompare<'a, 'tcx, 'b> { return true; } - def1.all_fields().count() == def2.all_fields().count() + def1.variants().len() == def2.variants().len() && def1 - .all_fields() - .zip(def2.all_fields()) - .all(|(field1, field2)| { - field1.ident(tcx).unnamed_equiv(&field2.ident(tcx)) - && self.structural_eq_defs_impl(field1.did, field2.did, seen) + .variants() + .iter() + .zip(def2.variants().iter()) + .all(|(var1, var2)| { + var1.fields.len() == var2.fields.len() + && var1.fields.iter().zip(var2.fields.iter()).all( + |(field1, field2)| { + field1.ident(tcx).unnamed_equiv(&field2.ident(tcx)) + && self.structural_eq_defs_impl( + field1.did, field2.did, seen, + ) + }, + ) }) }