@@ -9,7 +9,7 @@ use rustc_macros::symbols;
99use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder } ;
1010use rustc_serialize:: { UseSpecializedDecodable , UseSpecializedEncodable } ;
1111
12- use std:: cmp:: { PartialEq , Ordering , PartialOrd , Ord } ;
12+ use std:: cmp:: { PartialEq , PartialOrd , Ord } ;
1313use std:: fmt;
1414use std:: hash:: { Hash , Hasher } ;
1515use std:: str;
@@ -766,11 +766,6 @@ impl Ident {
766766 Ident :: with_dummy_span ( kw:: Invalid )
767767 }
768768
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-
774769 /// Maps a string to an identifier with a dummy span.
775770 pub fn from_str ( string : & str ) -> Ident {
776771 Ident :: with_dummy_span ( Symbol :: intern ( string) )
@@ -813,11 +808,6 @@ impl Ident {
813808 pub fn as_str ( self ) -> LocalInternedString {
814809 self . name . as_str ( )
815810 }
816-
817- /// Convert the name to an `InternedString`.
818- pub fn as_interned_str ( self ) -> InternedString {
819- self . name . as_interned_str ( )
820- }
821811}
822812
823813impl PartialEq for Ident {
@@ -903,15 +893,6 @@ impl Symbol {
903893 } )
904894 }
905895
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-
915896 /// Convert to a `LocalInternedString`. This is a slowish operation because
916897 /// it requires locking the symbol interner.
917898 pub fn as_str ( self ) -> LocalInternedString {
@@ -922,11 +903,6 @@ impl Symbol {
922903 } )
923904 }
924905
925- /// Convert to an `InternedString`.
926- pub fn as_interned_str ( self ) -> InternedString {
927- InternedString { symbol : self }
928- }
929-
930906 pub fn as_u32 ( self ) -> u32 {
931907 self . 0 . as_u32 ( )
932908 }
@@ -1105,9 +1081,9 @@ fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
11051081 GLOBALS . with ( |globals| f ( & mut * globals. symbol_interner . lock ( ) ) )
11061082}
11071083
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.
11111087///
11121088/// Because the interner outlives any thread which uses this type, we can
11131089/// 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 {
11161092// FIXME: ensure that the interner outlives any thread which uses
11171093// `LocalInternedString`, by creating a new thread right after constructing the
11181094// interner.
1119- #[ derive( Eq , PartialOrd , Ord ) ]
1095+ #[ derive( Clone , Eq , PartialOrd , Ord ) ]
11201096pub struct LocalInternedString {
11211097 string : & ' static str ,
11221098}
@@ -1157,89 +1133,3 @@ impl fmt::Display for LocalInternedString {
11571133 fmt:: Display :: fmt ( self . string , f)
11581134 }
11591135}
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