summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-06-13 15:02:39 +0800
committerJohn Hodge <tpg@mutabah.net>2016-06-13 15:02:39 +0800
commitc314f8e15e05e81b921b8b04c08f8eca4436c5e8 (patch)
treed70dbf9062a05eb93f48bd4af33f61924a2478bb
parent8947b0dda71d4713c9f69c8b2cd6bde3308b5000 (diff)
downloadmrust-c314f8e15e05e81b921b8b04c08f8eca4436c5e8.tar.gz
HIR Typecheck - Search for Deref impl in * operator
-rw-r--r--src/hir/type.cpp2
-rw-r--r--src/hir_typeck/expr.cpp16
2 files changed, 17 insertions, 1 deletions
diff --git a/src/hir/type.cpp b/src/hir/type.cpp
index 34b0bb2e..fd082606 100644
--- a/src/hir/type.cpp
+++ b/src/hir/type.cpp
@@ -284,7 +284,7 @@ void ::HIR::TypeRef::match_generics(const Span& sp, const ::HIR::TypeRef& x_in,
if( match_test_generics(sp, x_in, resolve_placeholder, callback) ) {
}
else {
- BUG(sp, "TypeRef::match_generics with mismatched forms - " << *this << " and " << x_in);
+ BUG(sp, "TypeRef::match_generics with mismatched parameters - " << *this << " and " << x_in);
}
}
bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x_in, t_cb_resolve_type resolve_placeholder, t_cb_match_generics callback) const
diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp
index c152e2bd..123a9a26 100644
--- a/src/hir_typeck/expr.cpp
+++ b/src/hir_typeck/expr.cpp
@@ -1257,8 +1257,24 @@ namespace typeck {
else TU_IFLET(::HIR::TypeRef::Data, ty.m_data, Array, e,
this->context.apply_equality(node.span(), node.m_res_type, ::HIR::TypeRef::new_slice(e.inner->clone()));
)
+ else if( ty.m_data.is_Infer() ) {
+ // Leave it for now
+ }
else {
// TODO: Search for Deref impl
+ ::HIR::TypeRef res;
+ const auto& op_deref = this->context.m_crate.get_lang_item_path(node.span(), "deref");
+ bool rv = this->context.find_trait_impls(node.span(), op_deref, ::HIR::PathParams{}, ty, [&](const auto& _args, const auto& types) {
+ if( res != ::HIR::TypeRef() )
+ TODO(node.span(), "Handle multiple implementations of Deref");
+ if( types.find("Target") == types.end() )
+ BUG(node.span(), "Impl of Deref didn't include `Target` associated type (TODO: Is this a bug, what about bounds?)");
+ res = types.at("Target").clone();
+ return true;
+ });
+ if( rv ) {
+ this->context.apply_equality(node.span(), node.m_res_type, res);
+ }
}
::HIR::ExprVisitorDef::visit(node);
}