diff options
author | Philip Herron <herron.philip@googlemail.com> | 2025-07-31 21:29:02 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-08-05 16:37:01 +0200 |
commit | ad8393db6b492358028367d27b4f3b918dd7a7c0 (patch) | |
tree | 44f6340d307c36efc7e265f874183f0494900bfa | |
parent | 13d6c61231e82c6fdaf666924199fd519877f4f0 (diff) | |
download | gcc-ad8393db6b492358028367d27b4f3b918dd7a7c0.zip gcc-ad8393db6b492358028367d27b4f3b918dd7a7c0.tar.gz gcc-ad8393db6b492358028367d27b4f3b918dd7a7c0.tar.bz2 |
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 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.philip@googlemail.com>
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-subst.cc | 6 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-3546.rs | 16 |
2 files changed, 19 insertions, 3 deletions
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index a47cde3..45c8cd6 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 0000000..d4ec0bb --- /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 } |