]> gcc.gnu.org Git - gcc.git/commit
Merge #1049
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>
Wed, 23 Mar 2022 09:28:09 +0000 (09:28 +0000)
committerGitHub <noreply@github.com>
Wed, 23 Mar 2022 09:28:09 +0000 (09:28 +0000)
commiteef1ee2638c73e35cc804c2d4ab42598dccea8ac
tree49e8cb28376b9059702bad0b2ead1fa054ad583b
parentb9720caa100efa6758a5f0d54d3764072d83be41
parentef5638186202daac03feed7a20eb975991965403
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>
gcc/rust/expand/rust-macro-expand.cc
gcc/rust/parse/rust-parse-impl.h
gcc/rust/parse/rust-parse.h
This page took 0.05868 seconds and 5 git commands to generate.