diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-28 12:23:03 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-28 12:23:03 +0800 |
commit | d1d9cba0a6c66570f0f05eaf957927980f8a0336 (patch) | |
tree | 0b497cb6b1474a6cb3fa780dc04ee08b63f66d07 /src/hir/type.cpp | |
parent | 396a0f96ef19c225aa265304bbe1715fe4f1df36 (diff) | |
download | mrust-d1d9cba0a6c66570f0f05eaf957927980f8a0336.tar.gz |
HIR Typecheck - Fuzzy match more cases with unbound UFCS
Diffstat (limited to 'src/hir/type.cpp')
-rw-r--r-- | src/hir/type.cpp | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/src/hir/type.cpp b/src/hir/type.cpp index 5233b681..2daf1612 100644 --- a/src/hir/type.cpp +++ b/src/hir/type.cpp @@ -599,41 +599,50 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x return Compare::Equal; ), (Path, + ::HIR::Compare rv = Compare::Unequal; if( te.path.m_data.tag() != xe.path.m_data.tag() ) { - return Compare::Unequal; + rv = Compare::Unequal; } - TU_MATCH(::HIR::Path::Data, (te.path.m_data, xe.path.m_data), (tpe, xpe), - (Generic, - if( tpe.m_path != xpe.m_path ) { - return Compare::Unequal; - } - return match_generics_pp(sp, tpe.m_params, xpe.m_params, resolve_placeholder, callback); - ), - (UfcsKnown, - auto cmp = tpe.type->match_test_generics_fuzz( sp, *xpe.type, resolve_placeholder, callback ); - if( tpe.trait.m_path != xpe.trait.m_path ) - return Compare::Unequal; - cmp &= match_generics_pp(sp, tpe.trait.m_params, xpe.trait.m_params, resolve_placeholder, callback); - if( tpe.item != xpe.item ) - return Compare::Unequal; - cmp &= match_generics_pp(sp, tpe.params, xpe.params, resolve_placeholder, callback); - return cmp; - ), - (UfcsUnknown, - auto cmp = tpe.type->match_test_generics_fuzz( sp, *xpe.type, resolve_placeholder, callback ); - if( tpe.item != xpe.item ) - return Compare::Unequal; - cmp &= match_generics_pp(sp, tpe.params, xpe.params, resolve_placeholder, callback); - return cmp; - ), - (UfcsInherent, - auto cmp = tpe.type->match_test_generics_fuzz( sp, *xpe.type, resolve_placeholder, callback ); - if( tpe.item != xpe.item ) - return Compare::Unequal; - cmp &= match_generics_pp(sp, tpe.params, xpe.params, resolve_placeholder, callback); - return cmp; + else { + TU_MATCH(::HIR::Path::Data, (te.path.m_data, xe.path.m_data), (tpe, xpe), + (Generic, + if( tpe.m_path != xpe.m_path ) { + rv = Compare::Unequal; + } + else { + rv = match_generics_pp(sp, tpe.m_params, xpe.m_params, resolve_placeholder, callback); + } + ), + (UfcsKnown, + rv = tpe.type->match_test_generics_fuzz( sp, *xpe.type, resolve_placeholder, callback ); + if( tpe.trait.m_path != xpe.trait.m_path ) + rv = Compare::Unequal; + rv &= match_generics_pp(sp, tpe.trait.m_params, xpe.trait.m_params, resolve_placeholder, callback); + if( tpe.item != xpe.item ) + rv = Compare::Unequal; + rv &= match_generics_pp(sp, tpe.params, xpe.params, resolve_placeholder, callback); + ), + (UfcsUnknown, + rv = tpe.type->match_test_generics_fuzz( sp, *xpe.type, resolve_placeholder, callback ); + if( tpe.item != xpe.item ) + rv = Compare::Unequal; + rv &= match_generics_pp(sp, tpe.params, xpe.params, resolve_placeholder, callback); + ), + (UfcsInherent, + rv = tpe.type->match_test_generics_fuzz( sp, *xpe.type, resolve_placeholder, callback ); + if( tpe.item != xpe.item ) + rv = Compare::Unequal; + rv &= match_generics_pp(sp, tpe.params, xpe.params, resolve_placeholder, callback); + ) ) - ) + } + + if( rv == ::HIR::Compare::Unequal ) { + if( te.binding.is_Unbound() || xe.binding.is_Unbound() ) { + rv = ::HIR::Compare::Fuzzy; + } + } + return rv; ), (TraitObject, if( te.m_trait.m_path.m_path != xe.m_trait.m_path.m_path ) { @@ -987,7 +996,13 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x return (le == re ? Compare::Equal : Compare::Unequal); ), (Path, - return le.path.compare_with_placeholders( sp, re.path, resolve_placeholder ); + auto rv = le.path.compare_with_placeholders( sp, re.path, resolve_placeholder ); + if( rv == ::HIR::Compare::Unequal ) { + if( le.binding.is_Unbound() || re.binding.is_Unbound() ) { + rv = ::HIR::Compare::Fuzzy; + } + } + return rv; ), (Generic, if( le.binding != re.binding ) { |