aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse/rust-parse.h
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-03-23 09:28:09 +0000
committerGitHub <noreply@github.com>2022-03-23 09:28:09 +0000
commiteef1ee2638c73e35cc804c2d4ab42598dccea8ac (patch)
tree49e8cb28376b9059702bad0b2ead1fa054ad583b /gcc/rust/parse/rust-parse.h
parentb9720caa100efa6758a5f0d54d3764072d83be41 (diff)
parentef5638186202daac03feed7a20eb975991965403 (diff)
downloadgcc-eef1ee2638c73e35cc804c2d4ab42598dccea8ac.zip
gcc-eef1ee2638c73e35cc804c2d4ab42598dccea8ac.tar.gz
gcc-eef1ee2638c73e35cc804c2d4ab42598dccea8ac.tar.bz2
Merge #1049
1049: Add better restrictions around semicolons in statements r=CohenArthur a=CohenArthur When parsing macro invocations, rustc does not actually consume the statement's trailing semicolon. Let's take the following example: ```rust macro_rules! one_stmt { ($s:stmt) => {}; } macro_rules! one_or_more_stmt { ($($s:stmt)*) => {}; } one_stmt!(let a = 1); one_stmt!(let b = 2;); // error one_or_more_stmt!(;); // valid one_or_more_stmt!(let a = 15;); // valid, two statements! one_or_more_stmt!(let a = 15 let b = 13); // valid, two statements again ``` A semicolon can count as a valid empty statement, but cannot be part of a statement (in macro invocations). This commit adds more restrictions that allow the parser to not always expect a semicolon token after the statement. Furthermore, this fixes a test that was previously accepted by the compiler but not by rustc. Fixes #1046 Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc/rust/parse/rust-parse.h')
-rw-r--r--gcc/rust/parse/rust-parse.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index c86d194..cb77033 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -81,6 +81,7 @@ struct ParseRestrictions
bool entered_from_unary = false;
bool expr_can_be_null = false;
bool expr_can_be_stmt = false;
+ bool consume_semi = true;
};
// Parser implementation for gccrs.
@@ -129,11 +130,9 @@ public:
* | LetStatement
* | ExpressionStatement
* | MacroInvocationSemi
- *
- * @param allow_no_semi Allow the parser to not parse a semicolon after
- * the statement without erroring out
*/
- std::unique_ptr<AST::Stmt> parse_stmt (bool allow_no_semi = false);
+ std::unique_ptr<AST::Stmt> parse_stmt (ParseRestrictions restrictions
+ = ParseRestrictions ());
std::unique_ptr<AST::Type> parse_type ();
std::unique_ptr<AST::ExternalItem> parse_external_item ();
std::unique_ptr<AST::TraitItem> parse_trait_item ();
@@ -616,14 +615,17 @@ private:
* semicolon to follow it
*/
std::unique_ptr<AST::LetStmt> parse_let_stmt (AST::AttrVec outer_attrs,
- bool allow_no_semi = false);
+ ParseRestrictions restrictions
+ = ParseRestrictions ());
std::unique_ptr<AST::ExprStmt> parse_expr_stmt (AST::AttrVec outer_attrs,
- bool allow_no_semi = false);
+ ParseRestrictions restrictions
+ = ParseRestrictions ());
std::unique_ptr<AST::ExprStmtWithBlock>
parse_expr_stmt_with_block (AST::AttrVec outer_attrs);
std::unique_ptr<AST::ExprStmtWithoutBlock>
parse_expr_stmt_without_block (AST::AttrVec outer_attrs,
- bool allow_no_semi = false);
+ ParseRestrictions restrictions
+ = ParseRestrictions ());
ExprOrStmt parse_stmt_or_expr_without_block ();
ExprOrStmt parse_stmt_or_expr_with_block (AST::AttrVec outer_attrs);
ExprOrStmt parse_macro_invocation_maybe_semi (AST::AttrVec outer_attrs);