diff options
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.cc | 19 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile.cc | 18 |
2 files changed, 16 insertions, 21 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 49a6f2f..2128f25 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -747,8 +747,9 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref, auto root = receiver->get_root (); std::vector<Resolver::PathProbeCandidate> candidates - = Resolver::PathProbeType::Probe (root, segment, true, false, true); - + = Resolver::PathProbeType::Probe (root, segment, true /* probe_impls */, + false /* probe_bounds */, + true /* ignore_mandatory_trait_items */); if (candidates.size () == 0) { // this means we are defaulting back to the trait_item if @@ -776,12 +777,22 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref, rust_assert (candidates.size () == 1); auto &candidate = candidates.at (0); rust_assert (candidate.is_impl_candidate ()); + rust_assert (candidate.ty->get_kind () == TyTy::TypeKind::FNDEF); + TyTy::FnType *candidate_call = static_cast<TyTy::FnType *> (candidate.ty); HIR::ImplItem *impl_item = candidate.item.impl.impl_item; - if (!fntype->has_subsititions_defined ()) + if (!candidate_call->has_subsititions_defined ()) return CompileInherentImplItem::Compile (impl_item, ctx); - return CompileInherentImplItem::Compile (impl_item, ctx, fntype); + TyTy::BaseType *monomorphized = candidate_call; + if (candidate_call->needs_generic_substitutions ()) + { + TyTy::BaseType *infer_impl_call + = candidate_call->infer_substitions (expr_locus); + monomorphized = infer_impl_call->unify (fntype); + } + + return CompileInherentImplItem::Compile (impl_item, ctx, monomorphized); } } diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 9e2c5b3..bd782b0 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -38,7 +38,6 @@ CompileCrate::~CompileCrate () {} void CompileCrate::Compile (HIR::Crate &crate, Context *ctx) - { CompileCrate c (crate, ctx); c.go (); @@ -383,26 +382,11 @@ HIRCompileBase::compute_address_for_trait_item ( = self_bound->lookup_associated_item (ref->get_identifier ()); rust_assert (!associated_self_item.is_error ()); - // apply any generic arguments from this predicate TyTy::BaseType *mono1 = associated_self_item.get_tyty_for_receiver (self); - TyTy::BaseType *mono2 = nullptr; - if (predicate->has_generic_args ()) - { - mono2 = associated_self_item.get_tyty_for_receiver ( - self, predicate->get_generic_args ()); - } - else - { - mono2 = associated_self_item.get_tyty_for_receiver (self); - } rust_assert (mono1 != nullptr); rust_assert (mono1->get_kind () == TyTy::TypeKind::FNDEF); TyTy::FnType *assocated_item_ty1 = static_cast<TyTy::FnType *> (mono1); - rust_assert (mono2 != nullptr); - rust_assert (mono2->get_kind () == TyTy::TypeKind::FNDEF); - TyTy::FnType *assocated_item_ty2 = static_cast<TyTy::FnType *> (mono2); - // Lookup the impl-block for the associated impl_item if it exists HIR::Function *associated_function = nullptr; for (auto &impl_item : associated_impl_block->get_impl_items ()) @@ -434,7 +418,7 @@ HIRCompileBase::compute_address_for_trait_item ( { TyTy::SubstitutionArgumentMappings mappings = assocated_item_ty1->solve_missing_mappings_from_this ( - *assocated_item_ty2, *lookup_fntype); + *trait_item_fntype, *lookup_fntype); lookup_fntype = lookup_fntype->handle_substitions (mappings); } |