aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-06-29 10:13:29 +0100
committerPhilip Herron <philip.herron@embecosm.com>2023-06-29 15:38:44 +0000
commiteb88e324cde1e832dc6f3a5932aef9ee8e7abf6a (patch)
treed337b12ce226abdee39c206b877dfeeb1170ab78
parent2ddf542ed6710dd428ef810c1c2c618d4bd55388 (diff)
downloadgcc-eb88e324cde1e832dc6f3a5932aef9ee8e7abf6a.zip
gcc-eb88e324cde1e832dc6f3a5932aef9ee8e7abf6a.tar.gz
gcc-eb88e324cde1e832dc6f3a5932aef9ee8e7abf6a.tar.bz2
gccrs: Track associated type generics
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>
-rw-r--r--gcc/rust/typecheck/rust-hir-trait-reference.h3
-rw-r--r--gcc/rust/typecheck/rust-hir-trait-resolve.cc20
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-type.cc11
3 files changed, 26 insertions, 8 deletions
diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h b/gcc/rust/typecheck/rust-hir-trait-reference.h
index 91621a2..da69f66 100644
--- a/gcc/rust/typecheck/rust-hir-trait-reference.h
+++ b/gcc/rust/typecheck/rust-hir-trait-reference.h
@@ -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 ();
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 1022d6f..377f8d4 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -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;
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 905ff77..d5c910b 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -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 ();
}