diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-29 09:34:40 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-29 09:34:40 +0800 |
commit | bb2b8ce80e56acceea8005fbc00e2e042382a2a0 (patch) | |
tree | ede9bf44cc8e0d4ba85605321d4d49ae8eab82ae /src | |
parent | c1386b6872d4353de3a8e3494ec5bd5e0b29b7bb (diff) | |
download | mrust-bb2b8ce80e56acceea8005fbc00e2e042382a2a0.tar.gz |
HIR Typecheck Expr - Skip cast if types equal
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 86557240..7e1966b3 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -1706,6 +1706,12 @@ namespace { const auto& sp = node.span(); const auto& tgt_ty = this->context.get_type(node.m_res_type); const auto& src_ty = this->context.get_type(node.m_value->m_res_type); + + if( this->context.m_ivars.types_equal(src_ty, tgt_ty) ) { + this->m_completed = true; + return ; + } + TU_MATCH( ::HIR::TypeRef::Data, (tgt_ty.m_data), (e), (Infer, // Can't know anything @@ -1816,7 +1822,16 @@ namespace { ) ), (Function, - ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty)); + // NOTE: Valid if it's causing a fn item -> fn pointer coercion + TU_MATCH_DEF( ::HIR::TypeRef::Data, (src_ty.m_data), (s_e), + ( + ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty) << " to " << this->context.m_ivars.fmt_type(src_ty)); + ), + (Function, + // Check that the ABI and unsafety is correct + ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty) << " to " << this->context.m_ivars.fmt_type(src_ty)); + ) + ) ), (Closure, BUG(sp, "Attempting to cast to a closure type - impossible"); |