https://gcc.gnu.org/g:941c145089f9a305709faee115cdf598635bdbd3
commit r16-7771-g941c145089f9a305709faee115cdf598635bdbd3 Author: lenny.chiadmi-delage <[email protected]> Date: Tue Jan 6 16:34:52 2026 +0000 gccrs: fixes the error thrown 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 <[email protected]> Diff: --- gcc/rust/parse/rust-parse-impl-expr.hxx | 14 ++++---------- gcc/rust/parse/rust-parse-impl.hxx | 13 +++++++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl-expr.hxx b/gcc/rust/parse/rust-parse-impl-expr.hxx index b870273e27c8..4de5599d62e8 100644 --- a/gcc/rust/parse/rust-parse-impl-expr.hxx +++ b/gcc/rust/parse/rust-parse-impl-expr.hxx @@ -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); } diff --git a/gcc/rust/parse/rust-parse-impl.hxx b/gcc/rust/parse/rust-parse-impl.hxx index 96d1753d6b25..9766cafa16a5 100644 --- a/gcc/rust/parse/rust-parse-impl.hxx +++ b/gcc/rust/parse/rust-parse-impl.hxx @@ -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
