@@ -871,14 +871,17 @@ impl UseSpecializedDecodable for Ident {
871
871
872
872
/// An interned string.
873
873
///
874
- /// Internally, a `Symbol` is implemented as an index, and all operations
875
- /// (including hashing, equality, and ordering) operate on that index. The use
876
- /// of `rustc_index::newtype_index!` means that `Option<Symbol>` only takes up 4 bytes,
877
- /// because `rustc_index::newtype_index!` reserves the last 256 values for tagging purposes.
874
+ /// Internally, a `Symbol` is implemented as an index. Ordering and hashing use
875
+ /// the underlying string chars. Equality uses the index, but because of the
876
+ /// interning this is equivalent to using the underlying string chars.
877
+ ///
878
+ /// The use of `rustc_index::newtype_index!` means that `Option<Symbol>` only
879
+ /// takes up 4 bytes, because `rustc_index::newtype_index!` reserves the last
880
+ /// 256 values for tagging purposes.
878
881
///
879
882
/// Note that `Symbol` cannot directly be a `rustc_index::newtype_index!` because it
880
883
/// implements `fmt::Debug`, `Encodable`, and `Decodable` in special ways.
881
- #[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
884
+ #[ derive( Clone , Copy , PartialEq , Eq ) ]
882
885
pub struct Symbol ( SymbolIndex ) ;
883
886
884
887
rustc_index:: newtype_index! {
@@ -932,6 +935,30 @@ impl Symbol {
932
935
}
933
936
}
934
937
938
+ impl PartialOrd for Symbol {
939
+ fn partial_cmp ( & self , other : & Symbol ) -> Option < Ordering > {
940
+ if self == other {
941
+ return Some ( Ordering :: Equal ) ;
942
+ }
943
+ self . with2 ( * other, |self_str, other_str| self_str. partial_cmp ( other_str) )
944
+ }
945
+ }
946
+
947
+ impl Ord for Symbol {
948
+ fn cmp ( & self , other : & Symbol ) -> Ordering {
949
+ if self == other {
950
+ return Ordering :: Equal ;
951
+ }
952
+ self . with2 ( * other, |self_str, other_str| self_str. cmp ( other_str) )
953
+ }
954
+ }
955
+
956
+ impl Hash for Symbol {
957
+ fn hash < H : Hasher > ( & self , state : & mut H ) {
958
+ self . with ( |str| str. hash ( state) )
959
+ }
960
+ }
961
+
935
962
impl fmt:: Debug for Symbol {
936
963
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
937
964
self . with ( |str| fmt:: Debug :: fmt ( & str, f) )
@@ -1028,7 +1055,7 @@ pub mod sym {
1028
1055
1029
1056
impl Symbol {
1030
1057
fn is_used_keyword_2018 ( self ) -> bool {
1031
- self >= kw:: Async && self <= kw:: Dyn
1058
+ self . 0 >= kw:: Async . 0 && self . 0 <= kw:: Dyn . 0
1032
1059
}
1033
1060
1034
1061
fn is_unused_keyword_2018 ( self ) -> bool {
@@ -1037,7 +1064,7 @@ impl Symbol {
1037
1064
1038
1065
/// Used for sanity checking rustdoc keyword sections.
1039
1066
pub fn is_doc_keyword ( self ) -> bool {
1040
- self <= kw:: Union
1067
+ self . 0 <= kw:: Union . 0
1041
1068
}
1042
1069
1043
1070
/// A keyword or reserved identifier that can be used as a path segment.
@@ -1065,20 +1092,20 @@ impl Ident {
1065
1092
// Returns `true` for reserved identifiers used internally for elided lifetimes,
1066
1093
// unnamed method parameters, crate root module, error recovery etc.
1067
1094
pub fn is_special ( self ) -> bool {
1068
- self . name <= kw:: Underscore
1095
+ self . name . 0 <= kw:: Underscore . 0
1069
1096
}
1070
1097
1071
1098
/// Returns `true` if the token is a keyword used in the language.
1072
1099
pub fn is_used_keyword ( self ) -> bool {
1073
1100
// Note: `span.edition()` is relatively expensive, don't call it unless necessary.
1074
- self . name >= kw:: As && self . name <= kw:: While ||
1101
+ self . name . 0 >= kw:: As . 0 && self . name . 0 <= kw:: While . 0 ||
1075
1102
self . name . is_used_keyword_2018 ( ) && self . span . rust_2018 ( )
1076
1103
}
1077
1104
1078
1105
/// Returns `true` if the token is a keyword reserved for possible future use.
1079
1106
pub fn is_unused_keyword ( self ) -> bool {
1080
1107
// Note: `span.edition()` is relatively expensive, don't call it unless necessary.
1081
- self . name >= kw:: Abstract && self . name <= kw:: Yield ||
1108
+ self . name . 0 >= kw:: Abstract . 0 && self . name . 0 <= kw:: Yield . 0 ||
1082
1109
self . name . is_unused_keyword_2018 ( ) && self . span . rust_2018 ( )
1083
1110
}
1084
1111
0 commit comments