]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: derive(Ord, PartialOrd): Handle tuples properly
authorArthur Cohen <arthur.cohen@embecosm.com>
Fri, 18 Apr 2025 16:30:46 +0000 (18:30 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:47 +0000 (16:36 +0200)
gcc/rust/ChangeLog:

* expand/rust-derive-ord.cc (is_last): Remove.
(DeriveOrd::visit_tuple): Fix implementation.

gcc/rust/expand/rust-derive-ord.cc

index 2403e9c2a33d68c94ce7beeeb577af3b65fb5ef4..e39c6b44ca46bf77080c8fa39b2624b5543e53d5 100644 (file)
@@ -123,15 +123,6 @@ DeriveOrd::make_cmp_arms ()
          builder.match_arm (std::move (non_equal))};
 }
 
-template <typename T>
-inline bool
-is_last (T &elt, std::vector<T> &vec)
-{
-  rust_assert (!vec.empty ());
-
-  return &elt == &vec.back ();
-}
-
 std::unique_ptr<Expr>
 DeriveOrd::recursive_match (std::vector<SelfOther> &&members)
 {
@@ -210,7 +201,14 @@ DeriveOrd::visit_struct (StructStruct &item)
 // straightforward once we have `visit_struct` working
 void
 DeriveOrd::visit_tuple (TupleStruct &item)
-{}
+{
+  auto fields = SelfOther::indexes (builder, item.get_fields ());
+
+  auto match_expr = recursive_match (std::move (fields));
+
+  expanded = cmp_impl (builder.block (std::move (match_expr)),
+                      item.get_identifier (), item.get_generic_params ());
+}
 
 // for enums, we need to generate a match for each of the enum's variant that
 // contains data and then do the same thing as visit_struct or visit_enum. if