diff options
author | John Hodge <tpg@mutabah.net> | 2016-07-10 16:37:10 +1000 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-07-10 16:37:10 +1000 |
commit | 61e61e0a557c399ed6f62a645e25063557b8f569 (patch) | |
tree | 0bfc34de37ec1d38d9629810fdb5f37acf0a82aa /src | |
parent | ad62a9475dd8b820bff0f1ed2ef883933f7aebe2 (diff) | |
download | mrust-61e61e0a557c399ed6f62a645e25063557b8f569.tar.gz |
HIR Typecheck - Hacky Copy impls
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_typeck/helpers.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp index 1908a884..04984054 100644 --- a/src/hir_typeck/helpers.cpp +++ b/src/hir_typeck/helpers.cpp @@ -960,6 +960,40 @@ bool TraitResolution::find_trait_impls(const Span& sp, ) return callback( type, ::HIR::PathParams(), {} ); } + + if( trait == this->m_crate.get_lang_item_path(sp, "copy") ) { + struct H { + static bool is_copy(const Span& sp, const TraitResolution& self, const ::HIR::TypeRef& ty) { + const auto& type = self.m_ivars.get_type(ty); + TU_MATCH_DEF(::HIR::TypeRef::Data, (type.m_data), (e), + ( + // TODO: Search for impls? + TODO(sp, "Search for Copy impl on " << type); + ), + (Primitive, + if( e == ::HIR::CoreType::Str ) + return false; + return true; + ), + (Borrow, + return e.type == ::HIR::BorrowType::Shared; + ), + (Pointer, + return true; + ), + (Array, + return is_copy(sp, self, *e.inner); + ) + ) + } + }; + if( H::is_copy(sp, *this, type) ) { + return callback( type, ::HIR::PathParams(), {} ); + } + else { + return false; + } + } const auto& trait_fn = this->m_crate.get_lang_item_path(sp, "fn"); const auto& trait_fn_mut = this->m_crate.get_lang_item_path(sp, "fn_mut"); |