]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: derive(Clone): Add note about Clone::clone()
authorArthur Cohen <arthur.cohen@embecosm.com>
Thu, 2 Jan 2025 10:56:11 +0000 (10:56 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 21 Mar 2025 11:57:51 +0000 (12:57 +0100)
gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::clone_call): Mention using `clone_fn`
lang item in the future.

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

index 2f733fae9107d9ef7312cec51a26289bb9d5df0b..b8c92dcc6feb39cd8753274556a63e0d1df2005d 100644 (file)
@@ -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));