From 63f803074b5baf2e3e744d5a1ff97daf583c8110 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Thu, 16 Jan 2025 14:46:06 +0100 Subject: [PATCH] derive(Copy): Improve bounds when deriving Copy 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gcc/rust/expand/rust-derive-copy.cc b/gcc/rust/expand/rust-derive-copy.cc index 927d1c58407..64c7367e4a5 100644 --- a/gcc/rust/expand/rust-derive-copy.cc +++ b/gcc/rust/expand/rust-derive-copy.cc @@ -54,7 +54,7 @@ DeriveCopy::copy_impl ( // for example: // // #[derive(Copy)] - // struct Be { ... } + // struct Be { ... } // // we need to generate the impl block: // @@ -89,7 +89,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> extra_bounds; + extra_bounds.emplace_back (std::unique_ptr ( + 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;