19
19
) ]
20
20
#![ doc( rust_logo) ]
21
21
#![ 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.
25
22
#![ feature( staged_api) ]
26
23
#![ feature( allow_internal_unstable) ]
27
24
#![ feature( decl_macro) ]
30
27
#![ feature( panic_can_unwind) ]
31
28
#![ feature( restricted_std) ]
32
29
#![ feature( rustc_attrs) ]
33
- #![ feature( min_specialization) ]
34
30
#![ feature( extend_one) ]
35
31
#![ recursion_limit = "256" ]
36
32
#![ allow( internal_features) ]
@@ -185,16 +181,6 @@ impl FromStr for TokenStream {
185
181
}
186
182
}
187
183
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
-
198
184
/// Prints the token stream as a string that is supposed to be losslessly convertible back
199
185
/// into the same token stream (modulo spans), except for possibly `TokenTree::Group`s
200
186
/// with `Delimiter::None` delimiters and negative numeric literals.
@@ -210,7 +196,10 @@ impl ToString for TokenStream {
210
196
impl fmt:: Display for TokenStream {
211
197
#[ allow( clippy:: recursive_format_impl) ] // clippy doesn't see the specialization
212
198
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
+ }
214
203
}
215
204
}
216
205
@@ -756,21 +745,6 @@ impl From<Literal> for TokenTree {
756
745
}
757
746
}
758
747
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
-
774
748
/// Prints the token tree as a string that is supposed to be losslessly convertible back
775
749
/// into the same token tree (modulo spans), except for possibly `TokenTree::Group`s
776
750
/// with `Delimiter::None` delimiters and negative numeric literals.
@@ -786,7 +760,12 @@ impl ToString for TokenTree {
786
760
impl fmt:: Display for TokenTree {
787
761
#[ allow( clippy:: recursive_format_impl) ] // clippy doesn't see the specialization
788
762
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
+ }
790
769
}
791
770
}
792
771
@@ -912,24 +891,14 @@ impl Group {
912
891
}
913
892
}
914
893
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
-
925
894
/// Prints the group as a string that should be losslessly convertible back
926
895
/// into the same group (modulo spans), except for possibly `TokenTree::Group`s
927
896
/// with `Delimiter::None` delimiters.
928
897
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
929
898
impl fmt:: Display for Group {
930
899
#[ allow( clippy:: recursive_format_impl) ] // clippy doesn't see the specialization
931
900
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 ( ) ) ) )
933
902
}
934
903
}
935
904
@@ -1035,14 +1004,6 @@ impl Punct {
1035
1004
}
1036
1005
}
1037
1006
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
-
1046
1007
/// Prints the punctuation character as a string that should be losslessly convertible
1047
1008
/// back into the same character.
1048
1009
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
@@ -1138,14 +1099,6 @@ impl Ident {
1138
1099
}
1139
1100
}
1140
1101
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
-
1149
1102
/// Prints the identifier as a string that should be losslessly convertible back
1150
1103
/// into the same identifier.
1151
1104
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
@@ -1520,14 +1473,6 @@ impl FromStr for Literal {
1520
1473
}
1521
1474
}
1522
1475
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
-
1531
1476
/// Prints the literal as a string that should be losslessly convertible
1532
1477
/// back into the same literal (except for possible rounding for floating point literals).
1533
1478
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
0 commit comments