diff options
author | John Hodge <tpg@mutabah.net> | 2016-08-23 17:01:32 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-08-23 17:01:32 +0800 |
commit | 6cf05070d793f95e051046f0a301f6e006bebb50 (patch) | |
tree | da97928bab54513ffd2c26d4174720ef6da1ffcc /src | |
parent | 2c9fa961084439d5e58f70e151e79b56961599c8 (diff) | |
download | mrust-6cf05070d793f95e051046f0a301f6e006bebb50.tar.gz |
HIR Typecheck - Bettern Copy handling in static
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_typeck/static.cpp | 23 | ||||
-rw-r--r-- | src/hir_typeck/static.hpp | 4 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/hir_typeck/static.cpp b/src/hir_typeck/static.cpp index f9962efd..ea411a24 100644 --- a/src/hir_typeck/static.cpp +++ b/src/hir_typeck/static.cpp @@ -109,6 +109,14 @@ bool StaticTraitResolve::find_impl( ) ) + if( trait_path == m_lang_Copy ) { + if( this->type_is_copy(type) ) { + static ::HIR::PathParams null_params; + static ::std::map< ::std::string, ::HIR::TypeRef> null_assoc; + return found_cb( ImplRef(&type, &null_params, &null_assoc) ); + } + } + bool ret; // TODO: A bound can imply something via its associated types. How deep can this go? @@ -708,11 +716,22 @@ bool StaticTraitResolve::type_is_copy(const ::HIR::TypeRef& ty) const static Span sp; TU_MATCH(::HIR::TypeRef::Data, (ty.m_data), (e), (Generic, - return this->find_impl(sp, m_crate.get_lang_item_path(sp, "copy"), {}, ty, [&](auto ){ return true;}); + return this->iterate_bounds([&](const auto& b) { + TU_IFLET(::HIR::GenericBound, b, TraitBound, e, + if( e.type == ty && e.trait.m_path.m_path == m_lang_Copy ) { + return true; + } + ) + return false; + }); ), (Path, // TODO: Cache this result for the relevant scope. - return this->find_impl(sp, m_crate.get_lang_item_path(sp, "copy"), {}, ty, [&](auto ){ return true;}); + auto cb_ident = [](const auto&ty)->const auto&{return ty;}; + return m_crate.find_trait_impls(m_lang_Copy, ty, cb_ident, [&](const auto& impl) { + auto pp = ::HIR::PathParams(); + return this->find_impl__check_crate(sp, m_lang_Copy, &pp, ty, [&](auto ){ return true; }, impl); + }); ), (Diverge, // The ! type is kinda Copy ... diff --git a/src/hir_typeck/static.hpp b/src/hir_typeck/static.hpp index 928367f4..b2e112f1 100644 --- a/src/hir_typeck/static.hpp +++ b/src/hir_typeck/static.hpp @@ -21,12 +21,16 @@ public: ::std::map< ::HIR::TypeRef, ::HIR::TypeRef> m_type_equalities; +private: + ::HIR::SimplePath m_lang_Copy; + public: StaticTraitResolve(const ::HIR::Crate& crate): m_crate(crate), m_impl_generics(nullptr), m_item_generics(nullptr) { + m_lang_Copy = m_crate.get_lang_item_path(Span(), "copy"); prep_indexes(); } |