summaryrefslogtreecommitdiff
path: root/src/mir/from_hir.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-09-06 18:36:56 +0800
committerJohn Hodge <tpg@mutabah.net>2016-09-06 18:36:56 +0800
commit84f82d42a8bd56f1f9dbd62d9d0255554002d315 (patch)
treefa9c5f2c49136f2ec7e793420e265c1a9c4c990a /src/mir/from_hir.cpp
parentde087df3045bb802fe0de3cbb7859ca63d097d50 (diff)
downloadmrust-84f82d42a8bd56f1f9dbd62d9d0255554002d315.tar.gz
MIR Gen - Rough support for Box
Diffstat (limited to 'src/mir/from_hir.cpp')
-rw-r--r--src/mir/from_hir.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 4a540c14..5a0ca03a 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -929,7 +929,13 @@ namespace {
}
else
{
- TODO(node.span(), "Support emitting CoerceUnsized-based _Unsize ops in MIR - " << ty_in << " -> " << ty_out);
+ // NOTES: (from IRC: eddyb)
+ // < eddyb> they're required that T and U are the same struct definition (with different type parameters) and exactly one field differs in type between T and U (ignoring PhantomData)
+ // < eddyb> Mutabah: I forgot to mention that the field that differs in type must also impl CoerceUnsized
+
+ // TODO: Just emit a cast and leave magic handling to codegen
+ // - This code _could_ do inspection of the types and insert a destructure+unsize+restructure, but that does't handle direct `T: CoerceUnsize<U>`
+ m_builder.set_result( node.span(), ::MIR::RValue::make_Cast({ mv$(ptr_lval), node.m_res_type.clone() }) );
}
}
void visit(::HIR::ExprNode_Index& node) override
@@ -1002,13 +1008,25 @@ namespace {
TU_MATCH_DEF( ::HIR::TypeRef::Data, (ty_val.m_data), (te),
(
+ if( m_builder.lang_Box() )
+ {
+ if( ty_val.m_data.is_Path()
+ && ty_val.m_data.as_Path().path.m_data.is_Generic()
+ && ty_val.m_data.as_Path().path.m_data.as_Generic().m_path == *m_builder.lang_Box()
+ )
+ {
+ // Box magically derefs.
+ // HACK: Break out of the switch used for TU_MATCH_DEF
+ break;
+ }
+ }
BUG(sp, "Deref on unsupported type - " << ty_val);
),
- //(Array,
- // ),
(Pointer,
+ // Deref on a pointer - TODO: Requires unsafe
),
(Borrow,
+ // Deref on a borrow - Always valid... assuming borrowck is there :)
)
)