Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 500b001

Browse files
committed
pprust: Use print_mac_common for macro_rules definitions
1 parent 65a714a commit 500b001

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

src/libsyntax/print/pprust.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
703703
&mut self,
704704
path: &ast::Path,
705705
has_bang: bool,
706+
ident: Option<ast::Ident>,
706707
tts: TokenStream,
707708
delim: MacDelimiter,
708709
span: Span,
@@ -711,6 +712,11 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
711712
if has_bang {
712713
self.word("!");
713714
}
715+
if let Some(ident) = ident {
716+
self.space();
717+
self.print_ident(ident);
718+
self.space();
719+
}
714720
match delim {
715721
MacDelimiter::Parenthesis => self.popen(),
716722
MacDelimiter::Bracket => self.word("["),
@@ -1329,33 +1335,17 @@ impl<'a> State<'a> {
13291335
self.s.word(";");
13301336
}
13311337
ast::ItemKind::Mac(ref mac) => {
1332-
if item.ident.name == kw::Invalid {
1333-
self.print_mac(mac);
1334-
match mac.node.delim {
1335-
MacDelimiter::Brace => {}
1336-
_ => self.s.word(";"),
1337-
}
1338-
} else {
1339-
self.print_path(&mac.node.path, false, 0);
1340-
self.s.word("! ");
1341-
self.print_ident(item.ident);
1342-
self.cbox(INDENT_UNIT);
1343-
self.popen();
1344-
self.print_tts(mac.node.stream(), true);
1345-
self.pclose();
1346-
self.s.word(";");
1347-
self.end();
1338+
self.print_mac(mac);
1339+
match mac.node.delim {
1340+
MacDelimiter::Brace => {}
1341+
_ => self.s.word(";"),
13481342
}
13491343
}
1350-
ast::ItemKind::MacroDef(ref tts) => {
1351-
self.s.word("macro_rules! ");
1352-
self.print_ident(item.ident);
1353-
self.cbox(INDENT_UNIT);
1354-
self.popen();
1355-
self.print_tts(tts.stream(), true);
1356-
self.pclose();
1357-
self.s.word(";");
1358-
self.end();
1344+
ast::ItemKind::MacroDef(ref macro_def) => {
1345+
let path = &ast::Path::from_ident(ast::Ident::with_empty_ctxt(sym::macro_rules));
1346+
self.print_mac_common(
1347+
path, true, Some(item.ident), macro_def.stream(), MacDelimiter::Brace, item.span
1348+
);
13591349
}
13601350
}
13611351
self.ann.post(self, AnnNode::Item(item))
@@ -1743,7 +1733,7 @@ impl<'a> State<'a> {
17431733
}
17441734

17451735
crate fn print_mac(&mut self, m: &ast::Mac) {
1746-
self.print_mac_common(&m.node.path, true, m.node.stream(), m.node.delim, m.span);
1736+
self.print_mac_common(&m.node.path, true, None, m.node.stream(), m.node.delim, m.span);
17471737
}
17481738

17491739

src/test/pretty/cast-lt.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
// pretty-mode:expanded
99
// pp-exact:cast-lt.pp
1010

11-
macro_rules! negative(( $ e : expr ) => { $ e < 0 });
11+
macro_rules! negative {( $ e : expr ) => { $ e < 0 } }
1212

1313
fn main() { (1 as i32) < 0; }

src/test/pretty/stmt_expr_attributes.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ fn _8() {
111111
}
112112

113113
fn _9() {
114-
macro_rules! stmt_mac(( ) => { let _ = ( ) ; });
114+
macro_rules!
115+
stmt_mac
116+
{( ) => { let _ = ( ) ; } }
115117

116118
#[rustc_dummy]
117119
stmt_mac!();
@@ -128,7 +130,7 @@ fn _9() {
128130
let _ = ();
129131
}
130132

131-
macro_rules! expr_mac(( ) => { ( ) });
133+
macro_rules! expr_mac {( ) => { ( ) } }
132134

133135
fn _10() {
134136
let _ = #[rustc_dummy] expr_mac!();

0 commit comments

Comments
 (0)