diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-22 08:57:03 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-22 16:00:27 +0800 |
commit | 87e260dc879cf7fa6570dd4250dfcfeff86319e7 (patch) | |
tree | 4080af26a82b56c7c2886485a74439005f6b0319 /src/hir_conv/resolve_ufcs.cpp | |
parent | a2c18661a090d26f395528982ac37e129fe04432 (diff) | |
download | mrust-87e260dc879cf7fa6570dd4250dfcfeff86319e7.tar.gz |
HIR Conv - Bind UFCS paths in patterns
Diffstat (limited to 'src/hir_conv/resolve_ufcs.cpp')
-rw-r--r-- | src/hir_conv/resolve_ufcs.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/hir_conv/resolve_ufcs.cpp b/src/hir_conv/resolve_ufcs.cpp index 85662a65..9dec8b91 100644 --- a/src/hir_conv/resolve_ufcs.cpp +++ b/src/hir_conv/resolve_ufcs.cpp @@ -409,6 +409,66 @@ namespace { } } + void visit_pattern(::HIR::Pattern& pat) override + { + static Span _sp = Span(); + const Span& sp = _sp; + + ::HIR::Visitor::visit_pattern(pat); + + TU_MATCH_DEF(::HIR::Pattern::Data, (pat.m_data), (e), + ( + ), + (Value, + this->visit_pattern_Value(sp, pat, e.val); + ), + (Range, + this->visit_pattern_Value(sp, pat, e.start); + this->visit_pattern_Value(sp, pat, e.end); + ) + ) + } + void visit_pattern_Value(const Span& sp, const ::HIR::Pattern& pat, ::HIR::Pattern::Value& val) + { + TU_IFLET( ::HIR::Pattern::Value, val, Named, ve, + TRACE_FUNCTION_F(ve.path); + TU_MATCH( ::HIR::Path::Data, (ve.path.m_data), (pe), + (Generic, + // Already done + ), + (UfcsUnknown, + BUG(sp, "UfcsUnknown still in pattern value - " << pat); + ), + (UfcsInherent, + bool rv = m_crate.find_type_impls(*pe.type, [&](const auto& t)->const auto& { return t; }, [&](const auto& impl) { + DEBUG("- matched inherent impl" << impl.m_params.fmt_args() << " " << impl.m_type); + // Search for item in this block + auto it = impl.m_constants.find(pe.item); + if( it != impl.m_constants.end() ) { + ve.binding = &it->second.data; + return true; + } + return false; + }); + if( !rv ) { + ERROR(sp, E0000, "Constant " << ve.path << " couldn't be found"); + } + ), + (UfcsKnown, + bool rv = this->m_resolve.find_impl(sp, pe.trait.m_path, &pe.trait.m_params, *pe.type, [&](const auto& impl) { + if( !impl.m_data.is_TraitImpl() ) { + return true; + } + ve.binding = &impl.m_data.as_TraitImpl().impl->m_constants.at( pe.item ).data; + return true; + }); + if( !rv ) { + ERROR(sp, E0000, "Constant " << ve.path << " couldn't be found"); + } + ) + ) + ) + } const ::HIR::Trait& find_trait(const ::HIR::SimplePath& path) const { |