@@ -588,7 +588,7 @@ impl fmt::Display for TokenTree {
588
588
/// A delimited token stream.
589
589
///
590
590
/// A `Group` internally contains a `TokenStream` which is surrounded by `Delimiter`s.
591
- #[ derive( Clone , Debug ) ]
591
+ #[ derive( Clone ) ]
592
592
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
593
593
pub struct Group {
594
594
delimiter : Delimiter ,
@@ -682,12 +682,23 @@ impl fmt::Display for Group {
682
682
}
683
683
}
684
684
685
+ #[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
686
+ impl fmt:: Debug for Group {
687
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
688
+ f. debug_struct ( "Group" )
689
+ . field ( "delimiter" , & self . delimiter ( ) )
690
+ . field ( "stream" , & self . stream ( ) )
691
+ . field ( "span" , & self . span ( ) )
692
+ . finish ( )
693
+ }
694
+ }
695
+
685
696
/// An `Punct` is an single punctuation character like `+`, `-` or `#`.
686
697
///
687
698
/// Multicharacter operators like `+=` are represented as two instances of `Punct` with different
688
699
/// forms of `Spacing` returned.
689
700
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
690
- #[ derive( Clone , Debug ) ]
701
+ #[ derive( Clone ) ]
691
702
pub struct Punct {
692
703
ch : char ,
693
704
spacing : Spacing ,
@@ -771,8 +782,19 @@ impl fmt::Display for Punct {
771
782
}
772
783
}
773
784
785
+ #[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
786
+ impl fmt:: Debug for Punct {
787
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
788
+ f. debug_struct ( "Punct" )
789
+ . field ( "ch" , & self . as_char ( ) )
790
+ . field ( "spacing" , & self . spacing ( ) )
791
+ . field ( "span" , & self . span ( ) )
792
+ . finish ( )
793
+ }
794
+ }
795
+
774
796
/// An identifier (`ident`).
775
- #[ derive( Clone , Debug ) ]
797
+ #[ derive( Clone ) ]
776
798
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
777
799
pub struct Ident {
778
800
sym : Symbol ,
@@ -851,17 +873,25 @@ impl Ident {
851
873
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
852
874
impl fmt:: Display for Ident {
853
875
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
854
- if self . is_raw {
855
- f. write_str ( "r#" ) ?;
856
- }
857
- self . sym . as_str ( ) . fmt ( f)
876
+ TokenStream :: from ( TokenTree :: from ( self . clone ( ) ) ) . fmt ( f)
877
+ }
878
+ }
879
+
880
+ #[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
881
+ impl fmt:: Debug for Ident {
882
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
883
+ f. debug_struct ( "Ident" )
884
+ . field ( "ident" , & self . to_string ( ) )
885
+ . field ( "span" , & self . span ( ) )
886
+ . finish ( )
858
887
}
859
888
}
860
889
861
890
/// A literal string (`"hello"`), byte string (`b"hello"`),
862
891
/// character (`'a'`), byte character (`b'a'`), an integer or floating point number
863
892
/// with or without a suffix (`1`, `1u8`, `2.3`, `2.3f32`).
864
893
/// Boolean literals like `true` and `false` do not belong here, they are `Ident`s.
894
+ // FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
865
895
#[ derive( Clone , Debug ) ]
866
896
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
867
897
pub struct Literal {
0 commit comments