diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-21 17:27:05 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-22 16:00:30 +0100 |
commit | ef5638186202daac03feed7a20eb975991965403 (patch) | |
tree | 247ff565c1d06636f05afbd5cd7af555e6d160bb /gcc/rust/parse/rust-parse.cc | |
parent | cc6e405912c83aee41efd3015d9157cdbe9134fe (diff) | |
download | gcc-ef5638186202daac03feed7a20eb975991965403.zip gcc-ef5638186202daac03feed7a20eb975991965403.tar.gz gcc-ef5638186202daac03feed7a20eb975991965403.tar.bz2 |
parser: Add better restrictions around semicolons in statements
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.
Diffstat (limited to 'gcc/rust/parse/rust-parse.cc')
0 files changed, 0 insertions, 0 deletions