diff options
author | John Hodge <tpg@ucc.asn.au> | 2019-01-01 18:16:10 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2019-01-01 18:16:10 +0800 |
commit | b7c4d85d6642a68fc8fcfd1e0466f3b9dae41b30 (patch) | |
tree | ed09d72d58229bfd2a9a6c544b5403bb47294a61 | |
parent | 11a9f976f334534bdaf6e6f7dc4f74f08446c7ee (diff) | |
download | mrust-b7c4d85d6642a68fc8fcfd1e0466f3b9dae41b30.tar.gz |
Match ergonomics - Fixes and expansion
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 10 | ||||
-rw-r--r-- | src/mir/from_hir.cpp | 5 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 04cb6f17..041247ba 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -3816,11 +3816,18 @@ void Context::handle_pattern(const Span& sp, ::HIR::Pattern& pat, const ::HIR::T if( pattern.m_binding.is_valid() ) { // - Binding present, use the current binding mode + pattern.m_binding.m_type = binding_mode; switch(binding_mode) { case ::HIR::PatternBinding::Type::Move: context.equate_types(sp, context.get_var(sp, pattern.m_binding.m_slot), type); break; + case ::HIR::PatternBinding::Type::MutRef: + context.equate_types(sp, context.get_var(sp, pattern.m_binding.m_slot), ::HIR::TypeRef::new_borrow(::HIR::BorrowType::Unique, type.clone())); + break; + case ::HIR::PatternBinding::Type::Ref: + context.equate_types(sp, context.get_var(sp, pattern.m_binding.m_slot), ::HIR::TypeRef::new_borrow(::HIR::BorrowType::Shared, type.clone())); + break; default: TODO(sp, "Assign variable type using mode " << (int)binding_mode << " and " << type); } @@ -3832,7 +3839,8 @@ void Context::handle_pattern(const Span& sp, ::HIR::Pattern& pat, const ::HIR::T ::HIR::BorrowType bt = ::HIR::BorrowType::Owned; const auto* ty_p = &context.get_type(type); while( ty_p->m_data.is_Borrow() ) { - bt = ::std::max(bt, ty_p->m_data.as_Borrow().type); + DEBUG("bt " << bt << ", " << ty_p->m_data.as_Borrow().type); + bt = ::std::min(bt, ty_p->m_data.as_Borrow().type); ty_p = &context.get_type( *ty_p->m_data.as_Borrow().inner ); n_deref ++; } diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index 2c45f5bb..bea8a38c 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -207,6 +207,11 @@ namespace { allow_refutable = 2; } + for(size_t i = 0; i < pat.m_implicit_deref_count; i ++) + { + lval = ::MIR::LValue::make_Deref({ box$( mv$(lval) ) }); + } + TU_MATCH_HDRA( (pat.m_data), {) TU_ARMA(Any, e) { } |