summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-07-08 17:39:30 +1000
committerJohn Hodge <tpg@mutabah.net>2016-07-08 17:39:30 +1000
commit4788a377a141bef730e98616105eea7c3c9bd541 (patch)
treee955456938e79261fff5f94bde1101f8bc32ccc5
parentbda2f259859a4545f98b3fa9fa16fe2d2103c80d (diff)
downloadmrust-4788a377a141bef730e98616105eea7c3c9bd541.tar.gz
HIR Typecheck CS - Coercion of fn() to nothing, print fn types
-rw-r--r--src/hir_typeck/expr_cs.cpp8
-rw-r--r--src/hir_typeck/helpers.cpp47
2 files changed, 40 insertions, 15 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp
index 3504bdcd..75869284 100644
--- a/src/hir_typeck/expr_cs.cpp
+++ b/src/hir_typeck/expr_cs.cpp
@@ -2481,13 +2481,15 @@ namespace {
return true;
),
(Borrow,
- // TODO: Borrows can have unsizing and deref coercions applied
+ // Borrows can have unsizing and deref coercions applied
),
(Pointer,
- // TODO: Pointers coerce from borrows and similar pointers
+ // Pointers coerce from borrows and similar pointers
),
(Function,
- TODO(sp, "check_coerce - Coercion from " << ty_r);
+ // NOTE: Functions don't coerce (TODO: They could lose the origin marker?)
+ context.equate_types(sp, ty, node_ptr->m_res_type);
+ return true;
),
(Closure,
// TODO: Can closures coerce to anything?
diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp
index 9646b239..540a2a90 100644
--- a/src/hir_typeck/helpers.cpp
+++ b/src/hir_typeck/helpers.cpp
@@ -388,16 +388,26 @@ void HMTypeInferrence::print_type(::std::ostream& os, const ::HIR::TypeRef& tr)
os << "; " << e.size_val << "]";
),
(Closure,
- //for(const auto& arg : e.m_arg_types)
- // if( type_contains_ivars(arg) )
- // return true;
- //return type_contains_ivars(*e.m_rettype);
+ os << "{" << e.node << "}(";
+ for(const auto& arg : e.m_arg_types) {
+ this->print_type(os, arg);
+ os << ",";
+ }
+ os << ")->";
+ this->print_type(os, *e.m_rettype);
),
(Function,
- //for(const auto& arg : e.m_arg_types)
- // if( type_contains_ivars(arg) )
- // return true;
- //return type_contains_ivars(*e.m_rettype);
+ if(e.is_unsafe)
+ os << "unsafe ";
+ if(e.m_abi != "")
+ os << "extern \"" << e.m_abi << "\" ";
+ os << "fn(";
+ for(const auto& arg : e.m_arg_types) {
+ this->print_type(os, arg);
+ os << ",";
+ }
+ os << ")->";
+ this->print_type(os, *e.m_rettype);
),
(TraitObject,
os << "(" << e.m_trait.m_path.m_path;
@@ -1012,6 +1022,15 @@ void TraitResolution::compact_ivars(HMTypeInferrence& m_ivars)
bool TraitResolution::has_associated_type(const ::HIR::TypeRef& input) const
{
+ struct H {
+ static bool check_pathparams(const TraitResolution& r, const ::HIR::PathParams& pp) {
+ for(const auto& arg : pp.m_types) {
+ if( r.has_associated_type(arg) )
+ return true;
+ }
+ return false;
+ }
+ };
//TRACE_FUNCTION_F(input);
TU_MATCH(::HIR::TypeRef::Data, (input.m_data), (e),
(Infer,
@@ -1030,10 +1049,7 @@ bool TraitResolution::has_associated_type(const ::HIR::TypeRef& input) const
(Path,
TU_MATCH(::HIR::Path::Data, (e.path.m_data), (e2),
(Generic,
- bool rv = false;
- for(const auto& arg : e2.m_params.m_types)
- rv |= has_associated_type(arg);
- return rv;
+ return H::check_pathparams(*this, e2.m_params);
),
(UfcsInherent,
TODO(Span(), "Path - UfcsInherent - " << e.path);
@@ -1054,6 +1070,13 @@ bool TraitResolution::has_associated_type(const ::HIR::TypeRef& input) const
),
(TraitObject,
// Recurse?
+ if( H::check_pathparams(*this, e.m_trait.m_path.m_params) )
+ return true;
+ for(const auto& m : e.m_markers) {
+ if( H::check_pathparams(*this, m.m_params) )
+ return true;
+ }
+ return false;
),
(Array,
return has_associated_type(*e.inner);