diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 5f3d691400b..8542be8ea60 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -703,6 +703,7 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::DerefM &mut self, path: &ast::Path, has_bang: bool, + ident: Option, tts: TokenStream, delim: MacDelimiter, span: Span, @@ -711,6 +712,11 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::DerefM if has_bang { self.word("!"); } + if let Some(ident) = ident { + self.space(); + self.print_ident(ident); + self.space(); + } match delim { MacDelimiter::Parenthesis => self.popen(), MacDelimiter::Bracket => self.word("["), @@ -1329,33 +1335,17 @@ impl<'a> State<'a> { self.s.word(";"); } ast::ItemKind::Mac(ref mac) => { - if item.ident.name == kw::Invalid { - self.print_mac(mac); - match mac.node.delim { - MacDelimiter::Brace => {} - _ => self.s.word(";"), - } - } else { - self.print_path(&mac.node.path, false, 0); - self.s.word("! "); - self.print_ident(item.ident); - self.cbox(INDENT_UNIT); - self.popen(); - self.print_tts(mac.node.stream(), true); - self.pclose(); - self.s.word(";"); - self.end(); + self.print_mac(mac); + match mac.node.delim { + MacDelimiter::Brace => {} + _ => self.s.word(";"), } } - ast::ItemKind::MacroDef(ref tts) => { - self.s.word("macro_rules! "); - self.print_ident(item.ident); - self.cbox(INDENT_UNIT); - self.popen(); - self.print_tts(tts.stream(), true); - self.pclose(); - self.s.word(";"); - self.end(); + ast::ItemKind::MacroDef(ref macro_def) => { + let path = &ast::Path::from_ident(ast::Ident::with_empty_ctxt(sym::macro_rules)); + self.print_mac_common( + path, true, Some(item.ident), macro_def.stream(), MacDelimiter::Brace, item.span + ); } } self.ann.post(self, AnnNode::Item(item)) @@ -1743,7 +1733,7 @@ impl<'a> State<'a> { } crate fn print_mac(&mut self, m: &ast::Mac) { - self.print_mac_common(&m.node.path, true, m.node.stream(), m.node.delim, m.span); + self.print_mac_common(&m.node.path, true, None, m.node.stream(), m.node.delim, m.span); } diff --git a/src/test/pretty/cast-lt.pp b/src/test/pretty/cast-lt.pp index 351889da245..c9fd7816360 100644 --- a/src/test/pretty/cast-lt.pp +++ b/src/test/pretty/cast-lt.pp @@ -8,6 +8,6 @@ extern crate std; // pretty-mode:expanded // pp-exact:cast-lt.pp -macro_rules! negative(( $ e : expr ) => { $ e < 0 }); +macro_rules! negative {( $ e : expr ) => { $ e < 0 } } fn main() { (1 as i32) < 0; } diff --git a/src/test/pretty/stmt_expr_attributes.rs b/src/test/pretty/stmt_expr_attributes.rs index d81485b555f..0d438d457bf 100644 --- a/src/test/pretty/stmt_expr_attributes.rs +++ b/src/test/pretty/stmt_expr_attributes.rs @@ -111,7 +111,9 @@ fn _8() { } fn _9() { - macro_rules! stmt_mac(( ) => { let _ = ( ) ; }); + macro_rules! + stmt_mac + {( ) => { let _ = ( ) ; } } #[rustc_dummy] stmt_mac!(); @@ -128,7 +130,7 @@ fn _9() { let _ = (); } -macro_rules! expr_mac(( ) => { ( ) }); +macro_rules! expr_mac {( ) => { ( ) } } fn _10() { let _ = #[rustc_dummy] expr_mac!();