@@ -20,6 +20,11 @@ use syntax_pos::{DUMMY_SP, FileName, Span};
2020
2121use std:: borrow:: Cow ;
2222
23+ pub enum MacHeader < ' a > {
24+ Path ( & ' a ast:: Path ) ,
25+ Keyword ( & ' static str ) ,
26+ }
27+
2328pub enum AnnNode < ' a > {
2429 Ident ( & ' a ast:: Ident ) ,
2530 Name ( & ' a ast:: Name ) ,
@@ -620,7 +625,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
620625 match attr. tokens . trees ( ) . next ( ) {
621626 Some ( TokenTree :: Delimited ( _, delim, tts) ) => {
622627 self . print_mac_common (
623- Some ( & attr. path ) , false , None , delim, tts, true , attr. span
628+ Some ( MacHeader :: Path ( & attr. path ) ) , false , None , delim, tts, true , attr. span
624629 ) ;
625630 }
626631 tree => {
@@ -706,7 +711,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
706711
707712 fn print_mac_common (
708713 & mut self ,
709- path : Option < & ast :: Path > ,
714+ header : Option < MacHeader < ' _ > > ,
710715 has_bang : bool ,
711716 ident : Option < ast:: Ident > ,
712717 delim : DelimToken ,
@@ -717,8 +722,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
717722 if delim == DelimToken :: Brace {
718723 self . cbox ( INDENT_UNIT ) ;
719724 }
720- if let Some ( path) = path {
721- self . print_path ( path, false , 0 ) ;
725+ match header {
726+ Some ( MacHeader :: Path ( path) ) => self . print_path ( path, false , 0 ) ,
727+ Some ( MacHeader :: Keyword ( kw) ) => self . word ( kw) ,
728+ None => { }
722729 }
723730 if has_bang {
724731 self . word ( "!" ) ;
@@ -729,7 +736,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
729736 }
730737 match delim {
731738 DelimToken :: Brace => {
732- if path . is_some ( ) || has_bang || ident. is_some ( ) {
739+ if header . is_some ( ) || has_bang || ident. is_some ( ) {
733740 self . nbsp ( ) ;
734741 }
735742 self . word ( "{" ) ;
@@ -1357,9 +1364,11 @@ impl<'a> State<'a> {
13571364 }
13581365 }
13591366 ast:: ItemKind :: MacroDef ( ref macro_def) => {
1367+ let ( kw, has_bang) =
1368+ if macro_def. legacy { ( "macro_rules" , true ) } else { ( "macro" , false ) } ;
13601369 self . print_mac_common (
1361- Some ( & ast :: Path :: from_ident ( ast :: Ident :: with_empty_ctxt ( sym :: macro_rules ) ) ) ,
1362- true ,
1370+ Some ( MacHeader :: Keyword ( kw ) ) ,
1371+ has_bang ,
13631372 Some ( item. ident ) ,
13641373 DelimToken :: Brace ,
13651374 macro_def. stream ( ) ,
@@ -1754,7 +1763,13 @@ impl<'a> State<'a> {
17541763
17551764 crate fn print_mac ( & mut self , m : & ast:: Mac ) {
17561765 self . print_mac_common (
1757- Some ( & m. node . path ) , true , None , m. node . delim . to_token ( ) , m. node . stream ( ) , true , m. span
1766+ Some ( MacHeader :: Path ( & m. node . path ) ) ,
1767+ true ,
1768+ None ,
1769+ m. node . delim . to_token ( ) ,
1770+ m. node . stream ( ) ,
1771+ true ,
1772+ m. span ,
17581773 ) ;
17591774 }
17601775
0 commit comments