From a3a343c8853cb0967b21e8da23a829665208b25d Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Wed, 10 Feb 2021 11:03:29 +0000 Subject: Give ParseRestriction option to allow for null parse_expr. The null_denotion function expects to find the beginning of an expression but breaks can be empty and the parser will fail with unexpected ';'. Fixes #225 --- gcc/rust/parse/rust-parse-impl.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'gcc/rust/parse/rust-parse-impl.h') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index d391304..18e6983 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -7437,7 +7437,10 @@ Parser::parse_break_expr ( } // parse break return expression if it exists - std::unique_ptr return_expr = parse_expr (); + ParseRestrictions restrictions; + restrictions.expr_can_be_null = true; + std::unique_ptr return_expr + = parse_expr (std::vector (), restrictions); return std::unique_ptr ( new AST::BreakExpr (locus, std::move (label), std::move (return_expr), @@ -12461,9 +12464,10 @@ Parser::null_denotation ( // array definition expr (not indexing) return parse_array_expr (std::move (outer_attrs), true); default: - rust_error_at (tok->get_locus (), - "found unexpected token %qs in null denotation", - tok->get_token_description ()); + if (!restrictions.expr_can_be_null) + rust_error_at (tok->get_locus (), + "found unexpected token %qs in null denotation", + tok->get_token_description ()); return nullptr; } } -- cgit v1.1