diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-04 17:22:06 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-04 17:22:06 +0800 |
commit | 9b3f03150b5a4b09f5d9bf6a95bf863ba2a8b0e1 (patch) | |
tree | d8ad7b467f0e2fc5fb707fd8fd520554c3e50e63 | |
parent | 1a6e144f8311faf6e6feaced2115ac00ae23d555 (diff) | |
download | mrust-9b3f03150b5a4b09f5d9bf6a95bf863ba2a8b0e1.tar.gz |
HIR - Support fuzzy generic match on TraitObject
-rw-r--r-- | src/hir/type.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/hir/type.cpp b/src/hir/type.cpp index e51929c9..4734a391 100644 --- a/src/hir/type.cpp +++ b/src/hir/type.cpp @@ -549,7 +549,6 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x return Compare::Unequal; cmp &= match_generics_pp(sp, tpe.params, xpe.params, resolve_placeholder, callback); return cmp; - TODO(sp, "Path UfcsKnown - " << *this << " and " << x); ), (UfcsUnknown, auto cmp = tpe.type->match_test_generics_fuzz( sp, *xpe.type, resolve_placeholder, callback ); @@ -568,7 +567,34 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x ) ), (TraitObject, - TODO(sp, "TraitObject"); + if( te.m_trait.m_path.m_path != xe.m_trait.m_path.m_path ) { + return Compare::Unequal; + } + if( te.m_markers.size() != xe.m_markers.size() ) { + return Compare::Unequal; + } + auto cmp = match_generics_pp(sp, te.m_trait.m_path.m_params, xe.m_trait.m_path.m_params, resolve_placeholder, callback); + for(unsigned int i = 0; i < te.m_markers.size(); i ++) + { + cmp &= match_generics_pp(sp, te.m_markers[i].m_params, xe.m_markers[i].m_params, resolve_placeholder, callback); + } + + auto it_l = te.m_trait.m_type_bounds.begin(); + auto it_r = xe.m_trait.m_type_bounds.begin(); + while( it_l != te.m_trait.m_type_bounds.end() && it_r != xe.m_trait.m_type_bounds.end() ) + { + if( it_l->first != it_r->first ) { + return Compare::Unequal; + } + cmp &= it_l->second .match_test_generics_fuzz( sp, it_r->second, resolve_placeholder, callback ); + ++ it_l; + ++ it_r; + } + + if( it_l != te.m_trait.m_type_bounds.end() || it_r != xe.m_trait.m_type_bounds.end() ) { + return Compare::Unequal; + } + return cmp; ), (Array, return te.inner->match_test_generics_fuzz( sp, *xe.inner, resolve_placeholder, callback ); |