aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-resolve-path.cc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-08-17 17:28:15 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-08-19 15:39:21 +0100
commit1dc718474044149ec1aa6bee9ea8e83d778f17f2 (patch)
tree688bcd5d3a550681afaa87b90c848f365d425bcb /gcc/rust/backend/rust-compile-resolve-path.cc
parentc25cdc84600e81bfd4d1ae104ff9eb524f7c49f0 (diff)
downloadgcc-1dc718474044149ec1aa6bee9ea8e83d778f17f2.zip
gcc-1dc718474044149ec1aa6bee9ea8e83d778f17f2.tar.gz
gcc-1dc718474044149ec1aa6bee9ea8e83d778f17f2.tar.bz2
optional trait item with associated types
Diffstat (limited to 'gcc/rust/backend/rust-compile-resolve-path.cc')
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc49
1 files changed, 27 insertions, 22 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index 97ba15d..1b892d2 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -76,6 +76,7 @@ ResolvePathRef::visit (HIR::PathInExpression &expr)
&lookup);
rust_assert (ok);
rust_assert (lookup->get_kind () == TyTy::TypeKind::FNDEF);
+ TyTy::FnType *fntype = static_cast<TyTy::FnType *> (lookup);
Bfunction *fn = nullptr;
if (!ctx->lookup_function_decl (lookup->get_ty_ref (), &fn))
@@ -145,28 +146,32 @@ ResolvePathRef::visit (HIR::PathInExpression &expr)
rust_assert (
trait_item_ref->is_optional ()); // has definition
- // FIXME
- // TyTy::BaseType *self_type = nullptr;
- // if (!ctx->get_tyctx ()->lookup_type (
- // expr.get_receiver ()->get_mappings ().get_hirid (),
- // &self_type))
- // {
- // rust_error_at (expr.get_locus (),
- // "failed to resolve type for self param");
- // return;
- // }
-
- // CompileTraitItem::Compile (
- // self_type, trait_item_ref->get_hir_trait_item (), ctx,
- // fntype);
- // if (!ctx->lookup_function_decl (fntype->get_ty_ref (),
- // &fn))
- // {
- // translated = ctx->get_backend ()->error_expression ();
- // rust_error_at (expr.get_locus (),
- // "forward declaration was not compiled");
- // return;
- // }
+ Analysis::NodeMapping trait_mappings
+ = trait_item_ref->get_parent_trait_mappings ();
+ auto associated_impl_id
+ = ctx->get_tyctx ()
+ ->lookup_associated_impl_mapping_for_self (
+ trait_mappings.get_hirid (), receiver);
+ rust_assert (associated_impl_id != UNKNOWN_HIRID);
+
+ Resolver::AssociatedImplTrait *associated = nullptr;
+ bool found_associated_trait_impl
+ = ctx->get_tyctx ()->lookup_associated_trait_impl (
+ associated_impl_id, &associated);
+ rust_assert (found_associated_trait_impl);
+ associated->setup_associated_types ();
+
+ CompileTraitItem::Compile (
+ receiver, trait_item_ref->get_hir_trait_item (), ctx,
+ fntype);
+
+ if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &fn))
+ {
+ resolved = ctx->get_backend ()->error_expression ();
+ rust_error_at (expr.get_locus (),
+ "forward declaration was not compiled");
+ return;
+ }
}
else
{