From: Philip Herron <[email protected]>

Fixes Rust-GCC/gccrs#4883

gcc/rust/ChangeLog:

        * typecheck/rust-hir-type-check-base.cc (walk_type_to_constrain): walk 
the generics as well

gcc/testsuite/ChangeLog:

        * rust/compile/issues/issue-4883.rs: New test.

Signed-off-by: Philip Herron <[email protected]>

Tested on x86_64-pc-linux-gnu.

---
 .../typecheck/rust-hir-type-check-base.cc     |  4 ++
 .../rust/compile/issues/issue-4883.rs         | 46 +++++++++++++++++++
 2 files changed, 50 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/issues/issue-4883.rs

diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc 
b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index c9e392039a3..52a3536245a 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -166,6 +166,10 @@ walk_type_to_constrain (std::set<HirId> 
&constrained_symbols, TyTy::BaseType &r)
     default:
       break;
     }
+
+  if (r.has_substitutions_defined ())
+    walk_types_to_constrain (constrained_symbols,
+                            r.get_subst_argument_mappings ());
 }
 
 bool
diff --git a/gcc/testsuite/rust/compile/issues/issue-4883.rs 
b/gcc/testsuite/rust/compile/issues/issue-4883.rs
new file mode 100644
index 00000000000..560290c6465
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issues/issue-4883.rs
@@ -0,0 +1,46 @@
+// { dg-options "-w" }
+#![feature(no_core, lang_items, unboxed_closures)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+pub trait Iterator2 {
+    type Item;
+}
+
+#[lang = "fn_once"]
+#[rustc_paren_sugar]
+pub trait FnOnce<Args> {
+    #[lang = "fn_once_output"]
+    type Output;
+
+    extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+#[lang = "fn_mut"]
+#[rustc_paren_sugar]
+pub trait FnMut<Args>: FnOnce<Args> {
+    extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
+}
+
+pub struct FilterMap<I, F> {
+    iter: I,
+    f: F,
+}
+
+impl<B, I: Iterator2, F> Iterator2 for FilterMap<I, F>
+where
+    F: FnMut(I::Item) -> Option<B>,
+{
+    type Item = B;
+}
+
+pub enum Option<T> {
+    None,
+    Some(T),
+}
+
+fn main() -> i32 {
+    0
+}
-- 
2.55.0

Reply via email to