From e6ff2bcc3a6107ecbef6e744c42f5e9b1b007dbe Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Wed, 1 Mar 2023 17:45:51 +0100 Subject: gccrs: parser: Fix while let expr parsing While let expr return unit but are valid construct in rust, they should therefore be included in the parsing code. Also add a new test to check parsing of while let expressions. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_while_let_loop_expr): Prevent hard error on token skip. (Parser::null_denotation): Fix parser for while let expressions. gcc/testsuite/ChangeLog: * rust/compile/while_let_expr.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/parse/rust-parse-impl.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'gcc/rust') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index c6267b2..f7e3cf4b 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -8372,7 +8372,7 @@ Parser::parse_while_let_loop_expr (AST::AttrVec outer_attrs, locus = lexer.peek_token ()->get_locus (); else locus = label.get_locus (); - skip_token (WHILE); + maybe_skip_token (WHILE); /* check for possible accidental recognition of a while loop as a while let * loop */ @@ -13114,9 +13114,16 @@ Parser::null_denotation (const_TokenPtr tok, return parse_loop_expr (std::move (outer_attrs), AST::LoopLabel::error (), tok->get_locus ()); case WHILE: - return parse_while_loop_expr (std::move (outer_attrs), - AST::LoopLabel::error (), - tok->get_locus ()); + if (lexer.peek_token ()->get_id () == LET) + { + return parse_while_let_loop_expr (std::move (outer_attrs)); + } + else + { + return parse_while_loop_expr (std::move (outer_attrs), + AST::LoopLabel::error (), + tok->get_locus ()); + } case MATCH_TOK: // also an expression with block return parse_match_expr (std::move (outer_attrs), tok->get_locus ()); -- cgit v1.1