From 1c68faaba066e54aa2fd4e9272706c5dd88ca567 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 13 Aug 2016 16:50:30 +0800 Subject: MIR Gen - Destructure enum struct patterns --- src/mir/from_hir.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index 77e39309..4c1455ef 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -130,7 +130,14 @@ namespace { ), (EnumStruct, ASSERT_BUG(sp, allow_refutable, "Refutable pattern not expected - " << pat); - TODO(sp, "Destructure using " << pat); + const auto& enm = *e.binding_ptr; + const auto& fields = enm.m_variants[e.binding_idx].second.as_Struct(); + auto lval_var = ::MIR::LValue::make_Downcast({ box$(mv$(lval)), e.binding_idx }); + for(const auto& fld_pat : e.sub_patterns) + { + unsigned idx = ::std::find_if( fields.begin(), fields.end(), [&](const auto&x){ return x.first == fld_pat.first; } ) - fields.begin(); + destructure_from_ex(sp, fld_pat.second, ::MIR::LValue::make_Field({ box$( lval_var.clone() ), idx}), allow_refutable); + } ), (Slice, ASSERT_BUG(sp, allow_refutable, "Refutable pattern not expected - " << pat); -- cgit v1.2.3