diff options
author | John Hodge <tpg@ucc.asn.au> | 2016-08-05 12:51:26 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2016-08-05 12:51:26 +0800 |
commit | 0459a4ee12ad98be68f92645c9a1483d117c0a15 (patch) | |
tree | b53abf6a3d0a07dc75c1883c3dd5828ff5f1d0c7 | |
parent | d3a7b742572e23a535571eb126a84a394c37dfe2 (diff) | |
download | mrust-0459a4ee12ad98be68f92645c9a1483d117c0a15.tar.gz |
HIR Typecheck CS - Add cast when going from &T to *const T
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 77f48d6a..887c309b 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -3226,7 +3226,18 @@ namespace { (Pointer, // Pointers coerce from borrows and similar pointers TU_IFLET(::HIR::TypeRef::Data, ty_src.m_data, Borrow, r_e, + if( r_e.type != l_e.type ) { + ERROR(sp, E0000, "Type mismatch between " << ty_dst << " and " << ty_src << " - Mutability differs"); + } context.equate_types(sp, *l_e.inner, *r_e.inner); + + // Add downcast + auto span = node_ptr->span(); + node_ptr->m_res_type = ty_src.clone(); + node_ptr = ::HIR::ExprNodeP(new ::HIR::ExprNode_Cast( mv$(span), mv$(node_ptr), ty_dst.clone() )); + node_ptr->m_res_type = ty_dst.clone(); + + context.m_ivars.mark_change(); return true; ) else TU_IFLET(::HIR::TypeRef::Data, ty_src.m_data, Pointer, r_e, |