[gccrs COMMIT] gccrs: Fix deriving with generic const args

gerris.rs@gmail.com gerris.rs@gmail.com
Fri Jul 24 23:33:45 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>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: https://github.com/Rust-GCC/gccrs/commit/0fcbc90bccd36ba142e3e978e0c29c5b5711a323

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4715

 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 dbcdc8ad2..0b73d2411 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 000000000..bfec48a6d
--- /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]>
+}

base-commit: a29a82e68375cb41cce994c66ae62fa3848cb500
-- 
2.54.0



More information about the Gcc-rust mailing list