]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: We cant clone types as it will dup the node-id
authorPhilip Herron <herron.philip@googlemail.com>
Sun, 11 May 2025 14:03:05 +0000 (15:03 +0100)
committerPhilip Herron <philip.herron@embecosm.com>
Tue, 13 May 2025 09:16:28 +0000 (09:16 +0000)
This patch ensuers we reuse the Builder for new type to
ensure we create a new type from scratch ensuring consistent
new node-ids.

gcc/rust/ChangeLog:

* expand/rust-derive-default.cc (DeriveDefault::visit_struct): use builder
(DeriveDefault::visit_tuple): likewise
* expand/rust-derive-eq.cc (DeriveEq::visit_tuple): likewise
(DeriveEq::visit_struct): likewise
(DeriveEq::visit_enum): likewise
(DeriveEq::visit_union): likewise

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: these are fixed now

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/expand/rust-derive-default.cc
gcc/rust/expand/rust-derive-eq.cc
gcc/testsuite/rust/compile/nr2/exclude

index 2e8b45681994c097e373bfc8c9b8b6f7114bd3af..1b497b5923b02d8e488c7bb0d3cf2533ec61f3d2 100644 (file)
@@ -98,7 +98,8 @@ DeriveDefault::visit_struct (StructStruct &item)
   for (auto &field : item.get_fields ())
     {
       auto name = field.get_field_name ().as_string ();
-      auto expr = default_call (field.get_field_type ().clone_type ());
+      auto type = Builder::new_type (field.get_field_type ());
+      auto expr = default_call (std::move (type));
 
       cloned_fields.emplace_back (
        builder.struct_expr_field (std::move (name), std::move (expr)));
@@ -119,7 +120,7 @@ DeriveDefault::visit_tuple (TupleStruct &tuple_item)
 
   for (auto &field : tuple_item.get_fields ())
     {
-      auto type = field.get_field_type ().clone_type ();
+      auto type = Builder::new_type (field.get_field_type ());
 
       defaulted_fields.emplace_back (default_call (std::move (type)));
     }
index 5e7a8946dfdbf0378eef07bfe9574d0ae6c42307..04c987dc96e375f64c4bd89232cae63453ba71cb 100644 (file)
@@ -142,7 +142,10 @@ DeriveEq::visit_tuple (TupleStruct &item)
   auto types = std::vector<std::unique_ptr<Type>> ();
 
   for (auto &field : item.get_fields ())
-    types.emplace_back (field.get_field_type ().clone_type ());
+    {
+      auto type = Builder::new_type (field.get_field_type ());
+      types.emplace_back (std::move (type));
+    }
 
   expanded = eq_impls (assert_receiver_is_total_eq_fn (std::move (types)),
                       item.get_identifier ().as_string (),
@@ -155,7 +158,10 @@ DeriveEq::visit_struct (StructStruct &item)
   auto types = std::vector<std::unique_ptr<Type>> ();
 
   for (auto &field : item.get_fields ())
-    types.emplace_back (field.get_field_type ().clone_type ());
+    {
+      auto type = Builder::new_type (field.get_field_type ());
+      types.emplace_back (std::move (type));
+    }
 
   expanded = eq_impls (assert_receiver_is_total_eq_fn (std::move (types)),
                       item.get_identifier ().as_string (),
@@ -179,15 +185,20 @@ DeriveEq::visit_enum (Enum &item)
            auto &tuple = static_cast<EnumItemTuple &> (*variant);
 
            for (auto &field : tuple.get_tuple_fields ())
-             types.emplace_back (field.get_field_type ().clone_type ());
-
+             {
+               auto type = Builder::new_type (field.get_field_type ());
+               types.emplace_back (std::move (type));
+             }
            break;
          }
          case EnumItem::Kind::Struct: {
            auto &tuple = static_cast<EnumItemStruct &> (*variant);
 
            for (auto &field : tuple.get_struct_fields ())
-             types.emplace_back (field.get_field_type ().clone_type ());
+             {
+               auto type = Builder::new_type (field.get_field_type ());
+               types.emplace_back (std::move (type));
+             }
 
            break;
          }
@@ -205,7 +216,10 @@ DeriveEq::visit_union (Union &item)
   auto types = std::vector<std::unique_ptr<Type>> ();
 
   for (auto &field : item.get_variants ())
-    types.emplace_back (field.get_field_type ().clone_type ());
+    {
+      auto type = Builder::new_type (field.get_field_type ());
+      types.emplace_back (std::move (type));
+    }
 
   expanded = eq_impls (assert_receiver_is_total_eq_fn (std::move (types)),
                       item.get_identifier ().as_string (),
index 312964c6b1445a4d7001456bca3cf2a680acf2a2..d4e066a5f7234429642e8012f55689b42286088b 100644 (file)
@@ -6,8 +6,6 @@ pub_restricted_1.rs
 pub_restricted_2.rs
 pub_restricted_3.rs
 issue-2905-2.rs
-derive-default1.rs
-derive-eq-invalid.rs
 torture/alt_patterns1.rs
 torture/name_resolve1.rs
 issue-3671.rs