]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: derive(PartialEq): Use that common class
authorArthur Cohen <arthur.cohen@embecosm.com>
Fri, 18 Apr 2025 16:19:18 +0000 (18:19 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:47 +0000 (16:36 +0200)
gcc/rust/ChangeLog:

* expand/rust-derive-partial-eq.cc (DerivePartialEq::tuple_indexes): Remove.
(DerivePartialEq::field_acccesses): Remove.
(DerivePartialEq::visit_tuple): Use new API.
(DerivePartialEq::visit_struct): Likewise.
* expand/rust-derive-partial-eq.h: Remove declarations.

gcc/rust/expand/rust-derive-partial-eq.cc
gcc/rust/expand/rust-derive-partial-eq.h

index 22368bcb2b0109af3f4f9e93fa919def7471bd53..13a09fce059d040adfcad292e07a8e353e6481ca 100644 (file)
@@ -83,24 +83,6 @@ DerivePartialEq::eq_fn (std::unique_ptr<Expr> &&cmp_expression,
                           std::move (block));
 }
 
-DerivePartialEq::SelfOther
-DerivePartialEq::tuple_indexes (int idx)
-{
-  return SelfOther{
-    builder.tuple_idx ("self", idx),
-    builder.tuple_idx ("other", idx),
-  };
-}
-
-DerivePartialEq::SelfOther
-DerivePartialEq::field_acccesses (const std::string &field_name)
-{
-  return SelfOther{
-    builder.field_access (builder.identifier ("self"), field_name),
-    builder.field_access (builder.identifier ("other"), field_name),
-  };
-}
-
 std::unique_ptr<Expr>
 DerivePartialEq::build_eq_expression (
   std::vector<SelfOther> &&field_expressions)
@@ -137,7 +119,7 @@ DerivePartialEq::visit_tuple (TupleStruct &item)
   auto fields = std::vector<SelfOther> ();
 
   for (size_t idx = 0; idx < item.get_fields ().size (); idx++)
-    fields.emplace_back (tuple_indexes (idx));
+    fields.emplace_back (SelfOther::index (builder, idx));
 
   auto fn = eq_fn (build_eq_expression (std::move (fields)), type_name);
 
@@ -153,7 +135,7 @@ DerivePartialEq::visit_struct (StructStruct &item)
 
   for (auto &field : item.get_fields ())
     fields.emplace_back (
-      field_acccesses (field.get_field_name ().as_string ()));
+      SelfOther::field (builder, field.get_field_name ().as_string ()));
 
   auto fn = eq_fn (build_eq_expression (std::move (fields)), type_name);
 
index 12d793d81bca3c9bc22db5c8f5f1ff6d49a656ab..fdfe4dacb85a56f908820c49b0d8fb2eb71c2181 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "rust-derive.h"
 #include "rust-path.h"
+#include "rust-derive-cmp-common.h"
 
 namespace Rust {
 namespace AST {
@@ -46,19 +47,6 @@ private:
   std::unique_ptr<AssociatedItem> eq_fn (std::unique_ptr<Expr> &&cmp_expression,
                                         std::string type_name);
 
-  /**
-   * A pair of two expressions from each instance being compared. E.g. this
-   * could be `self.0` and `other.0`, or `self.field` and `other.field`
-   */
-  struct SelfOther
-  {
-    std::unique_ptr<Expr> self_expr;
-    std::unique_ptr<Expr> other_expr;
-  };
-
-  SelfOther tuple_indexes (int idx);
-  SelfOther field_acccesses (const std::string &field_name);
-
   /**
    * Build a suite of equality arithmetic expressions chained together by a
    * boolean AND operator