summaryrefslogtreecommitdiff
path: root/src/hir
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-05-15 12:13:17 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-05-15 12:13:17 +0800
commit7e6dbc2b30d68be64b7caa18b9790148c99ecd8e (patch)
tree11829a17c890370b1a64e50b7fb875ff6321a05d /src/hir
parent6b459cee4eec7f75388901e80af71993eb3a90b3 (diff)
downloadmrust-7e6dbc2b30d68be64b7caa18b9790148c99ecd8e.tar.gz
HIR Impl Specialisation - Handling of TraitObject
Diffstat (limited to 'src/hir')
-rw-r--r--src/hir/hir.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp
index 895398e2..ea887e6e 100644
--- a/src/hir/hir.cpp
+++ b/src/hir/hir.cpp
@@ -402,7 +402,22 @@ namespace {
TODO(sp, "Path - " << le.path << " and " << right);
),
(TraitObject,
- TODO(sp, "TraitObject - " << left);
+ ASSERT_BUG(sp, right.m_data.is_TraitObject(), "Mismatched types - "<< left << " vs " << right);
+ const auto& re = right.m_data.as_TraitObject();
+ ASSERT_BUG(sp, le.m_trait.m_path.m_path == re.m_trait.m_path.m_path, "Mismatched types - "<< left << " vs " << right);
+ ASSERT_BUG(sp, le.m_markers.size() == re.m_markers.size(), "Mismatched types - "<< left << " vs " << right);
+
+ auto ord = typelist_ord_specific(sp, le.m_trait.m_path.m_params.m_types, re.m_trait.m_path.m_params.m_types);
+ if( ord != ::OrdEqual )
+ return ord;
+ for(size_t i = 0; i < le.m_markers.size(); i ++)
+ {
+ ASSERT_BUG(sp, le.m_markers[i].m_path == re.m_markers[i].m_path, "Mismatched types - " << left << " vs " << right);
+ ord = typelist_ord_specific(sp, le.m_markers[i].m_params.m_types, re.m_markers[i].m_params.m_types);
+ if(ord != ::OrdEqual)
+ return ord;
+ }
+ return ::OrdEqual;
),
(ErasedType,
TODO(sp, "ErasedType - " << left);
@@ -693,9 +708,21 @@ bool ::HIR::TraitImpl::overlaps_with(const ::HIR::TraitImpl& other) const
TODO(sp, "Path - " << ae.path << " and " << be.path);
),
(TraitObject,
- if( ae.m_trait.m_path != be.m_trait.m_path )
+ if( ae.m_trait.m_path.m_path != be.m_trait.m_path.m_path )
+ return false;
+ if( !H::types_overlap(ae.m_trait.m_path.m_params, be.m_trait.m_path.m_params) )
+ return false;
+ // Marker traits only overlap if the lists are the same (with overlap)
+ if( ae.m_markers.size() != be.m_markers.size() )
return false;
- TODO(sp, "TraitObject - " << a << " and " << b);
+ for(size_t i = 0; i < ae.m_markers.size(); i++)
+ {
+ if( ae.m_markers[i].m_path != be.m_markers[i].m_path )
+ return false;
+ if( !H::types_overlap(ae.m_markers[i].m_params, be.m_markers[i].m_params) )
+ return false;
+ }
+ return true;
),
(ErasedType,
TODO(sp, "ErasedType - " << a);