@@ -76,10 +76,10 @@ impl<'tcx> Const<'tcx> {
7676 match Self :: try_eval_lit_or_param ( tcx, ty, expr) {
7777 Some ( v) => v,
7878 None => tcx. mk_const (
79- ty:: ConstKind :: Unevaluated ( ty :: UnevaluatedConst {
79+ ty:: UnevaluatedConst {
8080 def : def. to_global ( ) ,
8181 substs : InternalSubsts :: identity_for_item ( tcx, def. did . to_def_id ( ) ) ,
82- } ) ,
82+ } ,
8383 ty,
8484 ) ,
8585 }
@@ -134,18 +134,12 @@ impl<'tcx> Const<'tcx> {
134134 let generics = tcx. generics_of ( item_def_id) ;
135135 let index = generics. param_def_id_to_index [ & def_id] ;
136136 let name = tcx. item_name ( def_id) ;
137- Some ( tcx. mk_const ( ty:: ConstKind :: Param ( ty :: ParamConst :: new ( index, name) ) , ty) )
137+ Some ( tcx. mk_const ( ty:: ParamConst :: new ( index, name) , ty) )
138138 }
139139 _ => None ,
140140 }
141141 }
142142
143- /// Interns the given value as a constant.
144- #[ inline]
145- pub fn from_value ( tcx : TyCtxt < ' tcx > , val : ty:: ValTree < ' tcx > , ty : Ty < ' tcx > ) -> Self {
146- tcx. mk_const ( ConstKind :: Value ( val) , ty)
147- }
148-
149143 /// Panics if self.kind != ty::ConstKind::Value
150144 pub fn to_valtree ( self ) -> ty:: ValTree < ' tcx > {
151145 match self . kind ( ) {
@@ -154,26 +148,23 @@ impl<'tcx> Const<'tcx> {
154148 }
155149 }
156150
157- pub fn from_scalar_int ( tcx : TyCtxt < ' tcx > , i : ScalarInt , ty : Ty < ' tcx > ) -> Self {
158- let valtree = ty:: ValTree :: from_scalar_int ( i) ;
159- Self :: from_value ( tcx, valtree, ty)
160- }
161-
162151 #[ inline]
163152 /// Creates a constant with the given integer value and interns it.
164153 pub fn from_bits ( tcx : TyCtxt < ' tcx > , bits : u128 , ty : ParamEnvAnd < ' tcx , Ty < ' tcx > > ) -> Self {
165154 let size = tcx
166155 . layout_of ( ty)
167156 . unwrap_or_else ( |e| panic ! ( "could not compute layout for {:?}: {:?}" , ty, e) )
168157 . size ;
169- Self :: from_scalar_int ( tcx, ScalarInt :: try_from_uint ( bits, size) . unwrap ( ) , ty. value )
158+ tcx. mk_const (
159+ ty:: ValTree :: from_scalar_int ( ScalarInt :: try_from_uint ( bits, size) . unwrap ( ) ) ,
160+ ty. value ,
161+ )
170162 }
171163
172164 #[ inline]
173165 /// Creates an interned zst constant.
174166 pub fn zero_sized ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> Self {
175- let valtree = ty:: ValTree :: zst ( ) ;
176- Self :: from_value ( tcx, valtree, ty)
167+ tcx. mk_const ( ty:: ValTree :: zst ( ) , ty)
177168 }
178169
179170 #[ inline]
@@ -220,7 +211,7 @@ impl<'tcx> Const<'tcx> {
220211 pub fn eval ( self , tcx : TyCtxt < ' tcx > , param_env : ParamEnv < ' tcx > ) -> Const < ' tcx > {
221212 if let Some ( val) = self . kind ( ) . try_eval_for_typeck ( tcx, param_env) {
222213 match val {
223- Ok ( val) => Const :: from_value ( tcx, val, self . ty ( ) ) ,
214+ Ok ( val) => tcx. mk_const ( val, self . ty ( ) ) ,
224215 Err ( guar) => tcx. const_error_with_guaranteed ( self . ty ( ) , guar) ,
225216 }
226217 } else {
0 commit comments