diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-11-18 12:31:49 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-11-18 17:47:12 +0800 |
commit | a28e029ac5c257ea2684899aa5dde3b1b846a96e (patch) | |
tree | 2ef3952140786a7b4e7e41cf26709876e153d32e /src | |
parent | a7cf23f5b4e78cf30e23312d49a6db0217def79e (diff) | |
download | mrust-a28e029ac5c257ea2684899aa5dde3b1b846a96e.tar.gz |
Const Eval - Use either the result or expected type in _Borrow
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_conv/constant_evaluation.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/hir_conv/constant_evaluation.cpp b/src/hir_conv/constant_evaluation.cpp index 5751b351..09b60fb4 100644 --- a/src/hir_conv/constant_evaluation.cpp +++ b/src/hir_conv/constant_evaluation.cpp @@ -439,18 +439,22 @@ namespace { } void visit(::HIR::ExprNode_Borrow& node) override { + ::HIR::TypeRef exp_ty_inner; TU_MATCH_DEF( ::HIR::TypeRef::Data, (m_exp_type.m_data), (te), ( //ERROR(node.span(), E0000, "Invalid expected type for a &-ptr - " << m_exp_type); + DEBUG("_Borrow: Unknown " << m_exp_type); + exp_ty_inner = m_exp_type.clone(); ), (Infer, ), (Borrow, - auto inner = mv$( *te.inner ); - m_exp_type = mv$(inner); + exp_ty_inner = mv$( *te.inner ); + DEBUG("_Borrow: borrow expecting inner " << exp_ty_inner); ) ) + m_exp_type = exp_ty_inner.clone(); node.m_value->visit(*this); auto val = mv$(m_rv); @@ -459,7 +463,12 @@ namespace { } if( visit_ty_with(m_rv_type, [&](const auto& x){ return x.m_data.is_Infer(); }) ) { - ERROR(node.span(), E0000, "Could not trivially infer type of referenced static - " << m_rv_type << ", lit = " << val); + if( visit_ty_with(exp_ty_inner, [&](const auto& x){ return x.m_data.is_Infer(); }) ) { + ERROR(node.span(), E0000, "Could not trivially infer type of referenced static - " << m_rv_type << ", lit = " << val << ", exp=&" << exp_ty_inner); + } + else { + m_rv_type = mv$(exp_ty_inner); + } } m_rv_type = ::HIR::TypeRef::new_borrow( node.m_type, mv$(m_rv_type) ); |