summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-07-10 16:29:15 +1000
committerJohn Hodge <tpg@mutabah.net>2016-07-10 16:29:57 +1000
commitad62a9475dd8b820bff0f1ed2ef883933f7aebe2 (patch)
tree6e66da0e22e1a17faa874eaca00b61f2231a882f /src
parent9049d47d48c82c311834ad4f90625b18e9ce2695 (diff)
downloadmrust-ad62a9475dd8b820bff0f1ed2ef883933f7aebe2.tar.gz
HIR Typecheck CS - Allow casts from usize to pointers
Diffstat (limited to 'src')
-rw-r--r--src/hir_typeck/expr_cs.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp
index 3081a366..6fbf8907 100644
--- a/src/hir_typeck/expr_cs.cpp
+++ b/src/hir_typeck/expr_cs.cpp
@@ -1297,12 +1297,31 @@ namespace {
(
ERROR(sp, E0000, "Invalid cast to pointer");
),
+ (Primitive,
+ if( s_e != ::HIR::CoreType::Usize ) {
+ ERROR(sp, E0000, "Invalid cast to pointer from " << src_ty);
+ }
+ // TODO: Can't be to a fat pointer though.
+ this->m_completed = true;
+ ),
(Infer,
+ switch( s_e.ty_class )
+ {
+ case ::HIR::InferClass::Float:
+ ERROR(sp, E0000, "Invalid cast to pointer from floating point literal");
+ case ::HIR::InferClass::Integer:
+ this->context.equate_types(sp, src_ty, ::HIR::TypeRef(::HIR::CoreType::Usize));
+ this->m_completed = true;
+ break;
+ case ::HIR::InferClass::None:
+ break;
+ }
),
(Borrow,
// Check class (must be equal) and type
// TODO: Check class
this->context.equate_types(sp, *e.inner, *s_e.inner);
+ this->m_completed = true;
),
(Pointer,
// Allow with no link?