diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/backend/rust-compile-stmt.h | 9 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-tyty.h | 8 | ||||
-rw-r--r-- | gcc/rust/rust-gcc.cc | 2 |
3 files changed, 13 insertions, 6 deletions
diff --git a/gcc/rust/backend/rust-compile-stmt.h b/gcc/rust/backend/rust-compile-stmt.h index 0f69fb0..ad34253 100644 --- a/gcc/rust/backend/rust-compile-stmt.h +++ b/gcc/rust/backend/rust-compile-stmt.h @@ -81,6 +81,7 @@ public: bool ok = ctx->get_tyctx ()->lookup_type ( stmt.get_init_expr ()->get_mappings ().get_hirid (), &actual); rust_assert (ok); + tree stmt_type = TyTyResolveCompile::compile (ctx, ty); Location lvalue_locus = stmt.get_pattern ()->get_locus (); Location rvalue_locus = stmt.get_init_expr ()->get_locus (); @@ -90,8 +91,14 @@ public: auto fnctx = ctx->peek_fn (); if (ty->is_unit ()) { - // FIXME this feels wrong ctx->add_statement (init); + + auto unit_type_init_expr + = ctx->get_backend ()->constructor_expression (stmt_type, false, {}, + -1, rvalue_locus); + auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var, + unit_type_init_expr); + ctx->add_statement (s); } else { diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h index a3720f8..52ad2f9 100644 --- a/gcc/rust/backend/rust-compile-tyty.h +++ b/gcc/rust/backend/rust-compile-tyty.h @@ -54,10 +54,10 @@ public: void visit (TyTy::TupleType &type) override { - if (type.num_fields () == 0) - translated = backend->unit_type (); - else - gcc_unreachable (); + // this interface is only for unit-type the -type interface takes into + // account the context + rust_assert (type.num_fields () == 0); + translated = backend->unit_type (); } void visit (TyTy::ArrayType &) override { gcc_unreachable (); } diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc index dfdfe8a5..60923d1 100644 --- a/gcc/rust/rust-gcc.cc +++ b/gcc/rust/rust-gcc.cc @@ -122,7 +122,7 @@ public: static tree unit_type; if (unit_type == nullptr) { - auto unit_type_node = integer_type (true, 0); + auto unit_type_node = struct_type ({}); unit_type = named_type ("()", unit_type_node, ::Linemap::predeclared_location ()); } |