https://gcc.gnu.org/g:528ade2725ca483eca4111327ed972d6f7488ba1

commit r17-5153-g528ade2725ca483eca4111327ed972d6f7488ba1
Author: Utkarsh Bahuguna <[email protected]>
Date:   Mon Sep 21 11:24:13 2026 +0530

    gccrs: Handle FUNCTION segments in new_type_param
    
    Fn/FnMut/FnOnce bounds can produce FUNCTION segments, which
    new_type_param did not handle.
    
    Use reconstruct() for these segments instead of hitting
    rust_unreachable().
    
    Fixes Rust-GCC/gccrs#3939
    
    gcc/rust/ChangeLog:
    
            * ast/rust-ast-builder.cc (Builder::new_type_param): Handle
            FUNCTION segments.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issues/3939.rs: New test.
    
    Signed-off-by: Utkarsh Bahuguna <[email protected]>

Diff:
---
 gcc/rust/ast/rust-ast-builder.cc          |  7 +------
 gcc/testsuite/rust/compile/issues/3939.rs | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 6332ce2f5c92..09db66957d96 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -654,12 +654,7 @@ Builder::new_type_param (
                    break;
 
                  case TypePathSegment::FUNCTION:
-                   {
-                     rust_unreachable ();
-                     // TODO
-                     // const TypePathSegmentFunction &fn
-                     //   = (const TypePathSegmentFunction &) (*seg.get ());
-                   }
+                   segments.emplace_back (seg->reconstruct ());
                    break;
                  }
              }
diff --git a/gcc/testsuite/rust/compile/issues/3939.rs 
b/gcc/testsuite/rust/compile/issues/3939.rs
new file mode 100644
index 000000000000..da253d9b646a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issues/3939.rs
@@ -0,0 +1,30 @@
+#![feature(no_core)]
+#![feature(lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+trait Sized {}
+
+#[lang = "copy"]
+trait Copy {}
+
+#[lang = "fn_once"]
+trait FnOnce<Args> {
+    #[lang = "fn_once_output"]
+    type Output;
+
+    fn call_once(self, args: Args) -> Self::Output;
+}
+
+#[lang = "fn_mut"]
+trait FnMut<Args>: FnOnce<Args> {
+    fn call_mut(&mut self, args: Args) -> Self::Output;
+}
+
+#[lang = "fn"]
+trait Fn<Args>: FnMut<Args> {
+    fn call(&self, args: Args) -> Self::Output;
+}
+
+#[derive(Copy)]
+pub struct X<T, F: Fn(T) -> T>(T, F);

Reply via email to