https://gcc.gnu.org/g:edf3ebf6a1adb4461127a3cfa7285b7132733088
commit r17-5150-gedf3ebf6a1adb4461127a3cfa7285b7132733088 Author: Philip Herron <[email protected]> Date: Fri Sep 18 22:07:06 2026 +0100 gccrs: fix unconstrained check to look for constrained bindings 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]> Diff: --- gcc/rust/typecheck/rust-hir-type-check-base.cc | 11 ++++++++++ gcc/testsuite/rust/compile/issues/4911.rs | 29 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index 52a3536245a1..f5f457f60203 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 000000000000..229dbf5895fd --- /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() {}
