From: lenny.chiadmi-delage Date: Tue, 6 Jan 2026 16:34:52 +0000 (+0000) Subject: gccrs: fixes the error thrown X-Git-Tag: basepoints/gcc-17~1033 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=941c145089f9a305709faee115cdf598635bdbd3;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/parse/rust-parse-impl-expr.hxx b/gcc/rust/parse/rust-parse-impl-expr.hxx index b870273e27c..4de5599d62e 100644 --- a/gcc/rust/parse/rust-parse-impl-expr.hxx +++ b/gcc/rust/parse/rust-parse-impl-expr.hxx @@ -77,11 +77,7 @@ Parser::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::MALFORMED); } @@ -1289,11 +1285,9 @@ Parser::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::CHILD_ERROR); } diff --git a/gcc/rust/parse/rust-parse-impl.hxx b/gcc/rust/parse/rust-parse-impl.hxx index 96d1753d6b2..9766cafa16a 100644 --- a/gcc/rust/parse/rust-parse-impl.hxx +++ b/gcc/rust/parse/rust-parse-impl.hxx @@ -7198,6 +7198,19 @@ Parser::parse_stmt_or_expr () return ExprOrStmt ( std::make_unique (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::MALFORMED); + } } // return expression