@@ -76,10 +76,10 @@ impl<'tcx> Const<'tcx> {
76
76
match Self :: try_eval_lit_or_param ( tcx, ty, expr) {
77
77
Some ( v) => v,
78
78
None => tcx. mk_const (
79
- ty:: ConstKind :: Unevaluated ( ty :: UnevaluatedConst {
79
+ ty:: UnevaluatedConst {
80
80
def : def. to_global ( ) ,
81
81
substs : InternalSubsts :: identity_for_item ( tcx, def. did . to_def_id ( ) ) ,
82
- } ) ,
82
+ } ,
83
83
ty,
84
84
) ,
85
85
}
@@ -134,18 +134,12 @@ impl<'tcx> Const<'tcx> {
134
134
let generics = tcx. generics_of ( item_def_id) ;
135
135
let index = generics. param_def_id_to_index [ & def_id] ;
136
136
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) )
138
138
}
139
139
_ => None ,
140
140
}
141
141
}
142
142
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
-
149
143
/// Panics if self.kind != ty::ConstKind::Value
150
144
pub fn to_valtree ( self ) -> ty:: ValTree < ' tcx > {
151
145
match self . kind ( ) {
@@ -154,26 +148,23 @@ impl<'tcx> Const<'tcx> {
154
148
}
155
149
}
156
150
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
-
162
151
#[ inline]
163
152
/// Creates a constant with the given integer value and interns it.
164
153
pub fn from_bits ( tcx : TyCtxt < ' tcx > , bits : u128 , ty : ParamEnvAnd < ' tcx , Ty < ' tcx > > ) -> Self {
165
154
let size = tcx
166
155
. layout_of ( ty)
167
156
. unwrap_or_else ( |e| panic ! ( "could not compute layout for {:?}: {:?}" , ty, e) )
168
157
. 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
+ )
170
162
}
171
163
172
164
#[ inline]
173
165
/// Creates an interned zst constant.
174
166
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)
177
168
}
178
169
179
170
#[ inline]
@@ -220,7 +211,7 @@ impl<'tcx> Const<'tcx> {
220
211
pub fn eval ( self , tcx : TyCtxt < ' tcx > , param_env : ParamEnv < ' tcx > ) -> Const < ' tcx > {
221
212
if let Some ( val) = self . kind ( ) . try_eval_for_typeck ( tcx, param_env) {
222
213
match val {
223
- Ok ( val) => Const :: from_value ( tcx, val, self . ty ( ) ) ,
214
+ Ok ( val) => tcx. mk_const ( val, self . ty ( ) ) ,
224
215
Err ( guar) => tcx. const_error_with_guaranteed ( self . ty ( ) , guar) ,
225
216
}
226
217
} else {
0 commit comments