diff options
author | John Hodge <tpg@mutabah.net> | 2016-08-24 10:47:35 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-08-24 10:47:35 +0800 |
commit | 140a8dd00437f3476096885319a955ef99e1618e (patch) | |
tree | b0d497ae40769c91081824e26ba9e3437ec8d969 | |
parent | 3e1589b560591b2d18a82d2f28674eb47597f961 (diff) | |
download | mrust-140a8dd00437f3476096885319a955ef99e1618e.tar.gz |
HIR Typecheck Expr - Fix trait selection for CallValue
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 1aa79ea5..d6c5478a 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -1725,6 +1725,32 @@ namespace { {} })) ); fcn_ret.m_data.as_Path().path.m_data.as_UfcsKnown().trait.m_params.m_types.push_back( fcn_args_tup.clone() ); + + // 3. Locate the most permissive implemented Fn* trait (Fn first, then FnMut, then assume just FnOnce) + // NOTE: Borrowing is added by the expansion to CallPath + if( this->context.m_resolve.find_trait_impls_bound(node.span(), lang_Fn, trait_pp, ty, [&](auto , auto cmp) { + return true; + //return cmp == ::HIR::Compare::Equal; + }) + ) + { + DEBUG("-- Using Fn"); + node.m_trait_used = ::HIR::ExprNode_CallValue::TraitUsed::Fn; + } + else if( this->context.m_resolve.find_trait_impls_bound(node.span(), lang_FnMut, trait_pp, ty, [&](auto , auto cmp) { + return true; + //return cmp == ::HIR::Compare::Equal; + }) + ) + { + DEBUG("-- Using FnMut"); + node.m_trait_used = ::HIR::ExprNode_CallValue::TraitUsed::FnMut; + } + else + { + DEBUG("-- Using FnOnce (default)"); + node.m_trait_used = ::HIR::ExprNode_CallValue::TraitUsed::FnOnce; + } } else if( !ty.m_data.is_Generic() ) { @@ -1742,27 +1768,6 @@ namespace { ERROR(node.span(), E0000, "Unable to find an implementation of Fn* for " << ty); } - // 3. Locate the most permissive implemented Fn* trait (Fn first, then FnMut, then assume just FnOnce) - // NOTE: Borrowing is added by the expansion to CallPath - if( this->context.m_resolve.find_trait_impls(node.span(), lang_Fn, trait_pp, ty, [&](auto , auto cmp) { - return cmp == ::HIR::Compare::Equal; - }) - ) - { - node.m_trait_used = ::HIR::ExprNode_CallValue::TraitUsed::Fn; - } - else if( this->context.m_resolve.find_trait_impls(node.span(), lang_FnMut, trait_pp, ty, [&](auto , auto cmp) { - return cmp == ::HIR::Compare::Equal; - }) - ) - { - node.m_trait_used = ::HIR::ExprNode_CallValue::TraitUsed::FnMut; - } - else - { - node.m_trait_used = ::HIR::ExprNode_CallValue::TraitUsed::FnOnce; - } - node.m_arg_types = mv$( fcn_args_tup.m_data.as_Tuple() ); node.m_arg_types.push_back( mv$(fcn_ret) ); ), |