From: Arthur Cohen Date: Thu, 2 Jan 2025 10:56:11 +0000 (+0000) Subject: gccrs: derive(Clone): Add note about Clone::clone() X-Git-Tag: basepoints/gcc-16~919 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72ad259a22c182756b883871285f7c30e7c778cb;p=thirdparty%2Fgcc.git 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. --- diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc index 2f733fae910..b8c92dcc6fe 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 &&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 ( new PathInExpression (builder.path_in_expression ({"Clone", "clone"}))); @@ -79,10 +88,7 @@ DeriveClone::clone_impl ( std::unique_ptr &&clone_fn, std::string name, const std::vector> &type_generics) { - // should that be `$crate::core::clone::Clone` instead? - auto segments = std::vector> (); - 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> (); trait_items.emplace_back (std::move (clone_fn));