summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-12-23 22:31:16 +1100
committerJohn Hodge <tpg@mutabah.net>2016-12-23 22:31:16 +1100
commit4d8c5a1a0ea1fea86e0e8b4be30ce0c77411f9c2 (patch)
tree3fea0ff7c9132de8727a62e00c7d9a591391952f
parent23f87f12c70bca2992006bfac27659761185b134 (diff)
downloadmrust-4d8c5a1a0ea1fea86e0e8b4be30ce0c77411f9c2.tar.gz
MIR Gen - Shortcut in `let` handling to remove a useless temporary
-rw-r--r--src/mir/from_hir.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index a3410d35..655591a5 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -420,12 +420,18 @@ namespace {
{
this->visit_node_ptr(node.m_value);
- if( m_builder.block_active() ) {
- this->destructure_from(node.span(), node.m_pattern, m_builder.get_result_in_lvalue(node.m_value->span(), node.m_type));
- }
- else {
+ if( ! m_builder.block_active() ) {
return ;
}
+
+ if( node.m_pattern.m_binding.is_valid() && node.m_pattern.m_data.is_Any() && node.m_pattern.m_binding.m_type == ::HIR::PatternBinding::Type::Move )
+ {
+ m_builder.push_stmt_assign( node.span(), ::MIR::LValue::make_Variable(node.m_pattern.m_binding.m_slot), m_builder.get_result(node.span()) );
+ }
+ else
+ {
+ this->destructure_from(node.span(), node.m_pattern, m_builder.get_result_in_lvalue(node.m_value->span(), node.m_type));
+ }
}
m_builder.set_result(node.span(), ::MIR::RValue::make_Tuple({}));
}