diff options
author | John Hodge <tpg@ucc.asn.au> | 2019-06-15 11:29:39 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2019-06-15 11:29:39 +0800 |
commit | 6490e4cdd72c03ed526a8754b48f592b453f5f25 (patch) | |
tree | e1291520e23fec55a2c14ff42ed085c3ea018d19 | |
parent | a9f501bde9d8ff5e714d0ef2663177b0949f95cc (diff) | |
download | mrust-6490e4cdd72c03ed526a8754b48f592b453f5f25.tar.gz |
HIR Annotate - Handle method receivers correctly
-rw-r--r-- | src/hir_expand/annotate_value_usage.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/hir_expand/annotate_value_usage.cpp b/src/hir_expand/annotate_value_usage.cpp index 5a7dfbd8..5ce270bc 100644 --- a/src/hir_expand/annotate_value_usage.cpp +++ b/src/hir_expand/annotate_value_usage.cpp @@ -337,9 +337,32 @@ namespace { } void visit(::HIR::ExprNode_CallMethod& node) override { + { + assert(node.m_cache.m_fcn); + ::HIR::ValueUsage vu = ::HIR::ValueUsage::Borrow; + switch(node.m_cache.m_fcn->m_receiver) + { + case ::HIR::Function::Receiver::Free: + BUG(node.span(), "_CallMethod resolved to free function"); + case ::HIR::Function::Receiver::Value: + case ::HIR::Function::Receiver::Box: + case ::HIR::Function::Receiver::Custom: + case ::HIR::Function::Receiver::BorrowOwned: + vu = ::HIR::ValueUsage::Move; + break; + case ::HIR::Function::Receiver::BorrowUnique: + vu = ::HIR::ValueUsage::Mutate; + break; + case ::HIR::Function::Receiver::BorrowShared: + vu = ::HIR::ValueUsage::Borrow; + break; + //case ::HIR::Function::Receiver::PointerMut: + //case ::HIR::Function::Receiver::PointerConst: + } + auto _ = push_usage( vu ); + this->visit_node_ptr(node.m_value); + } auto _ = push_usage( ::HIR::ValueUsage::Move ); - - this->visit_node_ptr(node.m_value); for( auto& val : node.m_args ) this->visit_node_ptr(val); } |