@@ -177,7 +177,7 @@ impl<'tcx> CtxtInterners<'tcx> {
177
177
178
178
#[ inline( never) ]
179
179
fn intern_const ( & self , ty : Ty < ' tcx > , val : ty:: ConstKind < ' tcx > ) -> & ' tcx Const < ' tcx > {
180
- self . const_ . intern ( Const { ty, val } , |c| Interned ( self . arena . alloc ( c) ) ) . 0
180
+ self . const_ . intern ( CstHash ( Const { ty, val } ) , |c| Interned ( self . arena . alloc ( c. 0 ) ) ) . 0
181
181
}
182
182
}
183
183
@@ -934,13 +934,10 @@ impl<'tcx> CommonLifetimes<'tcx> {
934
934
935
935
impl < ' tcx > CommonConsts < ' tcx > {
936
936
fn new ( interners : & CtxtInterners < ' tcx > , types : & CommonTypes < ' tcx > ) -> CommonConsts < ' tcx > {
937
- let mk_const = |c| interners . const_ . intern ( c , |c| Interned ( interners. arena . alloc ( c ) ) ) . 0 ;
937
+ let mk_const = |ty , val| interners. intern_const ( ty , val ) ;
938
938
939
939
CommonConsts {
940
- unit : mk_const ( ty:: Const {
941
- val : ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: ZST ) ) ,
942
- ty : types. unit ,
943
- } ) ,
940
+ unit : mk_const ( types. unit , ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: ZST ) ) ) ,
944
941
}
945
942
}
946
943
}
@@ -2060,22 +2057,45 @@ impl<'tcx, T> Borrow<[T]> for Interned<'tcx, List<T>> {
2060
2057
2061
2058
impl < ' tcx > PartialEq for Interned < ' tcx , Const < ' tcx > > {
2062
2059
fn eq ( & self , other : & Self ) -> bool {
2063
- self . 0 == other. 0
2060
+ self . 0 . ty == other. 0 . ty && self . 0 . val == other . 0 . val
2064
2061
}
2065
2062
}
2066
2063
2067
2064
impl < ' tcx > Eq for Interned < ' tcx , Const < ' tcx > > { }
2068
2065
2066
+ #[ repr( transparent) ]
2067
+ #[ derive( Clone , Copy ) ]
2068
+ struct CstHash < ' tcx > ( Const < ' tcx > ) ;
2069
+
2070
+ impl < ' tcx > Hash for CstHash < ' tcx > {
2071
+ fn hash < H : Hasher > ( & self , state : & mut H ) {
2072
+ self . 0 . ty . hash ( state) ;
2073
+ self . 0 . val . hash ( state) ;
2074
+ }
2075
+ }
2076
+
2077
+ impl < ' tcx > PartialEq for CstHash < ' tcx > {
2078
+ fn eq ( & self , other : & Self ) -> bool {
2079
+ self . 0 . ty == other. 0 . ty && self . 0 . val == other. 0 . val
2080
+ }
2081
+ }
2082
+
2083
+ impl Eq for CstHash < ' tcx > { }
2084
+
2069
2085
impl < ' tcx > Hash for Interned < ' tcx , Const < ' tcx > > {
2070
2086
fn hash < H : Hasher > ( & self , state : & mut H ) {
2071
2087
self . 0 . ty . hash ( state) ;
2072
2088
self . 0 . val . hash ( state) ;
2073
2089
}
2074
2090
}
2075
2091
2076
- impl < ' tcx > Borrow < Const < ' tcx > > for Interned < ' tcx , Const < ' tcx > > {
2077
- fn borrow ( & self ) -> & Const < ' tcx > {
2078
- & self . 0
2092
+ impl < ' tcx > Borrow < CstHash < ' tcx > > for Interned < ' tcx , Const < ' tcx > > {
2093
+ fn borrow ( & self ) -> & CstHash < ' tcx > {
2094
+ let c: & Const < ' tcx > = & self . 0 ;
2095
+ unsafe {
2096
+ // SAFETY: safe because CstHash is repr(transparent) over Const
2097
+ & * ( c as * const Const < ' tcx > as * const CstHash < ' tcx > )
2098
+ }
2079
2099
}
2080
2100
}
2081
2101
0 commit comments