diff options
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 4 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-tyty.h | 6 | ||||
-rw-r--r-- | gcc/rust/rust-backend.h | 3 | ||||
-rw-r--r-- | gcc/rust/rust-gcc.cc | 18 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-const-fold.h | 2 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/unit_type2.rs | 8 |
6 files changed, 33 insertions, 8 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 5bd1e96..e0c9352 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -423,7 +423,7 @@ public: { if (type.num_fields () == 0) { - translated = ctx->get_backend ()->void_type (); + translated = ctx->get_backend ()->unit_type (); return; } @@ -544,7 +544,7 @@ public: void visit (TyTy::NeverType &) override { - translated = ctx->get_backend ()->void_type (); + translated = ctx->get_backend ()->unit_type (); } private: diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h index ba98ac0..8576235 100644 --- a/gcc/rust/backend/rust-compile-tyty.h +++ b/gcc/rust/backend/rust-compile-tyty.h @@ -42,8 +42,6 @@ public: return compiler.translated; } - ~TyTyCompile () {} - void visit (TyTy::ErrorType &) override { gcc_unreachable (); } void visit (TyTy::InferType &) override { gcc_unreachable (); } @@ -53,7 +51,7 @@ public: void visit (TyTy::TupleType &type) override { if (type.num_fields () == 0) - translated = backend->void_type (); + translated = backend->unit_type (); else gcc_unreachable (); } @@ -224,7 +222,7 @@ public: void visit (TyTy::NeverType &) override { - translated = backend->void_type (); + translated = backend->unit_type (); } private: diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h index e71d81e..35271b6 100644 --- a/gcc/rust/rust-backend.h +++ b/gcc/rust/rust-backend.h @@ -109,6 +109,9 @@ public: // unsafe.Pointer is represented as *void. virtual Btype *void_type () = 0; + // get unit-type + virtual Btype *unit_type () = 0; + // Get the unnamed boolean type. virtual Btype *bool_type () = 0; diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc index 3158c11..794660e 100644 --- a/gcc/rust/rust-gcc.cc +++ b/gcc/rust/rust-gcc.cc @@ -171,6 +171,19 @@ public: Btype *void_type () { return this->make_type (void_type_node); } + Btype *unit_type () + { + static Btype *unit_type; + if (unit_type == nullptr) + { + auto unit_type_node = integer_type (true, 0); + unit_type = named_type ("()", unit_type_node, + ::Linemap::predeclared_location ()); + } + + return unit_type; + } + Btype *bool_type () { return this->make_type (boolean_type_node); } Btype *char_type () { return this->make_type (char_type_node); } @@ -297,7 +310,10 @@ public: return this->make_expression (null_pointer_node); } - Bexpression *unit_expression () { return this->make_expression (void_node); } + Bexpression *unit_expression () + { + return this->make_expression (integer_zero_node); + } Bexpression *var_expression (Bvariable *var, Location); diff --git a/gcc/rust/typecheck/rust-hir-const-fold.h b/gcc/rust/typecheck/rust-hir-const-fold.h index 4c030c5..c134d51 100644 --- a/gcc/rust/typecheck/rust-hir-const-fold.h +++ b/gcc/rust/typecheck/rust-hir-const-fold.h @@ -54,7 +54,7 @@ public: void visit (TyTy::TupleType &type) override { if (type.num_fields () == 0) - translated = backend->void_type (); + translated = backend->unit_type (); else gcc_unreachable (); } diff --git a/gcc/testsuite/rust/compile/torture/unit_type2.rs b/gcc/testsuite/rust/compile/torture/unit_type2.rs new file mode 100644 index 0000000..b5f9259 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/unit_type2.rs @@ -0,0 +1,8 @@ +fn test(a: ()) -> () { + a +} + +fn main() { + let a; + a = test(()); +} |