diff options
author | John Hodge <tpg@mutabah.net> | 2016-08-13 16:50:30 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-08-13 16:50:30 +0800 |
commit | 1c68faaba066e54aa2fd4e9272706c5dd88ca567 (patch) | |
tree | d4256bd0a4acf6b461631bf8a6b1ff170b6ae0f1 /src/mir/from_hir.cpp | |
parent | 36dd3a38f93a589c06de57c8a4f98bd92a6e0026 (diff) | |
download | mrust-1c68faaba066e54aa2fd4e9272706c5dd88ca567.tar.gz |
MIR Gen - Destructure enum struct patterns
Diffstat (limited to 'src/mir/from_hir.cpp')
-rw-r--r-- | src/mir/from_hir.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
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); |