diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-03-29 16:28:11 +0100 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2023-03-30 15:17:53 +0100 |
commit | 98735d4fe7f435170d0bbc3e5f8bee0702afe464 (patch) | |
tree | 12e069c2e44f039a246f87e06178e9efb0c34147 /gcc/rust | |
parent | ea9ae4044000496714d3f0c58f3dba21487247ac (diff) | |
download | gcc-98735d4fe7f435170d0bbc3e5f8bee0702afe464.zip gcc-98735d4fe7f435170d0bbc3e5f8bee0702afe464.tar.gz gcc-98735d4fe7f435170d0bbc3e5f8bee0702afe464.tar.bz2 |
gccrs: handle bare function types with no specified return type
When we have a function with no return type this defaults to (), but we
need to be sure we generate a new implicit HirId for it otherwise it will
end up in a recursive reference chain.
Fixes #2042
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit):
Add implicit unit type as the return type when not specified
gcc/testsuite/ChangeLog:
* rust/compile/issue-2042.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-type.cc | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index eef9b6c..ee683d8 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -70,10 +70,18 @@ TypeCheckType::Resolve (HIR::Type *type) void TypeCheckType::visit (HIR::BareFunctionType &fntype) { - TyTy::BaseType *return_type - = fntype.has_return_type () - ? TypeCheckType::Resolve (fntype.get_return_type ().get ()) - : TyTy::TupleType::get_unit_type (fntype.get_mappings ().get_hirid ()); + TyTy::BaseType *return_type; + if (fntype.has_return_type ()) + { + return_type = TypeCheckType::Resolve (fntype.get_return_type ().get ()); + } + else + { + // needs a new implicit ID + HirId ref = mappings->get_next_hir_id (); + return_type = TyTy::TupleType::get_unit_type (ref); + context->insert_implicit_type (ref, return_type); + } std::vector<TyTy::TyVar> params; for (auto ¶m : fntype.get_function_params ()) |