From: Utkarsh Bahuguna <[email protected]>
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]>
Tested on x86_64-pc-linux-gnu.
---
gcc/rust/ast/rust-ast-builder.cc | 7 +-----
gcc/testsuite/rust/compile/issues/3939.rs | 30 +++++++++++++++++++++++
2 files changed, 31 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issues/3939.rs
diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 6332ce2f5c9..09db66957d9 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 00000000000..da253d9b646
--- /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);
--
2.55.0