summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--src/hir_typeck/expr_check.cpp20
-rw-r--r--src/mir/from_hir.cpp17
3 files changed, 18 insertions, 23 deletions
diff --git a/Makefile b/Makefile
index a67ce723..def10c5b 100644
--- a/Makefile
+++ b/Makefile
@@ -162,10 +162,10 @@ test_rustos: $(addprefix output/rust_os/,libkernel.hir)
output/rust_os/libkernel.hir: ../rust_os/Kernel/Core/main.rs output/libstack_dst.hir $(BIN)
@mkdir -p $(dir $@)
- $(BIN) $< -o $@ 2>&1 | tee $@.txt | tail -n 30
+ $(DBG) $(BIN) $< -o $@ $(PIPECMD)
output/libstack_dst.hir: ../rust_os/externals/crates.io/stack_dst/src/lib.rs $(BIN)
@mkdir -p $(dir $@)
- $(BIN) $< -o $@ --cfg feature=no_std 2>&1 | tee $@.txt | tail -n 30
+ $(DBG) $(BIN) $< -o $@ --cfg feature=no_std $(PIPECMD)
# -------------------------------
diff --git a/src/hir_typeck/expr_check.cpp b/src/hir_typeck/expr_check.cpp
index fda3d51e..d0b2a21b 100644
--- a/src/hir_typeck/expr_check.cpp
+++ b/src/hir_typeck/expr_check.cpp
@@ -315,20 +315,10 @@ namespace {
}
const auto& src_ty = *se.inner;
const auto& dst_ty = *de.inner;
- // Check unsizability (including trait impls)
- // TODO: Unsize trait?
- TU_MATCH_DEF(::HIR::TypeRef::Data, (dst_ty.m_data), (e),
- (
- ERROR(sp, E0000, "Invalid unsizing operation to " << dst_ty << " from " << src_ty);
- ),
- (TraitObject,
- // TODO: Ensure that the source type impls all the required traits
- // - Must be sized unless it's a superset TraitObject
- ),
- (Slice,
- // TODO: Ensure that the source is an array (or impls Unsize)
- )
- )
+
+ const auto& lang_Unsize = this->get_lang_item_path(node.span(), "unsize");
+ // _ == < `src_ty` as Unsize< `dst_ty` >::""
+ check_associated_type(sp, ::HIR::TypeRef(), lang_Unsize, ::make_vec1( dst_ty.clone() ), src_ty, "");
}
else if( src_ty.m_data.is_Borrow() || dst_ty.m_data.is_Borrow() )
{
@@ -337,7 +327,7 @@ namespace {
else
{
const auto& lang_CoerceUnsized = this->get_lang_item_path(node.span(), "coerce_unsized");
- // _ == < `src_ty` as CoerceUnsize< `dst_ty` >::""
+ // _ == < `src_ty` as CoerceUnsized< `dst_ty` >::""
check_associated_type(sp, ::HIR::TypeRef(), lang_CoerceUnsized, ::make_vec1( dst_ty.clone() ), src_ty, "");
}
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 29d8d42c..5111320c 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -989,13 +989,18 @@ namespace {
const auto& ty_in = *ie.inner;
TU_MATCH_DEF( ::HIR::TypeRef::Data, (ty_out.m_data), (e),
(
- TODO(node.span(), "MIR _Unsize to " << ty_out);
+ const auto& lang_Unsize = m_builder.crate().get_lang_item_path(node.span(), "unsize");
+ if( m_builder.resolve().find_impl( node.span(), lang_Unsize, ::HIR::PathParams(ty_out.clone()), ty_in.clone(), [](auto ){ return true; }) )
+ {
+ // - HACK: Emit a cast operation on the pointers. Leave it up to monomorph to 'fix' it
+ m_builder.set_result( node.span(), ::MIR::RValue::make_Cast({ mv$(ptr_lval), node.m_res_type.clone() }) );
+ }
+ else
+ {
+ // Probably an error.
+ TODO(node.span(), "MIR _Unsize to " << ty_out);
+ }
),
- // TODO: Unsize custom types containing a ?Size generic - See the Unsize trait
- //(Path,
- // ),
- //(Generic,
- // ),
(Slice,
if( ty_in.m_data.is_Array() )
{