summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hir/generic_params.cpp34
-rw-r--r--src/hir/generic_params.hpp1
-rw-r--r--src/hir_conv/resolve_ufcs.cpp29
-rw-r--r--src/hir_typeck/expr_cs.cpp1
-rw-r--r--src/hir_typeck/outer.cpp2
5 files changed, 37 insertions, 30 deletions
diff --git a/src/hir/generic_params.cpp b/src/hir/generic_params.cpp
index 40608cea..399bddbf 100644
--- a/src/hir/generic_params.cpp
+++ b/src/hir/generic_params.cpp
@@ -3,6 +3,25 @@
#include "generic_params.hpp"
namespace HIR {
+ ::std::ostream& operator<<(::std::ostream& os, const GenericBound& x)
+ {
+ TU_MATCH(::HIR::GenericBound, (x), (e),
+ (Lifetime,
+ os << "'" << e.test << ": '" << e.valid_for;
+ ),
+ (TypeLifetime,
+ os << e.type << ": '" << e.valid_for;
+ ),
+ (TraitBound,
+ os << e.type << ": " << e.trait.m_path;
+ ),
+ (TypeEquality,
+ os << e.type << " = " << e.other_type;
+ )
+ )
+ return os;
+ }
+
::std::ostream& operator<<(::std::ostream& os, const ::HIR::GenericParams::PrintArgs& x)
{
if( x.gp.m_lifetimes.size() > 0 || x.gp.m_types.size() > 0 )
@@ -33,20 +52,7 @@ namespace HIR {
{
if(comma_needed)
os << ", ";
- TU_MATCH(::HIR::GenericBound, (b), (e),
- (Lifetime,
- os << "'" << e.test << ": '" << e.valid_for;
- ),
- (TypeLifetime,
- os << e.type << ": '" << e.valid_for;
- ),
- (TraitBound,
- os << e.type << ": " << e.trait.m_path;
- ),
- (TypeEquality,
- os << e.type << " = " << e.other_type;
- )
- )
+ os << b;
comma_needed = true;
}
}
diff --git a/src/hir/generic_params.hpp b/src/hir/generic_params.hpp
index 52ba2976..6d1a62e6 100644
--- a/src/hir/generic_params.hpp
+++ b/src/hir/generic_params.hpp
@@ -37,6 +37,7 @@ TAGGED_UNION(GenericBound, Lifetime,
::HIR::TypeRef other_type;
})
);
+extern ::std::ostream& operator<<(::std::ostream& os, const GenericBound& x);
struct GenericParams
{
diff --git a/src/hir_conv/resolve_ufcs.cpp b/src/hir_conv/resolve_ufcs.cpp
index c288a0cf..2cac5311 100644
--- a/src/hir_conv/resolve_ufcs.cpp
+++ b/src/hir_conv/resolve_ufcs.cpp
@@ -230,25 +230,22 @@ namespace {
}
bool locate_in_trait_impl_and_set(::HIR::Visitor::PathContext pc, const ::HIR::GenericPath& trait_path, const ::HIR::Trait& trait, ::HIR::Path::Data& pd) {
+ static Span sp;
+
auto& e = pd.as_UfcsUnknown();
if( this->locate_item_in_trait(pc, trait, pd) ) {
const auto& type = *e.type;
- auto trait_impl_it = this->m_crate.m_trait_impls.equal_range( trait_path.m_path );
- if( trait_impl_it.first == trait_impl_it.second ) {
- // Since this trait isn't implemented, none of the supertraits matter
- return false;
- }
- for( auto it = trait_impl_it.first; it != trait_impl_it.second; ++ it )
- {
- const auto& impl = it->second;
- DEBUG("impl" << impl.m_params.fmt_args() << " " << trait_path.m_path << impl.m_trait_args << " for " << impl.m_type);
- if( impl.matches_type(type) )
- {
- pd = get_ufcs_known(mv$(e), make_generic_path(trait_path.m_path, trait), trait);
- return true;
+ return this->m_crate.find_trait_impls(trait_path.m_path, type, [](const auto& x)->const auto&{return x;}, [&](const auto& impl) {
+ DEBUG("FOUND impl" << impl.m_params.fmt_args() << " " << trait_path.m_path << impl.m_trait_args << " for " << impl.m_type);
+ // TODO: Check bounds
+ for(const auto& bound : impl.m_params.m_bounds) {
+ DEBUG("- TODO: Bound " << bound);
+ return false;
}
- }
+ pd = get_ufcs_known(mv$(e), make_generic_path(trait_path.m_path, trait), trait);
+ return true;
+ });
}
else {
DEBUG("- Item " << e.item << " not in trait " << trait_path.m_path);
@@ -275,7 +272,7 @@ namespace {
DEBUG("p = " << p);
TU_IFLET(::HIR::Path::Data, p.m_data, UfcsUnknown, e,
- DEBUG("UfcsUnknown - p=" << p);
+ TRACE_FUNCTION_F("UfcsUnknown - p=" << p);
this->visit_type( *e.type );
this->visit_path_params( e.params );
@@ -348,7 +345,7 @@ namespace {
continue ;
break;
}
- DEBUG("- Looking for impl of " << *trait_info.first << " for " << *e.type);
+ DEBUG("- Trying trait " << *trait_info.first);
auto trait_path = ::HIR::GenericPath( *trait_info.first );
for(unsigned int i = 0; i < trait.m_params.m_types.size(); i ++ ) {
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp
index e3662cdc..b252434d 100644
--- a/src/hir_typeck/expr_cs.cpp
+++ b/src/hir_typeck/expr_cs.cpp
@@ -3216,6 +3216,7 @@ void Typecheck_Code_CS(const typeck::ModuleState& ms, t_args& args, const ::HIR:
for(unsigned int i = 0; i < context.link_assoc.size(); ) {
auto& rule = context.link_assoc[i];
+ DEBUG("- " << rule);
for( auto& ty : rule.params.m_types ) {
ty = context.m_resolve.expand_associated_types(rule.span, mv$(ty));
}
diff --git a/src/hir_typeck/outer.cpp b/src/hir_typeck/outer.cpp
index 78e49191..9439a007 100644
--- a/src/hir_typeck/outer.cpp
+++ b/src/hir_typeck/outer.cpp
@@ -256,6 +256,8 @@ namespace {
check_parameters(Span(), params, args);
DEBUG("p = " << p);
+
+ ::HIR::Visitor::visit_generic_path(p, pc);
}
void visit_path(::HIR::Path& p, ::HIR::Visitor::PathContext pc) override
{