summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hir/type.cpp13
-rw-r--r--src/hir/type.hpp3
-rw-r--r--src/hir_conv/markings.cpp16
-rw-r--r--src/hir_typeck/helpers.cpp19
-rw-r--r--src/hir_typeck/static.cpp7
5 files changed, 31 insertions, 27 deletions
diff --git a/src/hir/type.cpp b/src/hir/type.cpp
index ccd5cd21..6e8eaaa9 100644
--- a/src/hir/type.cpp
+++ b/src/hir/type.cpp
@@ -804,6 +804,19 @@ bool HIR::TypeRef::TypePathBinding::operator==(const HIR::TypeRef::TypePathBindi
throw "";
}
+const ::HIR::TraitMarkings* HIR::TypeRef::TypePathBinding::get_trait_markings() const
+{
+ const ::HIR::TraitMarkings* markings_ptr = nullptr;
+ TU_MATCHA( (*this), (tpb),
+ (Unbound, ),
+ (Opaque, ),
+ (ExternType, markings_ptr = &tpb->m_markings; ),
+ (Struct, markings_ptr = &tpb->m_markings; ),
+ (Union, markings_ptr = &tpb->m_markings; ),
+ (Enum, markings_ptr = &tpb->m_markings; )
+ )
+ return markings_ptr;
+}
::HIR::TypeRef HIR::TypeRef::clone() const
{
diff --git a/src/hir/type.hpp b/src/hir/type.hpp
index 38196a55..7a5a0a1c 100644
--- a/src/hir/type.hpp
+++ b/src/hir/type.hpp
@@ -19,6 +19,7 @@
namespace HIR {
+class TraitMarkings;
class ExternType;
class Struct;
class Union;
@@ -164,6 +165,8 @@ public:
), (), (), (
TypePathBinding clone() const;
+ const TraitMarkings* get_trait_markings() const;
+
bool operator==(const TypePathBinding& x) const;
bool operator!=(const TypePathBinding& x) const { return !(*this == x); }
)
diff --git a/src/hir_conv/markings.cpp b/src/hir_conv/markings.cpp
index d43db2b5..01eb0952 100644
--- a/src/hir_conv/markings.cpp
+++ b/src/hir_conv/markings.cpp
@@ -20,6 +20,7 @@ class Visitor:
const ::HIR::Crate& m_crate;
const ::HIR::SimplePath& m_lang_Unsize;
const ::HIR::SimplePath& m_lang_CoerceUnsized;
+ const ::HIR::SimplePath& m_lang_Copy;
const ::HIR::SimplePath& m_lang_Deref;
const ::HIR::SimplePath& m_lang_Drop;
const ::HIR::SimplePath& m_lang_PhantomData;
@@ -28,6 +29,7 @@ public:
m_crate(crate),
m_lang_Unsize( crate.get_lang_item_path_opt("unsize") ),
m_lang_CoerceUnsized( crate.get_lang_item_path_opt("coerce_unsized") ),
+ m_lang_Copy( crate.get_lang_item_path_opt("copy") ),
m_lang_Deref( crate.get_lang_item_path_opt("deref") ),
m_lang_Drop( crate.get_lang_item_path_opt("drop") ),
m_lang_PhantomData( crate.get_lang_item_path_opt("phantom_data") )
@@ -329,15 +331,7 @@ public:
if( impl.m_type.m_data.is_Path() )
{
const auto& te = impl.m_type.m_data.as_Path();
- const ::HIR::TraitMarkings* markings_ptr = nullptr;
- TU_MATCHA( (te.binding), (tpb),
- (Unbound, ),
- (Opaque, ),
- (ExternType, markings_ptr = &tpb->m_markings; ),
- (Struct, markings_ptr = &tpb->m_markings; ),
- (Union , markings_ptr = &tpb->m_markings; ),
- (Enum , markings_ptr = &tpb->m_markings; )
- )
+ const ::HIR::TraitMarkings* markings_ptr = te.binding.get_trait_markings();
if( markings_ptr )
{
::HIR::TraitMarkings& markings = *const_cast<::HIR::TraitMarkings*>(markings_ptr);
@@ -435,6 +429,10 @@ public:
DEBUG("Type " << impl.m_type << " can Deref");
markings.has_a_deref = true;
}
+ else if( trait_path == m_lang_Copy ) {
+ DEBUG("Type " << impl.m_type << " has a Copy impl");
+ markings.is_copy = true;
+ }
// TODO: Marker traits (with conditions)
else {
}
diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp
index 629b8bba..326ecfa9 100644
--- a/src/hir_typeck/helpers.cpp
+++ b/src/hir_typeck/helpers.cpp
@@ -2480,24 +2480,7 @@ bool TraitResolution::find_trait_impls_crate(const Span& sp,
TU_IFLET( ::HIR::TypeRef::Data, (type.m_data), Path, e,
if( e.path.m_data.is_Generic() && e.path.m_data.as_Generic().m_params.m_types.size() == 0 )
{
- TU_MATCH( ::HIR::TypeRef::TypePathBinding, (e.binding), (tpb),
- (Unbound,
- ),
- (Opaque,
- ),
- (ExternType,
- markings = &tpb->m_markings;
- ),
- (Struct,
- markings = &tpb->m_markings;
- ),
- (Union,
- markings = &tpb->m_markings;
- ),
- (Enum,
- markings = &tpb->m_markings;
- )
- )
+ markings = e.binding.get_trait_markings();
}
)
diff --git a/src/hir_typeck/static.cpp b/src/hir_typeck/static.cpp
index 0c0f1859..e08ea678 100644
--- a/src/hir_typeck/static.cpp
+++ b/src/hir_typeck/static.cpp
@@ -1469,6 +1469,13 @@ bool StaticTraitResolve::type_is_copy(const Span& sp, const ::HIR::TypeRef& ty)
return rv;
),
(Path,
+ const auto* markings = e.binding.get_trait_markings();
+ if( markings && ! markings->is_copy )
+ {
+ return false;
+ }
+ // TODO: Also have a marking that indicates that the type is unconditionally Copy
+
{
auto it = m_copy_cache.find(ty);
if( it != m_copy_cache.end() )