Skip to content

Commit

Permalink
derive(Copy): Improve bounds when deriving Copy
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* expand/rust-derive-copy.cc: Always add an extra Copy bound on generic Copy impls.
  • Loading branch information
CohenArthur committed Jan 16, 2025
1 parent bb58003 commit 63f8030
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions gcc/rust/expand/rust-derive-copy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ DeriveCopy::copy_impl (
// for example:
//
// #[derive(Copy)]
// struct Be<T: Copy> { ... }
// struct Be<T> { ... }
//
// we need to generate the impl block:
//
Expand Down Expand Up @@ -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<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;
Expand Down

0 comments on commit 63f8030

Please sign in to comment.