]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: derive(Copy): Improve bounds when deriving Copy
authorArthur Cohen <arthur.cohen@embecosm.com>
Thu, 16 Jan 2025 13:46:06 +0000 (14:46 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 24 Mar 2025 12:06:52 +0000 (13:06 +0100)
gcc/rust/ChangeLog:

* expand/rust-derive-copy.cc: Always add an extra Copy bound on generic Copy impls.

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

index 31b4819c042970d51518e8cdb9b590b014173c7d..1d5f72bd656c230deb89b5bf407986182c35489a 100644 (file)
@@ -52,7 +52,7 @@ DeriveCopy::copy_impl (
   // for example:
   //
   // #[derive(Copy)]
-  // struct Be<T: Copy> { ... }
+  // struct Be<T> { ... }
   //
   // we need to generate the impl block:
   //
@@ -87,7 +87,12 @@ DeriveCopy::copy_impl (
              = GenericArg::create_type (std::move (associated_type));
            generic_args.push_back (std::move (type_arg));
 
-           auto impl_type_param = builder.new_type_param (type_param);
+           std::vector<std::unique_ptr<TypeParamBound>> extra_bounds;
+           extra_bounds.emplace_back (std::unique_ptr<TypeParamBound> (
+             new TraitBound (builder.type_path (LangItem::Kind::COPY), loc)));
+
+           auto impl_type_param
+             = builder.new_type_param (type_param, std::move (extra_bounds));
            impl_generics.push_back (std::move (impl_type_param));
          }
          break;