From: Philip Herron <[email protected]>

Fixes Rust-GCC/gccrs#4911

gcc/rust/ChangeLog:

        * typecheck/rust-hir-type-check-base.cc (walk_type_to_constrain): walk 
binding args

gcc/testsuite/ChangeLog:

        * rust/compile/issues/4911.rs: New test.

Signed-off-by: Philip Herron <[email protected]>
---
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/e0a7a91b661fe9361410739c230b7391e104fde0

The commit has been mentioned in the following issue(s):
 - Rust-GCC/gccrs#4911: https://github.com/Rust-GCC/gccrs/issues/4911

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

 .../typecheck/rust-hir-type-check-base.cc     | 11 +++++++
 gcc/testsuite/rust/compile/issues/4911.rs     | 29 +++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/issues/4911.rs

diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc 
b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index 52a353624..f5f457f60 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -170,6 +170,15 @@ walk_type_to_constrain (std::set<HirId> 
&constrained_symbols, TyTy::BaseType &r)
   if (r.has_substitutions_defined ())
     walk_types_to_constrain (constrained_symbols,
                             r.get_subst_argument_mappings ());
+
+  for (const auto &bound : r.get_specified_bounds ())
+    {
+      const auto &args = bound.get_substitution_arguments ();
+      for (const auto &binding : args.get_binding_args ())
+       walk_type_to_constrain (constrained_symbols, *binding.second);
+      for (const auto &constraint : args.get_constraint_args ())
+       walk_type_to_constrain (constrained_symbols, *constraint.second);
+    }
 }
 
 bool
@@ -209,6 +218,8 @@ TypeCheckBase::check_for_unconstrained (
          const auto &args = bound.get_substitution_arguments ();
          for (const auto &binding : args.get_binding_args ())
            walk_type_to_constrain (constrained_symbols, *binding.second);
+         for (const auto &constraint : args.get_constraint_args ())
+           walk_type_to_constrain (constrained_symbols, *constraint.second);
        }
     }
 
diff --git a/gcc/testsuite/rust/compile/issues/4911.rs 
b/gcc/testsuite/rust/compile/issues/4911.rs
new file mode 100644
index 000000000..229dbf589
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issues/4911.rs
@@ -0,0 +1,29 @@
+// { dg-options "-w" }
+#![feature(lang_items, no_core)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+pub trait Iterator2 {
+    type Item;
+}
+
+pub trait IntoIterator2 {
+    type IntoIter;
+    type Item;
+}
+
+pub struct Flatten<I: Iterator2<Item: IntoIterator2>> {
+    inner: I,
+}
+
+impl<I, U> Iterator2 for Flatten<I>
+where
+    I: Iterator2<Item: IntoIterator2<IntoIter = U, Item = U>>,
+    U: Iterator2,
+{
+    type Item = U;
+}
+
+fn main() {}
-- 
2.55.0

Reply via email to