diff options
author | John Hodge <tpg@mutabah.net> | 2016-07-25 21:49:45 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-07-25 21:49:45 +0800 |
commit | 416c4aa0ae52104f8b97ae4262452f07225329db (patch) | |
tree | a28e6b14c6f132c03412f302a9282ea82fe200d7 /src | |
parent | 9693673fa336ddf9c29bd0a6bf1ce2853a9ddab1 (diff) | |
download | mrust-416c4aa0ae52104f8b97ae4262452f07225329db.tar.gz |
HIR Typecheck - Expand associated types when getting output type
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 18 | ||||
-rw-r--r-- | src/hir_typeck/static.cpp | 20 |
2 files changed, 27 insertions, 11 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 243f4cfc..b5ee0b03 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -3010,22 +3010,20 @@ namespace { DEBUG("Searching for impl " << v.trait << v.params << " for " << context.m_ivars.fmt_type(v.impl_ty)); bool found = context.m_resolve.find_trait_impls(sp, v.trait, v.params, v.impl_ty, [&](auto impl, auto cmp) { - DEBUG("Found " << impl); - ::HIR::TypeRef out_ty_o; + DEBUG("[check_associated] Found " << impl); if( v.name != "" ) { - out_ty_o = impl.get_type(v.name.c_str()); + auto out_ty_o = impl.get_type(v.name.c_str()); if( out_ty_o == ::HIR::TypeRef() ) { - auto ty1 = ::HIR::TypeRef( ::HIR::Path(::HIR::Path( v.impl_ty.clone(), ::HIR::GenericPath(v.trait, v.params.clone()), v.name, ::HIR::PathParams() )) ); - out_ty_o = context.m_resolve.expand_associated_types(sp, mv$(ty1)); + out_ty_o = ::HIR::TypeRef( ::HIR::Path(::HIR::Path( v.impl_ty.clone(), ::HIR::GenericPath(v.trait, v.params.clone()), v.name, ::HIR::PathParams() )) ); } + out_ty_o = context.m_resolve.expand_associated_types(sp, mv$(out_ty_o)); //BUG(sp, "Getting associated type '" << v.name << "' which isn't in " << v.trait << " (" << ty << ")"); - } - const auto& out_ty = (v.name == "" ? v.left_ty : out_ty_o); + + const auto& out_ty = out_ty_o; - // - If we're looking for an associated type, allow it to eliminate impossible impls - // > This makes `let v: usize = !0;` work without special cases - if( v.name != "" ) { + // - If we're looking for an associated type, allow it to eliminate impossible impls + // > This makes `let v: usize = !0;` work without special cases auto cmp2 = v.left_ty.compare_with_placeholders(sp, out_ty, context.m_ivars.callback_resolve_infer()); if( cmp2 == ::HIR::Compare::Unequal ) { DEBUG("- (fail) known result can't match (" << context.m_ivars.fmt_type(v.left_ty) << " and " << context.m_ivars.fmt_type(out_ty) << ")"); diff --git a/src/hir_typeck/static.cpp b/src/hir_typeck/static.cpp index 0224fb17..d9972116 100644 --- a/src/hir_typeck/static.cpp +++ b/src/hir_typeck/static.cpp @@ -707,7 +707,25 @@ bool ImplRef::type_is_specializable(const char* name) const os << "none"; } else { - os << "impl" << e.impl->m_params.fmt_args() << " ?" << e.impl->m_trait_args << " for " << e.impl->m_type << e.impl->m_params.fmt_bounds(); + os << "impl"; + if( e.impl->m_params.m_types.size() ) + { + os << "<"; + for( unsigned int i = 0; i < e.impl->m_params.m_types.size(); i ++ ) + { + const auto& ty_d = e.impl->m_params.m_types[i]; + os << ty_d.m_name << " = "; + if( e.params[i] ) { + os << *e.params[i]; + } + else { + os << "?"; + } + os << ","; + } + os << ">"; + } + os << " ?" << e.impl->m_trait_args << " for " << e.impl->m_type << e.impl->m_params.fmt_bounds(); } ), (BoundedPtr, |