From: Philip Herron Date: Sat, 17 Jan 2026 20:47:29 +0000 (+0000) Subject: gccrs: Optionally pull in the inherited arguments when required X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4bf6e043814858363f4189fc15faeaeacd16d8a;p=thirdparty%2Fgcc.git gccrs: Optionally pull in the inherited arguments when required gcc/rust/ChangeLog: * typecheck/rust-tyty-subst.cc: we can optionally apply inherited arguments gcc/testsuite/ChangeLog: * rust/compile/gat2.rs: New test. Signed-off-by: Philip Herron --- diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index f3873b8e684..6ee2a60dfe7 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -706,10 +706,16 @@ SubstitutionRef::get_mappings_from_generic_args ( } } - // for inherited arguments - size_t offs = used_arguments.size (); + // check if we need to use inherited arguments or nothing + size_t offs = 0; size_t total_arguments - = args.get_type_args ().size () + args.get_const_args ().size () + offs; + = args.get_type_args ().size () + args.get_const_args ().size (); + if (total_arguments < substitutions.size ()) + { + offs = used_arguments.size (); + total_arguments += offs; + } + if (total_arguments > substitutions.size ()) { rich_location r (line_table, args.get_locus ()); diff --git a/gcc/testsuite/rust/compile/gat2.rs b/gcc/testsuite/rust/compile/gat2.rs new file mode 100644 index 00000000000..2aead485ce2 --- /dev/null +++ b/gcc/testsuite/rust/compile/gat2.rs @@ -0,0 +1,33 @@ +#![feature(lang_items)] + +#[lang = "sized"] +trait Sized {} + +pub enum Option { + Some(T), + None, +} + +trait Foo { + type Bar; + + fn foo(self) -> Self::Bar; +} + +impl Foo for i32 { + type Bar = Option; + + fn foo(self) -> Self::Bar { + Option::None + } +} + +pub fn main() -> i32 { + let a = 15; + let res: Option = a.foo::(); + + match res { + Option::None => 0, + Option::Some(_) => 1, + } +}