diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-02-09 02:40:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-09 02:40:05 +0100 |
| commit | 78c01537576e813e3530cf776f2528bf7c063181 (patch) | |
| tree | 330410997e28b68ed10fea02a426f4435e60e7d1 | |
| parent | 8de9c88b0764d95c2f770a298aa057082bca8108 (diff) | |
| parent | cadffa74df1589011cc7e9c3a19e196e2c73b46c (diff) | |
Rollup merge of #81888 - ehuss:macro_rules-pp, r=petrochenkov
Fix pretty printer macro_rules with semicolon. The pretty printer was not including the trailing semicolon for a macro_rules definition that used parenthesis or brackets, which results in invalid code. This adds the semicolon in those two cases.
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state.rs | 3 | ||||
| -rw-r--r-- | src/test/pretty/macro_rules.rs | 19 |
2 files changed, 22 insertions, 0 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 7f4775bf41a..01e234c9be9 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1311,6 +1311,9 @@ impl<'a> State<'a> { true, item.span, ); + if macro_def.body.need_semicolon() { + self.word(";"); + } } } self.ann.post(self, AnnNode::Item(item)) diff --git a/src/test/pretty/macro_rules.rs b/src/test/pretty/macro_rules.rs new file mode 100644 index 00000000000..da223d164f9 --- /dev/null +++ b/src/test/pretty/macro_rules.rs @@ -0,0 +1,19 @@ +// pp-exact + +macro_rules! brace { () => { } ; } + +macro_rules! bracket[() => { } ;]; + +macro_rules! paren(() => { } ;); + +macro_rules! matcher_brackets { + (paren) => { } ; (bracket) => { } ; (brace) => { } ; +} + +macro_rules! all_fragments { + ($ b : block, $ e : expr, $ i : ident, $ it : item, $ l : lifetime, $ lit + : literal, $ m : meta, $ p : pat, $ pth : path, $ s : stmt, $ tt : tt, $ + ty : ty, $ vis : vis) => { } ; +} + +fn main() { } |
