From: Philip Herron <herron.phi...@googlemail.com> The substitution code was not taking into account the const generic arguments for checking the max bounds of total available parameters.
Fixes Rust-GCC#3546 gcc/rust/ChangeLog: * typecheck/rust-tyty-subst.cc: fix check for total arguments gcc/testsuite/ChangeLog: * rust/compile/issue-3546.rs: New test. Signed-off-by: Philip Herron <herron.phi...@googlemail.com> --- gcc/rust/typecheck/rust-tyty-subst.cc | 6 +++--- gcc/testsuite/rust/compile/issue-3546.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-3546.rs diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index a47cde3b966..45c8cd638eb 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -705,7 +705,9 @@ SubstitutionRef::get_mappings_from_generic_args ( // for inherited arguments size_t offs = used_arguments.size (); - if (args.get_type_args ().size () + offs > substitutions.size ()) + size_t total_arguments + = args.get_type_args ().size () + args.get_const_args ().size () + offs; + if (total_arguments > substitutions.size ()) { rich_location r (line_table, args.get_locus ()); if (!substitutions.empty ()) @@ -723,8 +725,6 @@ SubstitutionRef::get_mappings_from_generic_args ( return SubstitutionArgumentMappings::error (); } - size_t total_arguments - = args.get_type_args ().size () + args.get_const_args ().size () + offs; if (total_arguments < min_required_substitutions ()) { rich_location r (line_table, args.get_locus ()); diff --git a/gcc/testsuite/rust/compile/issue-3546.rs b/gcc/testsuite/rust/compile/issue-3546.rs new file mode 100644 index 00000000000..d4ec0bbd435 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3546.rs @@ -0,0 +1,16 @@ +const L: usize = 3; + +fn main() { + let p = Printer {}; + p.print(); +} + +trait Print<const N: usize> { + fn print(&self) -> usize { + 3 + } +} + +struct Printer {} +impl Print<L> for Printer {} +// { dg-error "generic item takes at most 1 type arguments but 1 were supplied" "" { target *-*-* } .-1 } -- 2.49.0