1919) ]
2020#![ doc( rust_logo) ]
2121#![ feature( rustdoc_internals) ]
22- // This library is copied into rust-analyzer to allow loading rustc compiled proc macros.
23- // Please avoid unstable features where possible to minimize the amount of changes necessary
24- // to make it compile with rust-analyzer on stable.
2522#![ feature( staged_api) ]
2623#![ feature( allow_internal_unstable) ]
2724#![ feature( decl_macro) ]
3027#![ feature( panic_can_unwind) ]
3128#![ feature( restricted_std) ]
3229#![ feature( rustc_attrs) ]
33- #![ feature( min_specialization) ]
3430#![ feature( extend_one) ]
3531#![ recursion_limit = "256" ]
3632#![ allow( internal_features) ]
@@ -185,16 +181,6 @@ impl FromStr for TokenStream {
185181 }
186182}
187183
188- // N.B., the bridge only provides `to_string`, implement `fmt::Display`
189- // based on it (the reverse of the usual relationship between the two).
190- #[ doc( hidden) ]
191- #[ stable( feature = "proc_macro_lib" , since = "1.15.0" ) ]
192- impl ToString for TokenStream {
193- fn to_string ( & self ) -> String {
194- self . 0 . as_ref ( ) . map ( |t| t. to_string ( ) ) . unwrap_or_default ( )
195- }
196- }
197-
198184/// Prints the token stream as a string that is supposed to be losslessly convertible back
199185/// into the same token stream (modulo spans), except for possibly `TokenTree::Group`s
200186/// with `Delimiter::None` delimiters and negative numeric literals.
@@ -210,7 +196,10 @@ impl ToString for TokenStream {
210196impl fmt:: Display for TokenStream {
211197 #[ allow( clippy:: recursive_format_impl) ] // clippy doesn't see the specialization
212198 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
213- f. write_str ( & self . to_string ( ) )
199+ match & self . 0 {
200+ Some ( ts) => write ! ( f, "{}" , ts. to_string( ) ) ,
201+ None => Ok ( ( ) ) ,
202+ }
214203 }
215204}
216205
@@ -756,21 +745,6 @@ impl From<Literal> for TokenTree {
756745 }
757746}
758747
759- // N.B., the bridge only provides `to_string`, implement `fmt::Display`
760- // based on it (the reverse of the usual relationship between the two).
761- #[ doc( hidden) ]
762- #[ stable( feature = "proc_macro_lib" , since = "1.15.0" ) ]
763- impl ToString for TokenTree {
764- fn to_string ( & self ) -> String {
765- match * self {
766- TokenTree :: Group ( ref t) => t. to_string ( ) ,
767- TokenTree :: Ident ( ref t) => t. to_string ( ) ,
768- TokenTree :: Punct ( ref t) => t. to_string ( ) ,
769- TokenTree :: Literal ( ref t) => t. to_string ( ) ,
770- }
771- }
772- }
773-
774748/// Prints the token tree as a string that is supposed to be losslessly convertible back
775749/// into the same token tree (modulo spans), except for possibly `TokenTree::Group`s
776750/// with `Delimiter::None` delimiters and negative numeric literals.
@@ -786,7 +760,12 @@ impl ToString for TokenTree {
786760impl fmt:: Display for TokenTree {
787761 #[ allow( clippy:: recursive_format_impl) ] // clippy doesn't see the specialization
788762 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
789- f. write_str ( & self . to_string ( ) )
763+ match self {
764+ TokenTree :: Group ( t) => write ! ( f, "{t}" ) ,
765+ TokenTree :: Ident ( t) => write ! ( f, "{t}" ) ,
766+ TokenTree :: Punct ( t) => write ! ( f, "{t}" ) ,
767+ TokenTree :: Literal ( t) => write ! ( f, "{t}" ) ,
768+ }
790769 }
791770}
792771
@@ -912,24 +891,14 @@ impl Group {
912891 }
913892}
914893
915- // N.B., the bridge only provides `to_string`, implement `fmt::Display`
916- // based on it (the reverse of the usual relationship between the two).
917- #[ doc( hidden) ]
918- #[ stable( feature = "proc_macro_lib" , since = "1.15.0" ) ]
919- impl ToString for Group {
920- fn to_string ( & self ) -> String {
921- TokenStream :: from ( TokenTree :: from ( self . clone ( ) ) ) . to_string ( )
922- }
923- }
924-
925894/// Prints the group as a string that should be losslessly convertible back
926895/// into the same group (modulo spans), except for possibly `TokenTree::Group`s
927896/// with `Delimiter::None` delimiters.
928897#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
929898impl fmt:: Display for Group {
930899 #[ allow( clippy:: recursive_format_impl) ] // clippy doesn't see the specialization
931900 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
932- f . write_str ( & self . to_string ( ) )
901+ write ! ( f , "{}" , TokenStream :: from ( TokenTree :: from ( self . clone ( ) ) ) )
933902 }
934903}
935904
@@ -1035,14 +1004,6 @@ impl Punct {
10351004 }
10361005}
10371006
1038- #[ doc( hidden) ]
1039- #[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
1040- impl ToString for Punct {
1041- fn to_string ( & self ) -> String {
1042- self . as_char ( ) . to_string ( )
1043- }
1044- }
1045-
10461007/// Prints the punctuation character as a string that should be losslessly convertible
10471008/// back into the same character.
10481009#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
@@ -1138,14 +1099,6 @@ impl Ident {
11381099 }
11391100}
11401101
1141- #[ doc( hidden) ]
1142- #[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
1143- impl ToString for Ident {
1144- fn to_string ( & self ) -> String {
1145- self . 0 . sym . with ( |sym| if self . 0 . is_raw { [ "r#" , sym] . concat ( ) } else { sym. to_owned ( ) } )
1146- }
1147- }
1148-
11491102/// Prints the identifier as a string that should be losslessly convertible back
11501103/// into the same identifier.
11511104#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
@@ -1520,14 +1473,6 @@ impl FromStr for Literal {
15201473 }
15211474}
15221475
1523- #[ doc( hidden) ]
1524- #[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
1525- impl ToString for Literal {
1526- fn to_string ( & self ) -> String {
1527- self . with_stringify_parts ( |parts| parts. concat ( ) )
1528- }
1529- }
1530-
15311476/// Prints the literal as a string that should be losslessly convertible
15321477/// back into the same literal (except for possible rounding for floating point literals).
15331478#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
0 commit comments