Skip to content

Commit eefda40

Browse files
committed
gccrs: Fix ICE when extra const arguments supplied
The substitution code was not taking into account the const generic arguments for checking the max bounds of total available parameters. Fixes #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 <[email protected]>
1 parent 14798ca commit eefda40

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

gcc/rust/typecheck/rust-tyty-subst.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,9 @@ SubstitutionRef::get_mappings_from_generic_args (
705705

706706
// for inherited arguments
707707
size_t offs = used_arguments.size ();
708-
if (args.get_type_args ().size () + offs > substitutions.size ())
708+
size_t total_arguments
709+
= args.get_type_args ().size () + args.get_const_args ().size () + offs;
710+
if (total_arguments > substitutions.size ())
709711
{
710712
rich_location r (line_table, args.get_locus ());
711713
if (!substitutions.empty ())
@@ -723,8 +725,6 @@ SubstitutionRef::get_mappings_from_generic_args (
723725
return SubstitutionArgumentMappings::error ();
724726
}
725727

726-
size_t total_arguments
727-
= args.get_type_args ().size () + args.get_const_args ().size () + offs;
728728
if (total_arguments < min_required_substitutions ())
729729
{
730730
rich_location r (line_table, args.get_locus ());
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const L: usize = 3;
2+
3+
fn main() {
4+
let p = Printer {};
5+
p.print();
6+
}
7+
8+
trait Print<const N: usize> {
9+
fn print(&self) -> usize {
10+
3
11+
}
12+
}
13+
14+
struct Printer {}
15+
impl Print<L> for Printer {}
16+
// { dg-error "generic item takes at most 1 type arguments but 1 were supplied" "" { target *-*-* } .-1 }

0 commit comments

Comments
 (0)