diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-05 11:46:30 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-05 11:46:30 +0800 |
commit | 2988d96c4c985321650853b120dc2c973ed7ed78 (patch) | |
tree | a5ec4e224123af36355ee0663abdedfb5825d1c5 | |
parent | 73f6bacc20dc8248654994d1d9a35e3aebcf7d0d (diff) | |
download | mrust-2988d96c4c985321650853b120dc2c973ed7ed78.tar.gz |
HIR Typecheck Expr - Support extracting associated type from trait object
-rw-r--r-- | src/hir_typeck/helpers.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp index 14f1559f..e4180c9a 100644 --- a/src/hir_typeck/helpers.cpp +++ b/src/hir_typeck/helpers.cpp @@ -1417,6 +1417,38 @@ void TraitResolution::expand_associated_types_inplace__UfcsKnown(const Span& sp, } ) + // If it's a TraitObject, then maybe we're asking for a bound + TU_IFLET(::HIR::TypeRef::Data, pe.type->m_data, TraitObject, te, + const auto& data_trait = te.m_trait.m_path; + if( pe.trait.m_path == data_trait.m_path ) { + auto cmp = ::HIR::Compare::Equal; + if( pe.trait.m_params.m_types.size() != data_trait.m_params.m_types.size() ) + { + cmp = ::HIR::Compare::Unequal; + } + else + { + for(unsigned int i = 0; i < pe.trait.m_params.m_types.size(); i ++) + { + const auto& l = pe.trait.m_params.m_types[i]; + const auto& r = data_trait.m_params.m_types[i]; + cmp &= l.compare_with_placeholders(sp, r, m_ivars.callback_resolve_infer()); + } + } + if( cmp != ::HIR::Compare::Unequal ) + { + auto it = te.m_trait.m_type_bounds.find( pe.item ); + if( it == te.m_trait.m_type_bounds.end() ) { + // TODO: Mark as opaque and return. + // - Why opaque? It's not bounded, don't even bother + TODO(sp, "Handle unconstrained associate type " << pe.item << " from " << *pe.type); + } + + input = it->second.clone(); + return ; + } + } + ) // 1. Bounds bool rv; |