@@ -20,6 +20,11 @@ use syntax_pos::{DUMMY_SP, FileName, Span};
20
20
21
21
use std:: borrow:: Cow ;
22
22
23
+ pub enum MacHeader < ' a > {
24
+ Path ( & ' a ast:: Path ) ,
25
+ Keyword ( & ' static str ) ,
26
+ }
27
+
23
28
pub enum AnnNode < ' a > {
24
29
Ident ( & ' a ast:: Ident ) ,
25
30
Name ( & ' a ast:: Name ) ,
@@ -620,7 +625,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
620
625
match attr. tokens . trees ( ) . next ( ) {
621
626
Some ( TokenTree :: Delimited ( _, delim, tts) ) => {
622
627
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
624
629
) ;
625
630
}
626
631
tree => {
@@ -706,7 +711,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
706
711
707
712
fn print_mac_common (
708
713
& mut self ,
709
- path : Option < & ast :: Path > ,
714
+ header : Option < MacHeader < ' _ > > ,
710
715
has_bang : bool ,
711
716
ident : Option < ast:: Ident > ,
712
717
delim : DelimToken ,
@@ -717,8 +722,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
717
722
if delim == DelimToken :: Brace {
718
723
self . cbox ( INDENT_UNIT ) ;
719
724
}
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 => { }
722
729
}
723
730
if has_bang {
724
731
self . word ( "!" ) ;
@@ -729,7 +736,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
729
736
}
730
737
match delim {
731
738
DelimToken :: Brace => {
732
- if path . is_some ( ) || has_bang || ident. is_some ( ) {
739
+ if header . is_some ( ) || has_bang || ident. is_some ( ) {
733
740
self . nbsp ( ) ;
734
741
}
735
742
self . word ( "{" ) ;
@@ -1357,9 +1364,11 @@ impl<'a> State<'a> {
1357
1364
}
1358
1365
}
1359
1366
ast:: ItemKind :: MacroDef ( ref macro_def) => {
1367
+ let ( kw, has_bang) =
1368
+ if macro_def. legacy { ( "macro_rules" , true ) } else { ( "macro" , false ) } ;
1360
1369
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 ,
1363
1372
Some ( item. ident ) ,
1364
1373
DelimToken :: Brace ,
1365
1374
macro_def. stream ( ) ,
@@ -1754,7 +1763,13 @@ impl<'a> State<'a> {
1754
1763
1755
1764
crate fn print_mac ( & mut self , m : & ast:: Mac ) {
1756
1765
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 ,
1758
1773
) ;
1759
1774
}
1760
1775
0 commit comments