[gcc/devel/rust/master] derive(Clone): Use lang item bounds on AssertParamIsCopy
Thomas Schwinge
tschwinge@gcc.gnu.org
Wed Mar 26 14:07:32 GMT 2025
https://gcc.gnu.org/g:1f39e0f2cbe23d46b805f976db0807e5aa27d362
commit 1f39e0f2cbe23d46b805f976db0807e5aa27d362
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Mon Jan 20 11:36:53 2025 +0000
derive(Clone): Use lang item bounds on AssertParamIsCopy
gcc/rust/ChangeLog:
* expand/rust-derive-clone.cc (DeriveClone::visit_union): Use lang items for Copy and
Sized bounds.
gcc/testsuite/ChangeLog:
* rust/compile/derive_macro6.rs: Add lang item attribute to Copy trait.
Diff:
---
gcc/rust/expand/rust-derive-clone.cc | 11 +++++------
gcc/testsuite/rust/compile/derive_macro6.rs | 2 +-
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc
index 754d89cd84df..6ee83a72b531 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -422,17 +422,16 @@ DeriveClone::visit_union (Union &item)
// FIXME: Should be $crate::core::clone::AssertParamIsCopy (or similar)
// (Rust-GCC#3329)
- auto copy_path = TypePath (vec (builder.type_path_segment ("Copy")), loc);
- auto sized_path = TypePath (vec (builder.type_path_segment ("Sized")), loc);
+ auto copy_path = builder.type_path (LangItem::Kind::COPY);
+ auto sized_path = builder.type_path (LangItem::Kind::SIZED);
auto copy_bound = std::unique_ptr<TypeParamBound> (
new TraitBound (copy_path, item.get_locus ()));
auto sized_bound = std::unique_ptr<TypeParamBound> (
- new TraitBound (sized_path, item.get_locus (), false, true));
+ new TraitBound (sized_path, item.get_locus (), false,
+ true /* opening_question_mark */));
- auto bounds = std::vector<std::unique_ptr<TypeParamBound>> ();
- bounds.emplace_back (std::move (copy_bound));
- bounds.emplace_back (std::move (sized_bound));
+ auto bounds = vec (std::move (copy_bound), std::move (sized_bound));
// struct AssertParamIsCopy<T: Copy + ?Sized> { _t: PhantomData<T> }
auto assert_param_is_copy = "AssertParamIsCopy";
diff --git a/gcc/testsuite/rust/compile/derive_macro6.rs b/gcc/testsuite/rust/compile/derive_macro6.rs
index 35327c03b54c..412144d5917a 100644
--- a/gcc/testsuite/rust/compile/derive_macro6.rs
+++ b/gcc/testsuite/rust/compile/derive_macro6.rs
@@ -1,9 +1,9 @@
#[lang = "sized"]
pub trait Sized {}
+#[lang = "copy"]
pub trait Copy {}
-
#[lang = "clone"]
pub trait Clone {
fn clone(&self) -> Self;
More information about the Gcc-cvs
mailing list