summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-10-29 14:27:13 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-10-29 14:27:13 +0800
commitbbe5262a00b41053355286e9a42551c06614da2b (patch)
tree943164d3a628f7e579b32589edf68735ee8f4876
parente0ce444a815bde4221469388a63dc02b9929a33a (diff)
downloadmrust-bbe5262a00b41053355286e9a42551c06614da2b.tar.gz
HIR Typecheck - Allow casting function pointers to *const i8
-rw-r--r--src/hir_typeck/expr_check.cpp2
-rw-r--r--src/hir_typeck/expr_cs.cpp8
-rw-r--r--src/mir/from_hir.cpp2
3 files changed, 8 insertions, 4 deletions
diff --git a/src/hir_typeck/expr_check.cpp b/src/hir_typeck/expr_check.cpp
index 14cc488c..d9cbc957 100644
--- a/src/hir_typeck/expr_check.cpp
+++ b/src/hir_typeck/expr_check.cpp
@@ -311,7 +311,7 @@ namespace {
//}
),
(Function,
- if( *de.inner != ::HIR::TypeRef::new_unit() && *de.inner != ::HIR::CoreType::U8 ) {
+ if( *de.inner != ::HIR::TypeRef::new_unit() && *de.inner != ::HIR::CoreType::U8 && *de.inner != ::HIR::CoreType::I8 ) {
ERROR(sp, E0000, "Invalid cast to " << dst_ty << " from " << src_ty);
}
),
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp
index ea040bf0..b665b14e 100644
--- a/src/hir_typeck/expr_cs.cpp
+++ b/src/hir_typeck/expr_cs.cpp
@@ -2081,17 +2081,21 @@ namespace {
return ;
),
(Pointer,
+ const auto& ity = this->context.get_type(*e.inner);
TU_MATCH_DEF( ::HIR::TypeRef::Data, (src_ty.m_data), (s_e),
(
ERROR(sp, E0000, "Invalid cast to pointer from " << src_ty);
),
(Function,
// TODO: What is the valid set? *const () and *const u8 at least are allowed
- if( *e.inner == ::HIR::TypeRef::new_unit() || *e.inner == ::HIR::CoreType::U8 ) {
+ if( ity == ::HIR::TypeRef::new_unit() || ity == ::HIR::CoreType::U8 || ity == ::HIR::CoreType::I8 ) {
this->m_completed = true;
}
+ else if( ity.m_data.is_Infer() ) {
+ // Keep around.
+ }
else {
- ERROR(sp, E0000, "Invalid cast to " << tgt_ty << " from " << src_ty);
+ ERROR(sp, E0000, "Invalid cast to " << this->context.m_ivars.fmt_type(tgt_ty) << " from " << src_ty);
}
),
(Primitive,
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 8ea22cef..2a02b166 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -1247,7 +1247,7 @@ namespace {
// Valid
)
else TU_IFLET( ::HIR::TypeRef::Data, ty_in.m_data, Function, se,
- if( *de.inner != ::HIR::TypeRef::new_unit() && *de.inner != ::HIR::CoreType::U8 ) {
+ if( *de.inner != ::HIR::TypeRef::new_unit() && *de.inner != ::HIR::CoreType::U8 && *de.inner != ::HIR::CoreType::I8 ) {
BUG(node.span(), "Cannot cast to " << ty_out << " from " << ty_in);
}
// Valid