[gcc r17-3116] gccrs: Fix deriving with generic const args

Arthur Cohen via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:00f557f225b5ba25fcc7ff664a20594988638019

commit r17-3116-g00f557f225b5ba25fcc7ff664a20594988638019
Author: Owen Avery <[email protected]>
Date:   Mon Jul 20 23:05:55 2026 -0400

    gccrs: Fix deriving with generic const args
    
    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 <[email protected]>

Diff:
---
 gcc/rust/expand/rust-derive.cc              | 14 +++++++------
 gcc/testsuite/rust/compile/derive_macro9.rs | 31 +++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/expand/rust-derive.cc b/gcc/rust/expand/rust-derive.cc
index dbcdc8ad2d4e..0b73d241173f 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 000000000000..bfec48a6d949
--- /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]>
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.