]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Track associated type generics
authorPhilip Herron <herron.philip@googlemail.com>
Thu, 29 Jun 2023 09:13:29 +0000 (10:13 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:46:32 +0000 (18:46 +0100)
This fixes an issue with our qualified type-paths if we point to a generic
associated type this needs to either use the placeholder type on the trait
reference or use the impl-type but apply the generics.

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.h: update prototype
* typecheck/rust-hir-trait-resolve.cc: add generic args as an out param
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): use the generics

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/typecheck/rust-hir-trait-reference.h
gcc/rust/typecheck/rust-hir-trait-resolve.cc
gcc/rust/typecheck/rust-hir-type-check-type.cc

index c0a6f561ada27b2e13e6ed7bfdb534415e23fe1f..440a232a50e21cda4c061ba8ef85c97169010f50 100644 (file)
@@ -253,7 +253,8 @@ public:
 
   TyTy::BaseType *
   setup_associated_types (const TyTy::BaseType *self,
-                         const TyTy::TypeBoundPredicate &bound);
+                         const TyTy::TypeBoundPredicate &bound,
+                         TyTy::SubstitutionArgumentMappings *args = nullptr);
 
   void reset_associated_types ();
 
index a8a026a7f9ae686e6dba755db32d153d58b1e051..f72c6fc225a2c1046624d649ddfc65c29519a3db 100644 (file)
@@ -434,7 +434,8 @@ AssociatedImplTrait::setup_raw_associated_types ()
 
 TyTy::BaseType *
 AssociatedImplTrait::setup_associated_types (
-  const TyTy::BaseType *self, const TyTy::TypeBoundPredicate &bound)
+  const TyTy::BaseType *self, const TyTy::TypeBoundPredicate &bound,
+  TyTy::SubstitutionArgumentMappings *args)
 {
   // compute the constrained impl block generic arguments based on self and the
   // higher ranked trait bound
@@ -491,25 +492,27 @@ AssociatedImplTrait::setup_associated_types (
   // generate inference variables for these bound arguments so we can compute
   // their values
   Location locus;
-  std::vector<TyTy::SubstitutionArg> args;
+  std::vector<TyTy::SubstitutionArg> subst_args;
   for (auto &p : substitutions)
     {
       if (p.needs_substitution ())
        {
          TyTy::TyVar infer_var = TyTy::TyVar::get_implicit_infer_var (locus);
-         args.push_back (TyTy::SubstitutionArg (&p, infer_var.get_tyty ()));
+         subst_args.push_back (
+           TyTy::SubstitutionArg (&p, infer_var.get_tyty ()));
        }
       else
        {
          TyTy::ParamType *param = p.get_param_ty ();
          TyTy::BaseType *resolved = param->destructure ();
-         args.push_back (TyTy::SubstitutionArg (&p, resolved));
+         subst_args.push_back (TyTy::SubstitutionArg (&p, resolved));
          param_mappings[param->get_symbol ()] = resolved->get_ref ();
        }
     }
 
-  TyTy::SubstitutionArgumentMappings infer_arguments (std::move (args), {},
-                                                     locus, param_subst_cb);
+  TyTy::SubstitutionArgumentMappings infer_arguments (std::move (subst_args),
+                                                     {}, locus,
+                                                     param_subst_cb);
   TyTy::BaseType *impl_self_infer
     = (!associated_self->is_concrete ())
        ? SubstMapperInternal::Resolve (associated_self, infer_arguments)
@@ -632,6 +635,11 @@ AssociatedImplTrait::setup_associated_types (
       resolved_trait_item->associated_type_set (substituted);
     }
 
+  if (args != nullptr)
+    {
+      *args = associated_type_args;
+    }
+
   return self_result;
 }
 
index d309101d107a0ef2f1ee07a6390148c91b668c2f..c476edfb7a4d6826b5648f0fb03725b6f150bc94 100644 (file)
@@ -214,6 +214,8 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
     }
 
   // we try to look for the real impl item if possible
+  TyTy::SubstitutionArgumentMappings args
+    = TyTy::SubstitutionArgumentMappings::error ();
   HIR::ImplItem *impl_item = nullptr;
   if (root->is_concrete ())
     {
@@ -223,7 +225,8 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
        = lookup_associated_impl_block (specified_bound, root);
       if (associated_impl_trait != nullptr)
        {
-         associated_impl_trait->setup_associated_types (root, specified_bound);
+         associated_impl_trait->setup_associated_types (root, specified_bound,
+                                                        &args);
 
          for (auto &i :
               associated_impl_trait->get_impl_block ()->get_impl_items ())
@@ -262,6 +265,12 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
          return;
        }
 
+      if (!args.is_error ())
+       {
+         // apply the args
+         translated = SubstMapperInternal::Resolve (translated, args);
+       }
+
       root_resolved_node_id = impl_item->get_impl_mappings ().get_nodeid ();
     }