diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-01-02 10:56:11 +0000 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2025-01-20 12:09:26 +0000 |
commit | 0c52c4c271dbde15541f495977ae9f9b14c49ef9 (patch) | |
tree | dc28004ed8d11af8a036f80b081b8be5719ed83e | |
parent | e8d3ccf05dce82d682649865a8e5fc61b92fc2d4 (diff) | |
download | gcc-0c52c4c271dbde15541f495977ae9f9b14c49ef9.zip gcc-0c52c4c271dbde15541f495977ae9f9b14c49ef9.tar.gz gcc-0c52c4c271dbde15541f495977ae9f9b14c49ef9.tar.bz2 |
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.
-rw-r--r-- | gcc/rust/expand/rust-derive-clone.cc | 14 |
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 aefc64c..2cabb72 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)); |