about summary refs log tree commit diff
path: root/compiler/rustc_ast
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2020-10-25 17:14:19 -0400
committerAaron Hill <aa1ronham@gmail.com>2020-11-02 13:03:13 -0500
commite78e9d4a06192cfbb9e1417fdd7a0753d51684a3 (patch)
tree50ad813cd0c21a4d99288be51fe7b837126a7748 /compiler/rustc_ast
parent499ebcfdf3b09a646154f321b7c28f5105e4dbf7 (diff)
downloadrust-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 'compiler/rustc_ast')
-rw-r--r--compiler/rustc_ast/src/ast.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index 7d5e235c885..f13d67b9c15 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -905,6 +905,13 @@ pub struct Stmt {
 }
 
 impl Stmt {
+    pub fn has_trailing_semicolon(&self) -> bool {
+        match &self.kind {
+            StmtKind::Semi(_) => true,
+            StmtKind::MacCall(mac) => matches!(mac.style, MacStmtStyle::Semicolon),
+            _ => false,
+        }
+    }
     pub fn add_trailing_semicolon(mut self) -> Self {
         self.kind = match self.kind {
             StmtKind::Expr(expr) => StmtKind::Semi(expr),