Skip to content

Commit

Permalink
pprust: Use print_mac_common for macro_rules definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jul 15, 2019
1 parent 65a714a commit 500b001
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
42 changes: 16 additions & 26 deletions src/libsyntax/print/pprust.rs
Expand Up @@ -703,6 +703,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
&mut self,
path: &ast::Path,
has_bang: bool,
ident: Option<ast::Ident>,
tts: TokenStream,
delim: MacDelimiter,
span: Span,
Expand All @@ -711,6 +712,11 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + 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("["),
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}


Expand Down
2 changes: 1 addition & 1 deletion src/test/pretty/cast-lt.pp
Expand Up @@ -8,6 +8,6 @@
// 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; }
6 changes: 4 additions & 2 deletions src/test/pretty/stmt_expr_attributes.rs
Expand Up @@ -111,7 +111,9 @@ fn _8() {
}

fn _9() {
macro_rules! stmt_mac(( ) => { let _ = ( ) ; });
macro_rules!
stmt_mac
{( ) => { let _ = ( ) ; } }

#[rustc_dummy]
stmt_mac!();
Expand All @@ -128,7 +130,7 @@ fn _9() {
let _ = ();
}

macro_rules! expr_mac(( ) => { ( ) });
macro_rules! expr_mac {( ) => { ( ) } }

fn _10() {
let _ = #[rustc_dummy] expr_mac!();
Expand Down

0 comments on commit 500b001

Please sign in to comment.