@@ -28,9 +28,9 @@ use crate::ty::TyKind::*;
2828use crate :: ty:: { self , DefIdTree , Ty , TypeAndMut } ;
2929use crate :: ty:: { AdtDef , AdtKind , Const , Region } ;
3030use crate :: ty:: { BindingMode , BoundVar } ;
31+ use crate :: ty:: { ConstKind , InferConst , ParamConst } ;
3132use crate :: ty:: { ConstVid , FloatVar , FloatVid , IntVar , IntVid , TyVar , TyVid } ;
3233use crate :: ty:: { ExistentialPredicate , Predicate , PredicateKind } ;
33- use crate :: ty:: { InferConst , ParamConst } ;
3434use crate :: ty:: { InferTy , ParamTy , PolyFnSig , ProjectionTy } ;
3535use crate :: ty:: { List , TyKind , TyS } ;
3636use rustc_ast:: ast;
@@ -856,9 +856,10 @@ impl<'tcx> CommonConsts<'tcx> {
856856 let mk_const = |c| interners. const_ . intern ( c, |c| Interned ( interners. arena . alloc ( c) ) ) . 0 ;
857857
858858 CommonConsts {
859- unit : mk_const ( ty:: Const {
860- val : ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: zst ( ) ) ) ,
859+ unit : mk_const ( Const {
861860 ty : types. unit ,
861+ val : ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: zst ( ) ) ) ,
862+ _priv : ty:: sty:: PrivateMarker ( ( ) ) ,
862863 } ) ,
863864 }
864865 }
@@ -1909,6 +1910,21 @@ impl<'tcx> Borrow<TyKind<'tcx>> for Interned<'tcx, TyS<'tcx>> {
19091910 }
19101911}
19111912
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+
19121928// N.B., an `Interned<List<T>>` compares and hashes as its elements.
19131929impl < ' tcx , T : PartialEq > PartialEq for Interned < ' tcx , List < T > > {
19141930 fn eq ( & self , other : & Interned < ' tcx , List < T > > ) -> bool {
@@ -2022,7 +2038,6 @@ macro_rules! direct_interners {
20222038
20232039direct_interners ! (
20242040 region: mk_region( RegionKind ) ,
2025- const_: mk_const( Const <' tcx>) ,
20262041 predicate_kind: intern_predicate_kind( PredicateKind <' tcx>) ,
20272042) ;
20282043
@@ -2086,6 +2101,13 @@ impl<'tcx> TyCtxt<'tcx> {
20862101 self . interners . intern_ty ( st)
20872102 }
20882103
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+
20892111 #[ inline]
20902112 pub fn mk_predicate ( & self , kind : PredicateKind < ' tcx > ) -> Predicate < ' tcx > {
20912113 let kind = self . intern_predicate_kind ( kind) ;
@@ -2307,7 +2329,7 @@ impl<'tcx> TyCtxt<'tcx> {
23072329
23082330 #[ inline]
23092331 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) ) )
23112333 }
23122334
23132335 #[ inline]
@@ -2327,7 +2349,7 @@ impl<'tcx> TyCtxt<'tcx> {
23272349
23282350 #[ inline]
23292351 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) )
23312353 }
23322354
23332355 #[ inline]
@@ -2337,7 +2359,7 @@ impl<'tcx> TyCtxt<'tcx> {
23372359
23382360 #[ inline]
23392361 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 } ) )
23412363 }
23422364
23432365 pub fn mk_param_from_def ( self , param : & ty:: GenericParamDef ) -> GenericArg < ' tcx > {
0 commit comments