diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mir/from_hir.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index a2faeeb5..9b9ddf5c 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -208,25 +208,36 @@ namespace { ASSERT_BUG(sp, allow_refutable, "Refutable pattern not expected - " << pat); ), (EnumValue, - ASSERT_BUG(sp, allow_refutable, "Refutable pattern not expected - " << pat); + const auto& enm = *e.binding_ptr; + if( enm.m_variants.size() > 1 ) + { + ASSERT_BUG(sp, allow_refutable, "Refutable pattern not expected - " << pat); + } ), (EnumTuple, - ASSERT_BUG(sp, allow_refutable, "Refutable pattern not expected - " << pat); - auto lval_var = ::MIR::LValue::make_Downcast({ box$(mv$(lval)), e.binding_idx }); - for(unsigned int i = 0; i < e.sub_patterns.size(); i ++ ) + const auto& enm = *e.binding_ptr; + if( enm.m_variants.size() > 1 ) { - destructure_from_ex(sp, e.sub_patterns[i], ::MIR::LValue::make_Field({ box$( lval_var.clone() ), i}), allow_refutable); + ASSERT_BUG(sp, allow_refutable, "Refutable pattern not expected - " << pat); + auto lval_var = ::MIR::LValue::make_Downcast({ box$(mv$(lval)), e.binding_idx }); + for(unsigned int i = 0; i < e.sub_patterns.size(); i ++ ) + { + destructure_from_ex(sp, e.sub_patterns[i], ::MIR::LValue::make_Field({ box$( lval_var.clone() ), i}), allow_refutable); + } } ), (EnumStruct, ASSERT_BUG(sp, allow_refutable, "Refutable pattern not expected - " << 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) + if( enm.m_variants.size() > 1 ) { - 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); + 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, |