Skip to content

Commit 78c0153

Browse files
authored
Rollup merge of rust-lang#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.
2 parents 8de9c88 + cadffa7 commit 78c0153

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,9 @@ impl<'a> State<'a> {
13111311
true,
13121312
item.span,
13131313
);
1314+
if macro_def.body.need_semicolon() {
1315+
self.word(";");
1316+
}
13141317
}
13151318
}
13161319
self.ann.post(self, AnnNode::Item(item))

src/test/pretty/macro_rules.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// pp-exact
2+
3+
macro_rules! brace { () => { } ; }
4+
5+
macro_rules! bracket[() => { } ;];
6+
7+
macro_rules! paren(() => { } ;);
8+
9+
macro_rules! matcher_brackets {
10+
(paren) => { } ; (bracket) => { } ; (brace) => { } ;
11+
}
12+
13+
macro_rules! all_fragments {
14+
($ b : block, $ e : expr, $ i : ident, $ it : item, $ l : lifetime, $ lit
15+
: literal, $ m : meta, $ p : pat, $ pth : path, $ s : stmt, $ tt : tt, $
16+
ty : ty, $ vis : vis) => { } ;
17+
}
18+
19+
fn main() { }

0 commit comments

Comments
 (0)