[COMMITTED 57/77] gccrs: Fix deriving with generic const args
arthur.cohen@embecosm.com
arthur.cohen@embecosm.com
Fri Aug 7 12:39:48 GMT 2026
From: Owen Avery <powerboat9.gamer@gmail.com>
This doesn't fix an issue with the typechecker, so the included test
only compiles up to the typechecking phase.
gcc/rust/ChangeLog:
* expand/rust-derive.cc (DeriveVisitor::setup_impl_generics):
Create a constant generic argument from a constant generic
parameter.
gcc/testsuite/ChangeLog:
* rust/compile/derive_macro9.rs: New test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/expand/rust-derive.cc | 14 ++++++----
gcc/testsuite/rust/compile/derive_macro9.rs | 31 +++++++++++++++++++++
2 files changed, 39 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/derive_macro9.rs
diff --git a/gcc/rust/expand/rust-derive.cc b/gcc/rust/expand/rust-derive.cc
index dbcdc8ad2d4..0b73d241173 100644
--- a/gcc/rust/expand/rust-derive.cc
+++ b/gcc/rust/expand/rust-derive.cc
@@ -143,12 +143,14 @@ DeriveVisitor::setup_impl_generics (
ConstGenericParam &const_param
= (ConstGenericParam &) *generic.get ();
- std::unique_ptr<Type> associated_type
- = builder.single_type_path (const_param.get_name ().as_string ());
-
- GenericArg type_arg
- = GenericArg::create_type (std::move (associated_type));
- generic_args.push_back (std::move (type_arg));
+ auto associated_expr
+ = std::make_unique<IdentifierExpr> (const_param.get_name (),
+ std::vector<Attribute> (),
+ const_param.get_locus ());
+
+ GenericArg const_arg
+ = GenericArg::create_const (std::move (associated_expr));
+ generic_args.push_back (std::move (const_arg));
auto impl_const_param = builder.new_const_param (const_param);
impl_generics.push_back (std::move (impl_const_param));
diff --git a/gcc/testsuite/rust/compile/derive_macro9.rs b/gcc/testsuite/rust/compile/derive_macro9.rs
new file mode 100644
index 00000000000..bfec48a6d94
--- /dev/null
+++ b/gcc/testsuite/rust/compile/derive_macro9.rs
@@ -0,0 +1,31 @@
+// { dg-additional-options "-frust-compile-until=typecheck" }
+#![feature(no_core)]
+#![no_core]
+
+#![feature(lang_items)]
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "copy"]
+pub trait Copy {}
+
+#[lang = "clone"]
+pub trait Clone {
+ fn clone(&self) -> Self;
+}
+
+#[lang = "phantom_data"]
+pub struct PhantomData<T>;
+
+impl<T: ?Sized> Clone for PhantomData<T> {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+
+impl<T: ?Sized> Copy for PhantomData<T> {}
+
+#[derive(Copy, Clone)]
+struct S<const N: usize> {
+ x: PhantomData<[u8; N]>
+}
--
2.50.1
More information about the Gcc-rust
mailing list