summaryrefslogtreecommitdiff
path: root/src/hir_expand/annotate_value_usage.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-11-04 09:21:52 +0800
committerJohn Hodge <tpg@mutabah.net>2016-11-04 09:21:52 +0800
commit996f0418da0efca90b7c3eb3a2839e9d766f6903 (patch)
tree9f550f481382b94e67eb8f24c02593b2b2649923 /src/hir_expand/annotate_value_usage.cpp
parente9230c242d8e1a6cfad67167c34e7ba5308fde0c (diff)
downloadmrust-996f0418da0efca90b7c3eb3a2839e9d766f6903.tar.gz
HIR Expand - Struct constructor base values don't always move
Diffstat (limited to 'src/hir_expand/annotate_value_usage.cpp')
-rw-r--r--src/hir_expand/annotate_value_usage.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/hir_expand/annotate_value_usage.cpp b/src/hir_expand/annotate_value_usage.cpp
index 0650e52c..04be9644 100644
--- a/src/hir_expand/annotate_value_usage.cpp
+++ b/src/hir_expand/annotate_value_usage.cpp
@@ -254,8 +254,10 @@ namespace {
void visit(::HIR::ExprNode_Field& node) override
{
+ bool is_copy = m_resolve.type_is_copy(node.span(), node.m_res_type);
+ DEBUG("ty = " << node.m_res_type << ", is_copy=" << is_copy);
// If taking this field by value, but the type is Copy - pretend it's a borrow.
- if( this->get_usage() == ::HIR::ValueUsage::Move && m_resolve.type_is_copy(node.span(), node.m_res_type) ) {
+ if( this->get_usage() == ::HIR::ValueUsage::Move && is_copy ) {
auto _ = push_usage( ::HIR::ValueUsage::Borrow );
this->visit_node_ptr(node.m_value);
}
@@ -310,11 +312,13 @@ namespace {
void visit(::HIR::ExprNode_StructLiteral& node) override
{
- auto _ = push_usage( ::HIR::ValueUsage::Move );
-
if( node.m_base_value ) {
+ // TODO: If only Copy fields will be used, set usage to Borrow
+ auto _ = push_usage( ::HIR::ValueUsage::Move );
this->visit_node_ptr(node.m_base_value);
}
+
+ auto _ = push_usage( ::HIR::ValueUsage::Move );
for( auto& fld_val : node.m_values ) {
this->visit_node_ptr(fld_val.second);
}