aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2025-01-02 10:56:11 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-21 12:57:51 +0100
commit72ad259a22c182756b883871285f7c30e7c778cb (patch)
treea0d4d0940db9321dcf9aaa83f09d654b038fc683 /gcc
parentd8c11ccefb48e600264f530df505ba96fa7d0835 (diff)
downloadgcc-72ad259a22c182756b883871285f7c30e7c778cb.zip
gcc-72ad259a22c182756b883871285f7c30e7c778cb.tar.gz
gcc-72ad259a22c182756b883871285f7c30e7c778cb.tar.bz2
gccrs: derive(Clone): Add note about Clone::clone()
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::clone_call): Mention using `clone_fn` lang item in the future.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/expand/rust-derive-clone.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc
index 2f733fa..b8c92dc 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -30,6 +30,15 @@ DeriveClone::clone_call (std::unique_ptr<Expr> &&to_clone)
// $crate::core::clone::Clone::clone for the fully qualified path - we don't
// link with `core` yet so that might be an issue. Use `Clone::clone` for now?
// TODO: Factor this function inside the DeriveAccumulator
+
+ // Interestingly, later versions of Rust have a `clone_fn` lang item which
+ // corresponds to this. But because we are first targeting 1.49, we cannot use
+ // it yet. Once we target a new, more recent version of the language, we'll
+ // have figured out how to compile and distribute `core`, meaning we'll be
+ // able to directly call `::core::clone::Clone::clone()`
+
+ // Not sure how to call it properly in the meantime...
+
auto path = std::unique_ptr<Expr> (
new PathInExpression (builder.path_in_expression ({"Clone", "clone"})));
@@ -79,10 +88,7 @@ DeriveClone::clone_impl (
std::unique_ptr<AssociatedItem> &&clone_fn, std::string name,
const std::vector<std::unique_ptr<GenericParam>> &type_generics)
{
- // should that be `$crate::core::clone::Clone` instead?
- auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
- segments.emplace_back (builder.type_path_segment ("Clone"));
- auto clone = TypePath (std::move (segments), loc);
+ auto clone = builder.type_path (LangItem::Kind::CLONE);
auto trait_items = std::vector<std::unique_ptr<AssociatedItem>> ();
trait_items.emplace_back (std::move (clone_fn));