From dbf5ab5257fa4535585fb41794b6a86a5c74d637 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 3 Sep 2016 14:59:48 +0800 Subject: HIR Typecheck - Search for type impls in other crates too --- src/hir_typeck/expr_cs.cpp | 1 + src/hir_typeck/helpers.cpp | 46 ++++++++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index eff5cc53..194834a8 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -341,6 +341,7 @@ namespace { // TODO: Either - Don't include the above impl bound, or change the below trait to the one that has that type for( const auto& assoc : be.trait.m_type_bounds ) { ::HIR::GenericPath type_trait_path; + ASSERT_BUG(sp, be.trait.m_trait_ptr, "Trait pointer not set in " << be.trait.m_path); context.m_resolve.trait_contains_type(sp, real_trait, *be.trait.m_trait_ptr, assoc.first, type_trait_path); auto other_ty = monomorphise_type_with(sp, assoc.second, cache.m_monomorph_cb, true); diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp index 6d382409..ec62bcfe 100644 --- a/src/hir_typeck/helpers.cpp +++ b/src/hir_typeck/helpers.cpp @@ -2220,31 +2220,33 @@ bool TraitResolution::find_method(const Span& sp, const HIR::t_trait_list& trait } else { // 2. Search for inherent methods - for(const auto& impl : m_crate.m_type_impls) - { - if( impl.matches_type(ty) ) { - auto it = impl.m_methods.find( method_name ); - if( it == impl.m_methods.end() ) - continue ; - const ::HIR::Function& fcn = it->second.data; - switch(fcn.m_receiver) - { - case ::HIR::Function::Receiver::Free: + bool rv = m_crate.find_type_impls(ty, m_ivars.callback_resolve_infer(), [&](const auto& impl) { + auto it = impl.m_methods.find( method_name ); + if( it == impl.m_methods.end() ) + return false ; + const ::HIR::Function& fcn = it->second.data; + switch(fcn.m_receiver) + { + case ::HIR::Function::Receiver::Free: + break; + case ::HIR::Function::Receiver::Value: + if( !allow_move ) break; - case ::HIR::Function::Receiver::Value: - if( !allow_move ) - break; - default: - DEBUG("Matching `impl" << impl.m_params.fmt_args() << " " << impl.m_type << "`"/* << " - " << top_ty*/); - fcn_path = ::HIR::Path( ::HIR::Path::Data::make_UfcsInherent({ - box$(ty.clone()), - method_name, - {} - }) ); - return true; - } + default: + DEBUG("Matching `impl" << impl.m_params.fmt_args() << " " << impl.m_type << "`"/* << " - " << top_ty*/); + fcn_path = ::HIR::Path( ::HIR::Path::Data::make_UfcsInherent({ + box$(ty.clone()), + method_name, + {} + }) ); + return true; } + return false; + }); + if( rv ) { + return true; } + // 3. Search for trait methods (using currently in-scope traits) for(const auto& trait_ref : ::reverse(traits)) { -- cgit v1.2.3