summaryrefslogtreecommitdiff
path: root/src/hir_expand/annotate_value_usage.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-11-25 15:41:39 +0800
committerJohn Hodge <tpg@mutabah.net>2016-11-25 15:41:39 +0800
commit167959d6fb7ff5b2dee029a1622e42860b1ef10a (patch)
treefdc018c87274282615df663b738d7d5626c5b057 /src/hir_expand/annotate_value_usage.cpp
parent86526ec2ee28c87d199f9632132d761bbce9d7de (diff)
downloadmrust-167959d6fb7ff5b2dee029a1622e42860b1ef10a.tar.gz
HIR Expand - Fix usage annotations for _CallValue
Diffstat (limited to 'src/hir_expand/annotate_value_usage.cpp')
-rw-r--r--src/hir_expand/annotate_value_usage.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/hir_expand/annotate_value_usage.cpp b/src/hir_expand/annotate_value_usage.cpp
index 5ddfd39b..08c35492 100644
--- a/src/hir_expand/annotate_value_usage.cpp
+++ b/src/hir_expand/annotate_value_usage.cpp
@@ -282,7 +282,27 @@ namespace {
}
void visit(::HIR::ExprNode_CallValue& node) override
{
- auto _ = push_usage( ::HIR::ValueUsage::Move );
+ // TODO: Different usage based on trait.
+ ::HIR::ValueUsage vu = ::HIR::ValueUsage::Borrow;
+ switch( node.m_trait_used )
+ {
+ case ::HIR::ExprNode_CallValue::TraitUsed::Unknown:
+ //TODO(node.span(), "Annotate usage when CallValue trait is unknown");
+ // - Can only happen when the callee is a closure, could do detectection of closure class in this pass?
+ // - Assume Move for now.
+ vu = ::HIR::ValueUsage::Move;
+ break;
+ case ::HIR::ExprNode_CallValue::TraitUsed::Fn:
+ vu = ::HIR::ValueUsage::Borrow;
+ break;
+ case ::HIR::ExprNode_CallValue::TraitUsed::FnMut:
+ vu = ::HIR::ValueUsage::Mutate;
+ break;
+ case ::HIR::ExprNode_CallValue::TraitUsed::FnOnce:
+ vu = ::HIR::ValueUsage::Move;
+ break;
+ }
+ auto _ = push_usage( vu );
this->visit_node_ptr(node.m_value);
for( auto& val : node.m_args )