@@ -9,7 +9,7 @@ use rustc_macros::symbols;
9
9
use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder } ;
10
10
use rustc_serialize:: { UseSpecializedDecodable , UseSpecializedEncodable } ;
11
11
12
- use std:: cmp:: { PartialEq , Ordering , PartialOrd , Ord } ;
12
+ use std:: cmp:: { PartialEq , PartialOrd , Ord } ;
13
13
use std:: fmt;
14
14
use std:: hash:: { Hash , Hasher } ;
15
15
use std:: str;
@@ -766,11 +766,6 @@ impl Ident {
766
766
Ident :: with_dummy_span ( kw:: Invalid )
767
767
}
768
768
769
- /// Maps an interned string to an identifier with an empty syntax context.
770
- pub fn from_interned_str ( string : InternedString ) -> Ident {
771
- Ident :: with_dummy_span ( string. as_symbol ( ) )
772
- }
773
-
774
769
/// Maps a string to an identifier with a dummy span.
775
770
pub fn from_str ( string : & str ) -> Ident {
776
771
Ident :: with_dummy_span ( Symbol :: intern ( string) )
@@ -813,11 +808,6 @@ impl Ident {
813
808
pub fn as_str ( self ) -> LocalInternedString {
814
809
self . name . as_str ( )
815
810
}
816
-
817
- /// Convert the name to an `InternedString`.
818
- pub fn as_interned_str ( self ) -> InternedString {
819
- self . name . as_interned_str ( )
820
- }
821
811
}
822
812
823
813
impl PartialEq for Ident {
@@ -903,15 +893,6 @@ impl Symbol {
903
893
} )
904
894
}
905
895
906
- /// Access two symbols' chars. This is a slowish operation because it
907
- /// requires locking the symbol interner, but it is faster than calling
908
- /// `with()` twice.
909
- fn with2 < F : FnOnce ( & str , & str ) -> R , R > ( self , other : Symbol , f : F ) -> R {
910
- with_interner ( |interner| {
911
- f ( interner. get ( self ) , interner. get ( other) )
912
- } )
913
- }
914
-
915
896
/// Convert to a `LocalInternedString`. This is a slowish operation because
916
897
/// it requires locking the symbol interner.
917
898
pub fn as_str ( self ) -> LocalInternedString {
@@ -922,11 +903,6 @@ impl Symbol {
922
903
} )
923
904
}
924
905
925
- /// Convert to an `InternedString`.
926
- pub fn as_interned_str ( self ) -> InternedString {
927
- InternedString { symbol : self }
928
- }
929
-
930
906
pub fn as_u32 ( self ) -> u32 {
931
907
self . 0 . as_u32 ( )
932
908
}
@@ -1105,9 +1081,9 @@ fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
1105
1081
GLOBALS . with ( |globals| f ( & mut * globals. symbol_interner . lock ( ) ) )
1106
1082
}
1107
1083
1108
- /// An alternative to `Symbol` and `InternedString` , useful when the chars
1109
- /// within the symbol need to be accessed. It deliberately has limited
1110
- /// functionality and should only be used for temporary values.
1084
+ /// An alternative to `Symbol`, useful when the chars within the symbol need to
1085
+ /// be accessed. It deliberately has limited functionality and should only be
1086
+ /// used for temporary values.
1111
1087
///
1112
1088
/// Because the interner outlives any thread which uses this type, we can
1113
1089
/// safely treat `string` which points to interner data, as an immortal string,
@@ -1116,7 +1092,7 @@ fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
1116
1092
// FIXME: ensure that the interner outlives any thread which uses
1117
1093
// `LocalInternedString`, by creating a new thread right after constructing the
1118
1094
// interner.
1119
- #[ derive( Eq , PartialOrd , Ord ) ]
1095
+ #[ derive( Clone , Eq , PartialOrd , Ord ) ]
1120
1096
pub struct LocalInternedString {
1121
1097
string : & ' static str ,
1122
1098
}
@@ -1157,89 +1133,3 @@ impl fmt::Display for LocalInternedString {
1157
1133
fmt:: Display :: fmt ( self . string , f)
1158
1134
}
1159
1135
}
1160
-
1161
- /// An alternative to `Symbol` that is focused on string contents.
1162
- ///
1163
- /// Its implementations of `Hash`, `PartialOrd` and `Ord` work with the
1164
- /// string chars rather than the symbol integer. This is useful when hash
1165
- /// stability is required across compile sessions, or a guaranteed sort
1166
- /// ordering is required.
1167
- #[ derive( Clone , Copy , PartialEq , Eq ) ]
1168
- pub struct InternedString {
1169
- symbol : Symbol ,
1170
- }
1171
-
1172
- impl InternedString {
1173
- /// Maps a string to its interned representation.
1174
- pub fn intern ( string : & str ) -> Self {
1175
- InternedString {
1176
- symbol : Symbol :: intern ( string)
1177
- }
1178
- }
1179
-
1180
- pub fn with < F : FnOnce ( & str ) -> R , R > ( self , f : F ) -> R {
1181
- self . symbol . with ( f)
1182
- }
1183
-
1184
- fn with2 < F : FnOnce ( & str , & str ) -> R , R > ( self , other : & InternedString , f : F ) -> R {
1185
- self . symbol . with2 ( other. symbol , f)
1186
- }
1187
-
1188
- pub fn as_symbol ( self ) -> Symbol {
1189
- self . symbol
1190
- }
1191
-
1192
- /// Convert to a `LocalInternedString`. This is a slowish operation because it
1193
- /// requires locking the symbol interner.
1194
- pub fn as_str ( self ) -> LocalInternedString {
1195
- self . symbol . as_str ( )
1196
- }
1197
- }
1198
-
1199
- impl Hash for InternedString {
1200
- fn hash < H : Hasher > ( & self , state : & mut H ) {
1201
- self . with ( |str| str. hash ( state) )
1202
- }
1203
- }
1204
-
1205
- impl PartialOrd < InternedString > for InternedString {
1206
- fn partial_cmp ( & self , other : & InternedString ) -> Option < Ordering > {
1207
- if self . symbol == other. symbol {
1208
- return Some ( Ordering :: Equal ) ;
1209
- }
1210
- self . with2 ( other, |self_str, other_str| self_str. partial_cmp ( other_str) )
1211
- }
1212
- }
1213
-
1214
- impl Ord for InternedString {
1215
- fn cmp ( & self , other : & InternedString ) -> Ordering {
1216
- if self . symbol == other. symbol {
1217
- return Ordering :: Equal ;
1218
- }
1219
- self . with2 ( other, |self_str, other_str| self_str. cmp ( other_str) )
1220
- }
1221
- }
1222
-
1223
- impl fmt:: Debug for InternedString {
1224
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1225
- self . with ( |str| fmt:: Debug :: fmt ( & str, f) )
1226
- }
1227
- }
1228
-
1229
- impl fmt:: Display for InternedString {
1230
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1231
- self . with ( |str| fmt:: Display :: fmt ( & str, f) )
1232
- }
1233
- }
1234
-
1235
- impl Decodable for InternedString {
1236
- fn decode < D : Decoder > ( d : & mut D ) -> Result < InternedString , D :: Error > {
1237
- Ok ( InternedString :: intern ( & d. read_str ( ) ?) )
1238
- }
1239
- }
1240
-
1241
- impl Encodable for InternedString {
1242
- fn encode < S : Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
1243
- self . with ( |string| s. emit_str ( string) )
1244
- }
1245
- }
0 commit comments