]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: typecheck: add loop ctx for labelled block
authorJakub Dupak <dev@jakubdupak.com>
Mon, 16 Oct 2023 13:28:03 +0000 (15:28 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:09:21 +0000 (19:09 +0100)
gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add loop ctx.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
gcc/rust/typecheck/rust-hir-type-check-expr.cc

index 4ed84840e88f9691c73d5b62ae3e2695a2437231..7bcd87ec555503275d824835067c6381cfed8eef 100644 (file)
@@ -566,6 +566,10 @@ TypeCheckExpr::visit (HIR::UnsafeBlockExpr &expr)
 void
 TypeCheckExpr::visit (HIR::BlockExpr &expr)
 {
+  if (expr.has_label ())
+    context->push_new_loop_context (expr.get_mappings ().get_hirid (),
+                                   expr.get_locus ());
+
   for (auto &s : expr.get_statements ())
     {
       if (!s->is_item ())
@@ -602,6 +606,20 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr)
   else if (expr.is_tail_reachable ())
     infered
       = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+  else if (expr.has_label ())
+    {
+      TyTy::BaseType *loop_context_type = context->pop_loop_context ();
+
+      bool loop_context_type_infered
+       = (loop_context_type->get_kind () != TyTy::TypeKind::INFER)
+         || ((loop_context_type->get_kind () == TyTy::TypeKind::INFER)
+             && (((TyTy::InferType *) loop_context_type)->get_infer_kind ()
+                 != TyTy::InferType::GENERAL));
+
+      infered = loop_context_type_infered ? loop_context_type
+                                         : TyTy::TupleType::get_unit_type (
+                                           expr.get_mappings ().get_hirid ());
+    }
   else
     {
       // FIXME this seems wrong