summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hir_typeck/helpers.cpp26
-rw-r--r--src/hir_typeck/static.cpp15
2 files changed, 35 insertions, 6 deletions
diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp
index f751fe2b..f3d29a46 100644
--- a/src/hir_typeck/helpers.cpp
+++ b/src/hir_typeck/helpers.cpp
@@ -1382,7 +1382,6 @@ void TraitResolution::expand_associated_types__UfcsKnown(const Span& sp, ::HIR::
*pe.type = expand_associated_types(sp, mv$(*pe.type));
-
// - If it's a closure, then the only trait impls are those generated by typeck
TU_IFLET(::HIR::TypeRef::Data, pe.type->m_data, Closure, te,
const auto trait_fn = this->m_crate.get_lang_item_path(sp, "fn");
@@ -1402,7 +1401,6 @@ void TraitResolution::expand_associated_types__UfcsKnown(const Span& sp, ::HIR::
}
)
- //this->find_impl()
// 1. Bounds
bool rv;
@@ -1547,16 +1545,34 @@ void TraitResolution::expand_associated_types__UfcsKnown(const Span& sp, ::HIR::
//pe.trait = mv$(trait_path);
DEBUG("Searching for impl");
+ ImplRef best_impl;
rv = this->find_trait_impls_crate(sp, trait_path.m_path, trait_path.m_params, *pe.type, [&](auto impl, auto qual) {
DEBUG("Found " << impl);
- auto ty = impl.get_type( pe.item.c_str() );
+ if( impl.type_is_specializable(pe.item.c_str()) ) {
+ if( impl.more_specific_than( best_impl ) ) {
+ best_impl = mv$(impl);
+ }
+ return false;
+ }
+ else {
+ auto ty = impl.get_type( pe.item.c_str() );
+ if( ty == ::HIR::TypeRef() )
+ ERROR(sp, E0000, "Couldn't find assocated type " << pe.item << " in " << pe.trait);
+
+ DEBUG("Converted UfcsKnown - " << e.path << " = " << ty);
+ input = mv$(ty);
+ return true;
+ }
+ });
+ if( !rv && best_impl.is_valid() ) {
+ auto ty = best_impl.get_type( pe.item.c_str() );
if( ty == ::HIR::TypeRef() )
ERROR(sp, E0000, "Couldn't find assocated type " << pe.item << " in " << pe.trait);
DEBUG("Converted UfcsKnown - " << e.path << " = " << ty);
input = mv$(ty);
- return true;
- });
+ rv = true;
+ }
if( rv ) {
input = this->expand_associated_types(sp, mv$(input));
return ;
diff --git a/src/hir_typeck/static.cpp b/src/hir_typeck/static.cpp
index 7526f76e..db38886b 100644
--- a/src/hir_typeck/static.cpp
+++ b/src/hir_typeck/static.cpp
@@ -554,7 +554,20 @@ bool ImplRef::more_specific_than(const ImplRef& other) const
if( e.impl == nullptr ) {
return false;
}
- TODO(Span(), "more_specific_than - TraitImpl (" << *this << " '>' " << other << ")");
+ TU_MATCH(Data, (other.m_data), (oe),
+ (TraitImpl,
+ if( oe.impl == nullptr ) {
+ return true;
+ }
+ TODO(Span(), "more_specific_than - TraitImpl ( `" << *this << "` '>' `" << other << "`)");
+ ),
+ (BoundedPtr,
+ return false;
+ ),
+ (Bounded,
+ return false;
+ )
+ )
),
(BoundedPtr,
return true;