diff options
author | John Hodge <tpg@mutabah.net> | 2016-11-17 18:17:04 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-11-17 18:17:04 +0800 |
commit | 05415b24dc782cc02f5cecfc88f85b38e5cb3531 (patch) | |
tree | 69d098b702879a53217215194616e00ade5161c9 | |
parent | 6d1b331c366918ca0f6bd8aab9116b6cf304bd72 (diff) | |
download | mrust-05415b24dc782cc02f5cecfc88f85b38e5cb3531.tar.gz |
HIR Typecheck Static - impls from ErasedType
-rw-r--r-- | src/hir_typeck/static.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/hir_typeck/static.cpp b/src/hir_typeck/static.cpp index ae808165..4bb87f1d 100644 --- a/src/hir_typeck/static.cpp +++ b/src/hir_typeck/static.cpp @@ -176,6 +176,36 @@ bool StaticTraitResolve::find_impl( } ) // --- / --- + TU_IFLET( ::HIR::TypeRef::Data, type.m_data, ErasedType, e, + for(const auto& trait : e.m_traits) + { + if( trait_path == trait.m_path.m_path && (!trait_params || trait.m_path.m_params == *trait_params) ) + { + return found_cb( ImplRef(&type, &trait.m_path.m_params, &trait.m_type_bounds), false ); + } + + // TODO: What if `trait_params` is nullptr? + bool rv = false; + bool is_supertrait = trait_params && this->find_named_trait_in_trait(sp, trait_path,*trait_params, *trait.m_trait_ptr, trait.m_path.m_path,trait.m_path.m_params, type, + [&](const auto& i_params, const auto& i_assoc) { + // Invoke callback with a proper ImplRef + ::std::map< ::std::string, ::HIR::TypeRef> assoc_clone; + for(const auto& e : i_assoc) + assoc_clone.insert( ::std::make_pair(e.first, e.second.clone()) ); + // HACK! Just add all the associated type bounds (only inserted if not already present) + for(const auto& e2 : trait.m_type_bounds) + assoc_clone.insert( ::std::make_pair(e2.first, e2.second.clone()) ); + auto ir = ImplRef(type.clone(), i_params.clone(), mv$(assoc_clone)); + DEBUG("- ir = " << ir); + rv = found_cb( mv$(ir), false ); + return false; + }); + if( is_supertrait ) + { + return rv; + } + } + ) // --- // If this type is an opaque UfcsKnown - check bounds |