diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-08 12:26:26 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-08 12:26:26 +0800 |
commit | 1015e9c26c6650a3d4f7f98a15e8b5b8935af9e3 (patch) | |
tree | 0016dc2577ce3c1dc8dbed6c1037a62fb891bd12 /src/mir/from_hir.cpp | |
parent | 2972b0f902bbdb2aab300e371c0fb618aaa928b3 (diff) | |
download | mrust-1015e9c26c6650a3d4f7f98a15e8b5b8935af9e3.tar.gz |
HIR Closures - Rework to correctly support borrow types
Diffstat (limited to 'src/mir/from_hir.cpp')
-rw-r--r-- | src/mir/from_hir.cpp | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index 10f9768d..68aa0ea2 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -1657,23 +1657,12 @@ namespace { { TRACE_FUNCTION_F("_Closure - " << node.m_obj_path); - // Emit construction of the closure. ::std::vector< ::MIR::LValue> vals; - for( const auto cap_idx : node.m_var_captures ) + vals.reserve( node.m_captures.size() ); + for(auto& arg : node.m_captures) { - ASSERT_BUG(node.span(), cap_idx < m_variable_types.size(), "Capture #" << cap_idx << " not in variable set (" << m_variable_types.size() << " total)"); - if( node.m_is_move ) { - vals.push_back( ::MIR::LValue::make_Variable(cap_idx) ); - } - else { - // TODO: Get correct borrow type (based on annotations stored in the node) - auto borrow_ty = ::HIR::BorrowType::Shared; - auto lval = m_builder.lvalue_or_temp( node.span(), - ::HIR::TypeRef::new_borrow(borrow_ty, m_variable_types[cap_idx].clone()), - ::MIR::RValue::make_Borrow({ 0, borrow_ty, ::MIR::LValue::make_Variable(cap_idx) }) - ); - vals.push_back( mv$(lval) ); - } + this->visit_node_ptr(arg); + vals.push_back( m_builder.get_result_in_lvalue(arg->span(), arg->m_res_type) ); } m_builder.set_result( node.span(), ::MIR::RValue::make_Struct({ |