From 68e24e2562e267f7ca42b6c7fc8b536b4a2459b3 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Mon, 3 Feb 2025 15:25:50 +0000 Subject: gccrs: Fix bad generic substitution error on fn/adt types When passing generics around we try to adjust them because there are cases where the names are adjusted from other generics this can fail for traits because of the implicit Self and we just need to continue on without adjustment. Fxies Rust-GCC#3382 gcc/rust/ChangeLog: * typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): continue on for trait item mode. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this. * rust/compile/issue-3382.rs: New test. Signed-off-by: Philip Herron --- gcc/rust/typecheck/rust-substitution-mapper.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'gcc/rust') diff --git a/gcc/rust/typecheck/rust-substitution-mapper.cc b/gcc/rust/typecheck/rust-substitution-mapper.cc index 394dfe4..49c4505 100644 --- a/gcc/rust/typecheck/rust-substitution-mapper.cc +++ b/gcc/rust/typecheck/rust-substitution-mapper.cc @@ -192,8 +192,10 @@ SubstMapperInternal::visit (TyTy::FnType &type) { TyTy::SubstitutionArgumentMappings adjusted = type.adjust_mappings_for_this (mappings); - if (adjusted.is_error ()) + if (adjusted.is_error () && !mappings.trait_item_mode ()) return; + if (adjusted.is_error () && mappings.trait_item_mode ()) + adjusted = mappings; TyTy::BaseType *concrete = type.handle_substitions (adjusted); if (concrete != nullptr) @@ -205,8 +207,10 @@ SubstMapperInternal::visit (TyTy::ADTType &type) { TyTy::SubstitutionArgumentMappings adjusted = type.adjust_mappings_for_this (mappings); - if (adjusted.is_error ()) + if (adjusted.is_error () && !mappings.trait_item_mode ()) return; + if (adjusted.is_error () && mappings.trait_item_mode ()) + adjusted = mappings; TyTy::BaseType *concrete = type.handle_substitions (adjusted); if (concrete != nullptr) -- cgit v1.1