https://gcc.gnu.org/g:35f841b5a84fafb934550d964a258f626d19d013
commit r17-4344-g35f841b5a84fafb934550d964a258f626d19d013 Author: Philip Herron <[email protected]> Date: Tue Sep 8 11:22:27 2026 +0100 gccrs: walk the binding generic arguments for unconstrained checks Fixes Rust-GCC/gccrs#4862 Fixes Rust-GCC/gccrs#4863 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc: walk type bindings gcc/testsuite/ChangeLog: * rust/compile/issue-4862.rs: New test. * rust/compile/issue-4863.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/issue-4862.rs | 11 +++++++++++ gcc/testsuite/rust/compile/issue-4863.rs | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index b53232a57e52..faa6d5ea98ee 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc @@ -197,6 +197,17 @@ TypeCheckBase::check_for_unconstrained ( walk_types_to_constrain (constrained_symbols, constraint_b); walk_type_to_constrain (constrained_symbols, *reference); + for (const auto ¶m : params_to_constrain) + { + auto *ty = param.get_param_ty (); + for (const auto &bound : ty->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); + } + } + // check for unconstrained bool unconstrained = false; for (auto &sym : symbols_to_constrain) diff --git a/gcc/testsuite/rust/compile/issue-4862.rs b/gcc/testsuite/rust/compile/issue-4862.rs new file mode 100644 index 000000000000..17d9c3ca9775 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-4862.rs @@ -0,0 +1,11 @@ +#![feature(no_core, lang_items)] +#![no_core] +#[lang = "sized"] +pub trait Sized {} +trait Iterator { + type Item; +} +pub struct Wrapper<I>(I); +impl<T, I: Iterator<Item = T>> Iterator for Wrapper<I> { + type Item = T; +} diff --git a/gcc/testsuite/rust/compile/issue-4863.rs b/gcc/testsuite/rust/compile/issue-4863.rs new file mode 100644 index 000000000000..2c7592790c43 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-4863.rs @@ -0,0 +1,19 @@ +#![feature(no_core, lang_items)] +#![no_core] +#[lang = "sized"] +pub trait Sized {} +#[lang = "fn_once"] +trait FnOnce<Args> { + #[lang = "fn_once_output"] + type Output; + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} +trait Iterator { + type Item; +} +pub struct OnceWith<F> { + pub f: F, +} +impl<A, F: FnOnce() -> A> Iterator for OnceWith<F> { + type Item = A; +}
