aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse/rust-parse.h
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2023-05-10 02:08:37 +0100
committerCohenArthur <arthur.cohen@embecosm.com>2023-05-15 14:48:41 +0000
commit136ef0912e962052446de93d822c4661578d805a (patch)
treedb2ea85cd61fb84218a1bb418b1bd6d70d502d40 /gcc/rust/parse/rust-parse.h
parent4cd88c4cd60bce7a2fd14191334a56ab08ea5181 (diff)
downloadgcc-136ef0912e962052446de93d822c4661578d805a.zip
gcc-136ef0912e962052446de93d822c4661578d805a.tar.gz
gcc-136ef0912e962052446de93d822c4661578d805a.tar.bz2
gccrs: Fix parsing of block expressions followed by `.`
`{ ... }.f;` is parsed as a single statement in rust. This means that we can't determine whether an expression statement will need a semicolon terminator until we finish parsing it. To handle this we change expression parsing to check for this case by inspecting the expression returned from null_denotation and looking ahead for a `.` or `?` token. gcc/rust/ChangeLog: * ast/rust-ast.h (Expr::as_expr_without_block): Remove. (Expr::set_outer_attrs): Make public in base class. * expand/rust-macro-expand.cc: Add fixme comment for pre-existing bug. * hir/tree/rust-hir.h: Remove Expr::as_expr_without_block. * parse/rust-parse-impl.h (Parser::parse_lifetime): Use lifetime_from_token. (Parser::lifetime_from_token): New method. (Parser::null_denotation): Handle labelled loop expressions and for loop expressions. (Parser::parse_loop_label): Make initial token a parameter. (Parser::parse_labelled_loop_expr): Likewise. (Parser::parse_for_loop_expr): Allow FOR token to already be skipped. (Parser::parse_expr): Handle expr_can_be_stmt. (Parser::parse_expr_with_block): Remove. (Parser::parse_expr_stmt_with_block): Remove. (Parser::parse_expr_stmt_without_block): Remove. (Parser::parse_expr_without_block): Remove. (Parser::parse_stmt_or_expr_with_block): Remove. (Parser::parse_expr_stmt): Use parse_expr directly. (Parser::parse_match_expr): Likewise. (Parser::parse_stmt): Use parse_expr_stmt in more cases. (Parser::parse_stmt_or_expr): Rename from parse_stmt_or_expr_without_block, use parse_expr directly. (Parser::parse_block_expr): Update error message. * parse/rust-parse.h: Update declarations. gcc/testsuite/ChangeLog: * rust/compile/for_expr.rs: New test. * rust/compile/issue-407-2.rs: Update compiler output. * rust/compile/issue-407.rs: Update compiler output. * rust/compile/issue-867.rs: Update compiler output. * rust/compile/issue-2189.rs: New test. * rust/compile/macro_call_statement.rs: New test. * rust/compile/stmt_with_block_dot.rs: New test. * rust/compile/torture/loop8.rs: New test. Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>
Diffstat (limited to 'gcc/rust/parse/rust-parse.h')
-rw-r--r--gcc/rust/parse/rust-parse.h22
1 files changed, 5 insertions, 17 deletions
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index a092290..1e7e526 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -276,6 +276,7 @@ private:
template <typename EndTokenPred>
std::vector<AST::Lifetime> parse_lifetime_bounds (EndTokenPred is_end_token);
AST::Lifetime parse_lifetime ();
+ AST::Lifetime lifetime_from_token (const_TokenPtr tok);
std::unique_ptr<AST::ExternalTypeItem>
parse_external_type_item (AST::Visibility vis, AST::AttrVec outer_attrs);
std::unique_ptr<AST::TypeAlias> parse_type_alias (AST::Visibility vis,
@@ -531,13 +532,6 @@ private:
AST::AttrVec outer_attrs,
ParseRestrictions restrictions = ParseRestrictions ());
- // Expression-related (non-Pratt parsed)
- std::unique_ptr<AST::ExprWithBlock>
- parse_expr_with_block (AST::AttrVec outer_attrs);
- std::unique_ptr<AST::ExprWithoutBlock>
- parse_expr_without_block (AST::AttrVec outer_attrs = AST::AttrVec (),
- ParseRestrictions restrictions
- = ParseRestrictions ());
// When given a pratt_parsed_loc, use it as the location of the
// first token parsed in the expression (the parsing of that first
// token should be skipped).
@@ -569,8 +563,9 @@ private:
std::vector<std::unique_ptr<AST::Pattern> >
parse_match_arm_patterns (TokenId end_token_id);
std::unique_ptr<AST::BaseLoopExpr>
- parse_labelled_loop_expr (AST::AttrVec outer_attrs = AST::AttrVec ());
- AST::LoopLabel parse_loop_label ();
+ parse_labelled_loop_expr (const_TokenPtr tok,
+ AST::AttrVec outer_attrs = AST::AttrVec ());
+ AST::LoopLabel parse_loop_label (const_TokenPtr tok);
std::unique_ptr<AST::AsyncBlockExpr>
parse_async_block_expr (AST::AttrVec outer_attrs = AST::AttrVec ());
std::unique_ptr<AST::GroupedExpr> parse_grouped_expr (AST::AttrVec outer_attrs
@@ -637,14 +632,7 @@ private:
std::unique_ptr<AST::ExprStmt> parse_expr_stmt (AST::AttrVec outer_attrs,
ParseRestrictions restrictions
= ParseRestrictions ());
- std::unique_ptr<AST::ExprStmt>
- parse_expr_stmt_with_block (AST::AttrVec outer_attrs);
- std::unique_ptr<AST::ExprStmt>
- parse_expr_stmt_without_block (AST::AttrVec outer_attrs,
- ParseRestrictions restrictions
- = ParseRestrictions ());
- ExprOrStmt parse_stmt_or_expr_without_block ();
- ExprOrStmt parse_stmt_or_expr_with_block (AST::AttrVec outer_attrs);
+ ExprOrStmt parse_stmt_or_expr ();
ExprOrStmt parse_macro_invocation_maybe_semi (AST::AttrVec outer_attrs);
ExprOrStmt parse_path_based_stmt_or_expr (AST::AttrVec outer_attrs);