diff options
author | John Hodge <tpg@mutabah.net> | 2017-08-31 17:36:06 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2017-08-31 17:36:06 +0800 |
commit | b6726e67982b9a73b9f5286c17ff81688ce06b11 (patch) | |
tree | 9446a2b5bb1303ad003261d08fadaa3ab9352c83 /src/hir_typeck | |
parent | 43a9adaef989a8bed5f8fafeef78555df0bd8fb0 (diff) | |
download | mrust-b6726e67982b9a73b9f5286c17ff81688ce06b11.tar.gz |
HIR Typecheck Expr - Inferrence check for non-borrow coercion source
Diffstat (limited to 'src/hir_typeck')
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 9c8d9a73..e2f386ed 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -4409,15 +4409,15 @@ namespace { unsigned int count = 0; ::HIR::PathParams pp { dst.clone() }; - bool found = context.m_resolve.find_trait_impls(sp, lang_Unsize, pp, src, [&best_impl,&count](auto impl, bool fuzzy){ - DEBUG("[check_unsize_tys] Found impl " << impl << (fuzzy ? " (fuzzy)" : "")); + bool found = context.m_resolve.find_trait_impls(sp, lang_Unsize, pp, src, [&best_impl,&count](auto impl, auto cmp){ + DEBUG("[check_unsize_tys] Found impl " << impl << (cmp == ::HIR::Compare::Fuzzy ? " (fuzzy)" : "")); if( impl.more_specific_than(best_impl) ) { best_impl = mv$(impl); count ++; } // TODO: Record the best impl (if fuzzy) and equate params - return !fuzzy; + return cmp != ::HIR::Compare::Fuzzy; }); if( found ) { @@ -5480,6 +5480,8 @@ namespace { TU_IFLET( ::HIR::TypeRef::Data, src.m_data, Borrow, se, TU_IFLET( ::HIR::TypeRef::Data, dst.m_data, Borrow, de, ) + else TU_IFLET( ::HIR::TypeRef::Data, dst.m_data, Pointer, de, + ) else { return true; } @@ -5657,13 +5659,14 @@ namespace { if( l.m_data.is_Borrow() ) { const auto& le = l.m_data.as_Borrow(); - const auto& re = r.m_data.as_Borrow(); + ASSERT_BUG(sp, r.m_data.is_Borrow() || r.m_data.is_Pointer(), "Coerce source for borrow isn't a borrow/pointert - " << r); + const auto& re_inner = r.m_data.is_Borrow() ? r.m_data.as_Borrow().inner : r.m_data.as_Pointer().inner; // Dereference `*re.inner` until it isn't possible or it equals `*le.inner` // - Repeat going the other direction. - if( H::type_derefs_from(sp, context, *le.inner, *re.inner) ) + if( H::type_derefs_from(sp, context, *le.inner, *re_inner) ) return DedupKeep::Left; - if( H::type_derefs_from(sp, context, *re.inner, *le.inner) ) + if( H::type_derefs_from(sp, context, *re_inner, *le.inner) ) return DedupKeep::Right; } return DedupKeep::Both; |