diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2020-10-25 17:14:19 -0400 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2020-11-02 13:03:13 -0500 |
| commit | e78e9d4a06192cfbb9e1417fdd7a0753d51684a3 (patch) | |
| tree | 50ad813cd0c21a4d99288be51fe7b837126a7748 /src | |
| parent | 499ebcfdf3b09a646154f321b7c28f5105e4dbf7 (diff) | |
| download | rust-e78e9d4a06192cfbb9e1417fdd7a0753d51684a3.tar.gz rust-e78e9d4a06192cfbb9e1417fdd7a0753d51684a3.zip | |
Treat trailing semicolon as a statement in macro call
See https://github.com/rust-lang/rust/issues/61733#issuecomment-716188981
We now preserve the trailing semicolon in a macro invocation, even if
the macro expands to nothing. As a result, the following code no longer
compiles:
```rust
macro_rules! empty {
() => { }
}
fn foo() -> bool { //~ ERROR mismatched
{ true } //~ ERROR mismatched
empty!();
}
```
Previously, `{ true }` would be considered the trailing expression, even
though there's a semicolon in `empty!();`
This makes macro expansion more token-based.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/macros/empty-trailing-stmt.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/macros/empty-trailing-stmt.stderr | 17 | ||||
| -rw-r--r-- | src/test/ui/proc-macro/meta-macro-hygiene.stdout | 2 |
3 files changed, 28 insertions, 1 deletions
diff --git a/src/test/ui/macros/empty-trailing-stmt.rs b/src/test/ui/macros/empty-trailing-stmt.rs new file mode 100644 index 00000000000..3d78ed4a475 --- /dev/null +++ b/src/test/ui/macros/empty-trailing-stmt.rs @@ -0,0 +1,10 @@ +macro_rules! empty { + () => { } +} + +fn foo() -> bool { //~ ERROR mismatched + { true } //~ ERROR mismatched + empty!(); +} + +fn main() {} diff --git a/src/test/ui/macros/empty-trailing-stmt.stderr b/src/test/ui/macros/empty-trailing-stmt.stderr new file mode 100644 index 00000000000..e88b12712fb --- /dev/null +++ b/src/test/ui/macros/empty-trailing-stmt.stderr @@ -0,0 +1,17 @@ +error[E0308]: mismatched types + --> $DIR/empty-trailing-stmt.rs:6:7 + | +LL | { true } + | ^^^^ expected `()`, found `bool` + +error[E0308]: mismatched types + --> $DIR/empty-trailing-stmt.rs:5:13 + | +LL | fn foo() -> bool { + | --- ^^^^ expected `bool`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/proc-macro/meta-macro-hygiene.stdout b/src/test/ui/proc-macro/meta-macro-hygiene.stdout index 81cebae17ae..a067b7b5411 100644 --- a/src/test/ui/proc-macro/meta-macro-hygiene.stdout +++ b/src/test/ui/proc-macro/meta-macro-hygiene.stdout @@ -40,7 +40,7 @@ macro_rules! produce_it } } -fn main /* 0#0 */() { } +fn main /* 0#0 */() { ; } /* Expansions: |
