]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fixes the error thrown
authorlenny.chiadmi-delage <lenny.chiadmi-delage@epita.fr>
Tue, 6 Jan 2026 16:34:52 +0000 (16:34 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 27 Feb 2026 14:57:05 +0000 (15:57 +0100)
Removes duplicate error in block expression parsing.
Removes cascading error in match arm parsing.
Adds proper error detection for unterminated expression.

Fixes Rust-GCC/gccrs#1210

gcc/rust/ChangeLog:

* parse/rust-parse-impl-expr.hxx: Removes duplicate errors.
* parse/rust-parse-impl.hxx: Detects when an expression without
block is not properly terminated

Signed-off-by: lenny.chiadmi-delage <lenny.chiadmi-delage@epita.fr>
gcc/rust/parse/rust-parse-impl-expr.hxx
gcc/rust/parse/rust-parse-impl.hxx

index b870273e27c8b948a51447af266ca07b31766b28..4de5599d62e86e861d6d88b7ef13898b3461f013 100644 (file)
@@ -77,11 +77,7 @@ Parser<ManagedTokenSource>::parse_block_expr (
 
   if (!skip_token (RIGHT_CURLY))
     {
-      Error error (t->get_locus (),
-                  "error may be from having an expression (as opposed to "
-                  "statement) in the body of the function but not last");
-      add_error (std::move (error));
-
+      // We don't need to throw an error as it already reported by skip_token
       skip_after_end_block ();
       return tl::unexpected<Parse::Error::Node> (Parse::Error::Node::MALFORMED);
     }
@@ -1289,11 +1285,9 @@ Parser<ManagedTokenSource>::parse_match_expr (AST::AttrVec outer_attrs,
 
       if (!expr)
        {
-         Error error (lexer.peek_token ()->get_locus (),
-                      "failed to parse expr in match arm in match expr");
-         add_error (std::move (error));
-
-         // skip somewhere?
+         /* We don't need to throw an error as it already reported by
+          * parse_expr
+          */
          return tl::unexpected<Parse::Error::Node> (
            Parse::Error::Node::CHILD_ERROR);
        }
index 96d1753d6b2537b36ae3382d78fe144bbfd21485..9766cafa16a5a59fed86ddc1fe675269e5739810 100644 (file)
@@ -7198,6 +7198,19 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr ()
        return ExprOrStmt (
          std::make_unique<AST::ExprStmt> (std::move (expr.value ()),
                                           t->get_locus (), false));
+
+      // Check if expr_without_block is properly terminated
+      if (expr.value ()->is_expr_without_block ()
+         && after_expr->get_id () != RIGHT_CURLY)
+       {
+         // expr_without_block must be followed by ';' or '}'
+         Error error (after_expr->get_locus (),
+                      "expected %<;%> or %<}%> after expression, found %qs",
+                      after_expr->get_token_description ());
+         add_error (std::move (error));
+         return tl::unexpected<Parse::Error::Node> (
+           Parse::Error::Node::MALFORMED);
+       }
     }
 
   // return expression