summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-11-18 12:31:49 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-11-18 17:47:12 +0800
commita28e029ac5c257ea2684899aa5dde3b1b846a96e (patch)
tree2ef3952140786a7b4e7e41cf26709876e153d32e
parenta7cf23f5b4e78cf30e23312d49a6db0217def79e (diff)
downloadmrust-a28e029ac5c257ea2684899aa5dde3b1b846a96e.tar.gz
Const Eval - Use either the result or expected type in _Borrow
-rw-r--r--src/hir_conv/constant_evaluation.cpp15
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) );