diff options
author | John Hodge <tpg@mutabah.net> | 2016-08-21 21:08:27 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-08-21 21:08:27 +0800 |
commit | 94a8912514f19b52854187accb2e57193f0eeac2 (patch) | |
tree | db2d2f5a9204d1cdc1a369c47e7ff65d41cb4ab0 | |
parent | b05c6ab59544a811e2ae7182a18dd705aeb388a7 (diff) | |
download | mrust-94a8912514f19b52854187accb2e57193f0eeac2.tar.gz |
HIR Typecheck Static - Extended Copy checking
-rw-r--r-- | src/hir_typeck/static.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/hir_typeck/static.cpp b/src/hir_typeck/static.cpp index 8abb7174..92d6fdb5 100644 --- a/src/hir_typeck/static.cpp +++ b/src/hir_typeck/static.cpp @@ -711,16 +711,33 @@ bool StaticTraitResolve::type_is_copy(const ::HIR::TypeRef& ty) const return false; ), (Borrow, + // Only shared &-ptrs are copy return (e.type == ::HIR::BorrowType::Shared); ), (Pointer, + // All raw pointers are Copy + return true; + ), + (Function, + // All function pointers are Copy return true; ), (Primitive, + // All primitives (except the unsized `str`) are Copy return e != ::HIR::CoreType::Str; ), (Array, - return type_is_copy(*e.inner); + return e.size_val == 0 || type_is_copy(*e.inner); + ), + (Slice, + // [T] isn't Sized, so isn't Copy ether + return false; + ), + (Tuple, + for(const auto& ty : e) + if( !type_is_copy(ty) ) + return false; + return true; ) ) } |