From 92b137048583c2c22c585097119dba6a5fe06228 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 4 Apr 2023 15:40:26 +0100 Subject: gccrs: Support fully qualified calls to trait items from CallExpr's Fixes #2070 gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): reuse resolve_method_address to monomorphize the call if required * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): allow matching against unimplemented trait item bounds gcc/testsuite/ChangeLog: * rust/compile/issue-2070.rs: New test. Signed-off-by: Philip Herron --- gcc/rust/backend/rust-compile-resolve-path.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index b7f1069..4814141 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -186,6 +186,7 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup, = ctx->get_mappings ()->lookup_hir_extern_item (ref, &parent_block); bool is_hir_item = resolved_item != nullptr; bool is_hir_extern_item = resolved_extern_item != nullptr; + bool is_fn = lookup->get_kind () == TyTy::TypeKind::FNDEF; if (is_hir_item) { if (!lookup->has_subsititions_defined ()) @@ -206,6 +207,21 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup, } else { + if (is_fn) + { + TyTy::FnType *fn = static_cast (lookup); + TyTy::BaseType *receiver = nullptr; + + if (fn->is_method ()) + { + receiver = fn->get_self_type (); + receiver = receiver->destructure (); + + return resolve_method_address (fn, ref, receiver, final_segment, + mappings, expr_locus); + } + } + HirId parent_impl_id = UNKNOWN_HIRID; HIR::ImplItem *resolved_item = ctx->get_mappings ()->lookup_hir_implitem (ref, &parent_impl_id); -- cgit v1.1