@@ -28,9 +28,9 @@ use crate::ty::TyKind::*;
28
28
use crate :: ty:: { self , DefIdTree , Ty , TypeAndMut } ;
29
29
use crate :: ty:: { AdtDef , AdtKind , Const , Region } ;
30
30
use crate :: ty:: { BindingMode , BoundVar } ;
31
+ use crate :: ty:: { ConstKind , InferConst , ParamConst } ;
31
32
use crate :: ty:: { ConstVid , FloatVar , FloatVid , IntVar , IntVid , TyVar , TyVid } ;
32
33
use crate :: ty:: { ExistentialPredicate , Predicate , PredicateKind } ;
33
- use crate :: ty:: { InferConst , ParamConst } ;
34
34
use crate :: ty:: { InferTy , ParamTy , PolyFnSig , ProjectionTy } ;
35
35
use crate :: ty:: { List , TyKind , TyS } ;
36
36
use rustc_ast:: ast;
@@ -856,9 +856,10 @@ impl<'tcx> CommonConsts<'tcx> {
856
856
let mk_const = |c| interners. const_ . intern ( c, |c| Interned ( interners. arena . alloc ( c) ) ) . 0 ;
857
857
858
858
CommonConsts {
859
- unit : mk_const ( ty:: Const {
860
- val : ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: zst ( ) ) ) ,
859
+ unit : mk_const ( Const {
861
860
ty : types. unit ,
861
+ val : ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: zst ( ) ) ) ,
862
+ _priv : ty:: sty:: PrivateMarker ( ( ) ) ,
862
863
} ) ,
863
864
}
864
865
}
@@ -1909,6 +1910,21 @@ impl<'tcx> Borrow<TyKind<'tcx>> for Interned<'tcx, TyS<'tcx>> {
1909
1910
}
1910
1911
}
1911
1912
1913
+ impl < ' tcx > PartialEq for Interned < ' tcx , Const < ' tcx > > {
1914
+ fn eq ( & self , other : & Interned < ' tcx , Const < ' tcx > > ) -> bool {
1915
+ self . 0 . ty == other. 0 . ty && self . 0 . val == other. 0 . val
1916
+ }
1917
+ }
1918
+
1919
+ impl < ' tcx > Eq for Interned < ' tcx , Const < ' tcx > > { }
1920
+
1921
+ impl < ' tcx > Hash for Interned < ' tcx , Const < ' tcx > > {
1922
+ fn hash < H : Hasher > ( & self , s : & mut H ) {
1923
+ self . 0 . ty . hash ( s) ;
1924
+ self . 0 . val . hash ( s) ;
1925
+ }
1926
+ }
1927
+
1912
1928
// N.B., an `Interned<List<T>>` compares and hashes as its elements.
1913
1929
impl < ' tcx , T : PartialEq > PartialEq for Interned < ' tcx , List < T > > {
1914
1930
fn eq ( & self , other : & Interned < ' tcx , List < T > > ) -> bool {
@@ -2022,7 +2038,6 @@ macro_rules! direct_interners {
2022
2038
2023
2039
direct_interners ! (
2024
2040
region: mk_region( RegionKind ) ,
2025
- const_: mk_const( Const <' tcx>) ,
2026
2041
predicate_kind: intern_predicate_kind( PredicateKind <' tcx>) ,
2027
2042
) ;
2028
2043
@@ -2086,6 +2101,13 @@ impl<'tcx> TyCtxt<'tcx> {
2086
2101
self . interners . intern_ty ( st)
2087
2102
}
2088
2103
2104
+ #[ inline]
2105
+ pub fn mk_const ( & self , ty : Ty < ' tcx > , val : ConstKind < ' tcx > ) -> & ' tcx Const < ' tcx > {
2106
+ let ct = Const { ty, val, _priv : super :: sty:: PrivateMarker ( ( ) ) } ;
2107
+
2108
+ self . interners . const_ . intern ( ct, |ct| Interned ( self . arena . alloc ( ct) ) ) . 0
2109
+ }
2110
+
2089
2111
#[ inline]
2090
2112
pub fn mk_predicate ( & self , kind : PredicateKind < ' tcx > ) -> Predicate < ' tcx > {
2091
2113
let kind = self . intern_predicate_kind ( kind) ;
@@ -2307,7 +2329,7 @@ impl<'tcx> TyCtxt<'tcx> {
2307
2329
2308
2330
#[ inline]
2309
2331
pub fn mk_const_var ( self , v : ConstVid < ' tcx > , ty : Ty < ' tcx > ) -> & ' tcx Const < ' tcx > {
2310
- self . mk_const ( ty:: Const { val : ty:: ConstKind :: Infer ( InferConst :: Var ( v) ) , ty } )
2332
+ self . mk_const ( ty, ty:: ConstKind :: Infer ( InferConst :: Var ( v) ) )
2311
2333
}
2312
2334
2313
2335
#[ inline]
@@ -2327,7 +2349,7 @@ impl<'tcx> TyCtxt<'tcx> {
2327
2349
2328
2350
#[ inline]
2329
2351
pub fn mk_const_infer ( self , ic : InferConst < ' tcx > , ty : Ty < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > {
2330
- self . mk_const ( ty:: Const { val : ty:: ConstKind :: Infer ( ic) , ty } )
2352
+ self . mk_const ( ty, ty:: ConstKind :: Infer ( ic) )
2331
2353
}
2332
2354
2333
2355
#[ inline]
@@ -2337,7 +2359,7 @@ impl<'tcx> TyCtxt<'tcx> {
2337
2359
2338
2360
#[ inline]
2339
2361
pub fn mk_const_param ( self , index : u32 , name : Symbol , ty : Ty < ' tcx > ) -> & ' tcx Const < ' tcx > {
2340
- self . mk_const ( ty:: Const { val : ty:: ConstKind :: Param ( ParamConst { index, name } ) , ty } )
2362
+ self . mk_const ( ty, ty:: ConstKind :: Param ( ParamConst { index, name } ) )
2341
2363
}
2342
2364
2343
2365
pub fn mk_param_from_def ( self , param : & ty:: GenericParamDef ) -> GenericArg < ' tcx > {
0 commit comments