diff options
author | John Hodge <tpg@mutabah.net> | 2018-12-26 23:36:18 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-12-26 23:36:18 +0800 |
commit | 2744a49ad3f3a8ff138ee0fd9b90244f3b5d7853 (patch) | |
tree | a5efed927163ebe399d0ef3150b953f2919cb0d9 /src | |
parent | e842fbbc375907b13b69d0f53de6dc3149804c13 (diff) | |
download | mrust-2744a49ad3f3a8ff138ee0fd9b90244f3b5d7853.tar.gz |
Typecheck Expressions - Handle changes to the `box` operator for 1.29 (still needs work later down the line)
`box` no longer has operator traits, and is (I believe) back to being
100% compiler magic.
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index a7c5ddee..7f58be4e 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -2354,7 +2354,29 @@ namespace { ) this->m_completed = true; } - void visit(::HIR::ExprNode_Emplace& node) override { + void visit_emplace_129(::HIR::ExprNode_Emplace& node) { + const auto& sp = node.span(); + const auto& exp_ty = this->context.get_type(node.m_res_type); + const auto& data_ty = this->context.get_type(node.m_value->m_res_type); + const auto& placer_ty = this->context.get_type(node.m_place->m_res_type); + const auto& lang_Boxed = this->context.m_lang_Box; + TRACE_FUNCTION_F("exp_ty=" << exp_ty << ", data_ty=" << data_ty << ", placer_ty" << placer_ty); + ASSERT_BUG(sp, node.m_type == ::HIR::ExprNode_Emplace::Type::Boxer, "1.29 mode with non-box _Emplace node"); + ASSERT_BUG(sp, placer_ty == ::HIR::TypeRef::new_unit(), "1.29 mode with box in syntax - placer type is " << placer_ty); + + ASSERT_BUG(sp, !lang_Boxed.m_components.empty(), "`owbed_box` not present when `box` operator used"); + + // NOTE: `owned_box` shouldn't point to anything but a struct + const auto& str = this->context.m_crate.get_struct_by_path(sp, lang_Boxed); + // TODO: Store this type to avoid having to construct it every pass + auto boxed_ty = ::HIR::TypeRef::new_path( ::HIR::GenericPath(lang_Boxed, {data_ty.clone()}), &str ); + + // TODO: is there anyting special about this node that might need revisits? + + context.equate_types(sp, exp_ty, boxed_ty); + this->m_completed = true; + } + void visit_emplace_119(::HIR::ExprNode_Emplace& node) { const auto& sp = node.span(); const auto& exp_ty = this->context.get_type(node.m_res_type); const auto& data_ty = this->context.get_type(node.m_value->m_res_type); @@ -2449,6 +2471,16 @@ namespace { this->m_completed = true; } + void visit(::HIR::ExprNode_Emplace& node) override { + switch(gTargetVersion) + { + case TargetVersion::Rustc1_19: + return visit_emplace_119(node); + case TargetVersion::Rustc1_29: + return visit_emplace_129(node); + } + throw "BUG: Unhandled target version"; + } void visit(::HIR::ExprNode_TupleVariant& node) override { no_revisit(node); |