@@ -621,12 +621,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
621621 } else {
622622 match attr. tokens . trees ( ) . next ( ) {
623623 Some ( TokenTree :: Delimited ( _, delim, tts) ) => {
624- let delim = match delim {
625- DelimToken :: Brace => MacDelimiter :: Brace ,
626- DelimToken :: Bracket => MacDelimiter :: Bracket ,
627- DelimToken :: Paren | DelimToken :: NoDelim => MacDelimiter :: Parenthesis ,
628- } ;
629- self . print_mac_common ( & attr. path , false , None , tts, delim, attr. span ) ;
624+ self . print_mac_common (
625+ Some ( & attr. path ) , false , None , delim, tts, true , attr. span
626+ ) ;
630627 }
631628 tree => {
632629 self . print_path ( & attr. path , false , 0 ) ;
@@ -692,13 +689,11 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
692689 _ => { }
693690 }
694691 }
695- TokenTree :: Delimited ( _, delim, tts) => {
696- self . word ( token_kind_to_string ( & token:: OpenDelim ( delim) ) ) ;
697- self . space ( ) ;
698- self . print_tts ( tts, convert_dollar_crate) ;
699- self . space ( ) ;
700- self . word ( token_kind_to_string ( & token:: CloseDelim ( delim) ) )
701- } ,
692+ TokenTree :: Delimited ( dspan, delim, tts) => {
693+ self . print_mac_common (
694+ None , false , None , delim, tts, convert_dollar_crate, dspan. entire ( )
695+ ) ;
696+ }
702697 }
703698 }
704699
@@ -715,14 +710,17 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
715710
716711 fn print_mac_common (
717712 & mut self ,
718- path : & ast:: Path ,
713+ path : Option < & ast:: Path > ,
719714 has_bang : bool ,
720715 ident : Option < ast:: Ident > ,
716+ delim : DelimToken ,
721717 tts : TokenStream ,
722- delim : MacDelimiter ,
718+ convert_dollar_crate : bool ,
723719 span : Span ,
724720 ) {
725- self . print_path ( path, false , 0 ) ;
721+ if let Some ( path) = path {
722+ self . print_path ( path, false , 0 ) ;
723+ }
726724 if has_bang {
727725 self . word ( "!" ) ;
728726 }
@@ -732,18 +730,20 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
732730 self . space ( ) ;
733731 }
734732 match delim {
735- MacDelimiter :: Parenthesis => self . popen ( ) ,
736- MacDelimiter :: Bracket => self . word ( "[" ) ,
737- MacDelimiter :: Brace => {
733+ DelimToken :: Paren => self . popen ( ) ,
734+ DelimToken :: Bracket => self . word ( "[" ) ,
735+ DelimToken :: NoDelim => self . word ( " " ) ,
736+ DelimToken :: Brace => {
738737 self . head ( "" ) ;
739738 self . bopen ( ) ;
740739 }
741740 }
742- self . print_tts ( tts, true ) ;
741+ self . print_tts ( tts, convert_dollar_crate ) ;
743742 match delim {
744- MacDelimiter :: Parenthesis => self . pclose ( ) ,
745- MacDelimiter :: Bracket => self . word ( "]" ) ,
746- MacDelimiter :: Brace => self . bclose ( span) ,
743+ DelimToken :: Paren => self . pclose ( ) ,
744+ DelimToken :: Bracket => self . word ( "]" ) ,
745+ DelimToken :: NoDelim => self . word ( " " ) ,
746+ DelimToken :: Brace => self . bclose ( span) ,
747747 }
748748 }
749749
@@ -1356,9 +1356,14 @@ impl<'a> State<'a> {
13561356 }
13571357 }
13581358 ast:: ItemKind :: MacroDef ( ref macro_def) => {
1359- let path = & ast:: Path :: from_ident ( ast:: Ident :: with_empty_ctxt ( sym:: macro_rules) ) ;
13601359 self . print_mac_common (
1361- path, true , Some ( item. ident ) , macro_def. stream ( ) , MacDelimiter :: Brace , item. span
1360+ Some ( & ast:: Path :: from_ident ( ast:: Ident :: with_empty_ctxt ( sym:: macro_rules) ) ) ,
1361+ true ,
1362+ Some ( item. ident ) ,
1363+ DelimToken :: Brace ,
1364+ macro_def. stream ( ) ,
1365+ true ,
1366+ item. span ,
13621367 ) ;
13631368 }
13641369 }
@@ -1747,10 +1752,11 @@ impl<'a> State<'a> {
17471752 }
17481753
17491754 crate fn print_mac ( & mut self , m : & ast:: Mac ) {
1750- self . print_mac_common ( & m. node . path , true , None , m. node . stream ( ) , m. node . delim , m. span ) ;
1755+ self . print_mac_common (
1756+ Some ( & m. node . path ) , true , None , m. node . delim . to_token ( ) , m. node . stream ( ) , true , m. span
1757+ ) ;
17511758 }
17521759
1753-
17541760 fn print_call_post ( & mut self , args : & [ P < ast:: Expr > ] ) {
17551761 self . popen ( ) ;
17561762 self . commasep_exprs ( Inconsistent , args) ;
0 commit comments