@@ -5,6 +5,8 @@ use std::ops::{ControlFlow, Deref};
55
66use derive_where:: derive_where;
77#[ cfg( feature = "nightly" ) ]
8+ use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
9+ #[ cfg( feature = "nightly" ) ]
810use rustc_macros:: { Decodable_NoContext , Encodable_NoContext , HashStable_NoContext } ;
911use rustc_type_ir_macros:: {
1012 GenericTypeVisitable , Lift_Generic , TypeFoldable_Generic , TypeVisitable_Generic ,
@@ -1010,10 +1012,7 @@ where
10101012
10111013#[ derive_where( Clone , Copy , PartialEq , Eq , Hash ; I : Interner ) ]
10121014#[ derive( Lift_Generic ) ]
1013- #[ cfg_attr(
1014- feature = "nightly" ,
1015- derive( Encodable_NoContext , Decodable_NoContext , HashStable_NoContext )
1016- ) ]
1015+ #[ cfg_attr( feature = "nightly" , derive( Encodable_NoContext , Decodable_NoContext ) ) ]
10171016pub enum BoundRegionKind < I : Interner > {
10181017 /// An anonymous region parameter for a given fn (&T)
10191018 Anon ,
@@ -1072,21 +1071,15 @@ impl<I: Interner> BoundRegionKind<I> {
10721071
10731072#[ derive_where( Clone , Copy , PartialEq , Eq , Debug , Hash ; I : Interner ) ]
10741073#[ derive( Lift_Generic ) ]
1075- #[ cfg_attr(
1076- feature = "nightly" ,
1077- derive( Encodable_NoContext , Decodable_NoContext , HashStable_NoContext )
1078- ) ]
1074+ #[ cfg_attr( feature = "nightly" , derive( Encodable_NoContext , Decodable_NoContext ) ) ]
10791075pub enum BoundTyKind < I : Interner > {
10801076 Anon ,
10811077 Param ( I :: DefId ) ,
10821078}
10831079
10841080#[ derive_where( Clone , Copy , PartialEq , Eq , Debug , Hash ; I : Interner ) ]
10851081#[ derive( Lift_Generic ) ]
1086- #[ cfg_attr(
1087- feature = "nightly" ,
1088- derive( Encodable_NoContext , Decodable_NoContext , HashStable_NoContext )
1089- ) ]
1082+ #[ cfg_attr( feature = "nightly" , derive( Encodable_NoContext , Decodable_NoContext ) ) ]
10901083pub enum BoundVariableKind < I : Interner > {
10911084 Ty ( BoundTyKind < I > ) ,
10921085 Region ( BoundRegionKind < I > ) ,
@@ -1116,6 +1109,58 @@ impl<I: Interner> BoundVariableKind<I> {
11161109 }
11171110}
11181111
1112+ #[ cfg( feature = "nightly" ) ]
1113+ // This is not a derived impl because a derive would require `I: HashStable`.
1114+ impl < CTX , I : Interner > HashStable < CTX > for BoundRegionKind < I >
1115+ where
1116+ I :: DefId : HashStable < CTX > ,
1117+ I :: Symbol : HashStable < CTX > ,
1118+ {
1119+ #[ inline]
1120+ fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
1121+ std:: mem:: discriminant ( self ) . hash_stable ( hcx, hasher) ;
1122+ match self {
1123+ BoundRegionKind :: Anon | BoundRegionKind :: ClosureEnv => { }
1124+ BoundRegionKind :: NamedForPrinting ( sym) => sym. hash_stable ( hcx, hasher) ,
1125+ BoundRegionKind :: Named ( def_id) => def_id. hash_stable ( hcx, hasher) ,
1126+ }
1127+ }
1128+ }
1129+
1130+ #[ cfg( feature = "nightly" ) ]
1131+ // This is not a derived impl because a derive would require `I: HashStable`.
1132+ impl < CTX , I : Interner > HashStable < CTX > for BoundTyKind < I >
1133+ where
1134+ I :: DefId : HashStable < CTX > ,
1135+ {
1136+ #[ inline]
1137+ fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
1138+ std:: mem:: discriminant ( self ) . hash_stable ( hcx, hasher) ;
1139+ match self {
1140+ BoundTyKind :: Anon => { }
1141+ BoundTyKind :: Param ( def_id) => def_id. hash_stable ( hcx, hasher) ,
1142+ }
1143+ }
1144+ }
1145+
1146+ #[ cfg( feature = "nightly" ) ]
1147+ // This is not a derived impl because a derive would require `I: HashStable`.
1148+ impl < CTX , I : Interner > HashStable < CTX > for BoundVariableKind < I >
1149+ where
1150+ BoundRegionKind < I > : HashStable < CTX > ,
1151+ BoundTyKind < I > : HashStable < CTX > ,
1152+ {
1153+ #[ inline]
1154+ fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
1155+ std:: mem:: discriminant ( self ) . hash_stable ( hcx, hasher) ;
1156+ match self {
1157+ BoundVariableKind :: Ty ( ty) => ty. hash_stable ( hcx, hasher) ,
1158+ BoundVariableKind :: Region ( region) => region. hash_stable ( hcx, hasher) ,
1159+ BoundVariableKind :: Const => { }
1160+ }
1161+ }
1162+ }
1163+
11191164#[ derive_where( Clone , Copy , PartialEq , Eq , Hash ; I : Interner ) ]
11201165#[ cfg_attr(
11211166 feature = "nightly" ,
0 commit comments