diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-01-15 13:00:45 +0000 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2025-01-21 13:54:14 +0000 |
commit | 2d76d473f7b1f699ae939e6fa5cb821eebcd3881 (patch) | |
tree | e46723cf6bc2c7e258fa5bc15e22f922c141e22a /gcc | |
parent | c53c8d70e8dce2a400c1f3a01343f5d550ea3a03 (diff) | |
download | gcc-2d76d473f7b1f699ae939e6fa5cb821eebcd3881.zip gcc-2d76d473f7b1f699ae939e6fa5cb821eebcd3881.tar.gz gcc-2d76d473f7b1f699ae939e6fa5cb821eebcd3881.tar.bz2 |
derive(Clone): Add Clone bound on generated impl blocks
gcc/rust/ChangeLog:
* expand/rust-derive-clone.cc: Add extra bound when deriving generic Clone
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/expand/rust-derive-clone.cc | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc index e914d60..754d89c 100644 --- a/gcc/rust/expand/rust-derive-clone.cc +++ b/gcc/rust/expand/rust-derive-clone.cc @@ -97,15 +97,15 @@ DeriveClone::clone_impl ( auto trait_items = std::vector<std::unique_ptr<AssociatedItem>> (); trait_items.emplace_back (std::move (clone_fn)); - // we need to build up the generics for this impl block which will be just a - // clone of the types specified ones + // We need to build up the generics for this impl block which will be just a + // clone of the generics specified, with added `Clone` bounds // - // for example: + // For example with: // // #[derive(Clone)] - // struct Be<T: Clone> { ... } + // struct Be<T> { ... } // - // we need to generate the impl block: + // We need to generate the following impl block: // // impl<T: Clone> Clone for Be<T> @@ -138,7 +138,12 @@ DeriveClone::clone_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::CLONE), 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; |