@@ -5,7 +5,6 @@ use crate::interpret::{
5
5
Scalar , ScalarMaybeUninit ,
6
6
} ;
7
7
use rustc_middle:: mir:: interpret:: ConstAlloc ;
8
- use rustc_middle:: mir:: { Field , ProjectionElem } ;
9
8
use rustc_middle:: ty:: { self , ScalarInt , Ty , TyCtxt } ;
10
9
use rustc_span:: source_map:: DUMMY_SP ;
11
10
use rustc_target:: abi:: VariantIdx ;
@@ -197,45 +196,45 @@ pub fn valtree_to_const_value<'tcx>(
197
196
let mut ecx = mk_eval_cx ( tcx, DUMMY_SP , param_env, false ) ;
198
197
199
198
match ty. kind ( ) {
199
+ ty:: FnDef ( ..) => {
200
+ assert ! ( valtree. unwrap_branch( ) . is_empty( ) ) ;
201
+ ConstValue :: Scalar ( Scalar :: ZST )
202
+ }
200
203
ty:: Bool | ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) | ty:: Char => match valtree {
201
204
ty:: ValTree :: Leaf ( scalar_int) => ConstValue :: Scalar ( Scalar :: Int ( scalar_int) ) ,
202
205
ty:: ValTree :: Branch ( _) => bug ! (
203
206
"ValTrees for Bool, Int, Uint, Float or Char should have the form ValTree::Leaf"
204
207
) ,
205
208
} ,
206
- ty:: Ref ( _, inner_ty, _) => {
207
- // create a place for the pointee
208
- let mut pointee_place = create_pointee_place ( & mut ecx, * inner_ty, valtree) ;
209
- debug ! ( ?pointee_place) ;
210
-
211
- // insert elements of valtree into `place`
212
- fill_place_recursively ( & mut ecx, & mut pointee_place, valtree) ;
213
- dump_place ( & ecx, pointee_place. into ( ) ) ;
214
- intern_const_alloc_recursive ( & mut ecx, InternKind :: Constant , & pointee_place) . unwrap ( ) ;
215
-
216
- let ref_place = pointee_place. to_ref ( & tcx) ;
217
- let imm = ImmTy :: from_immediate ( ref_place, tcx. layout_of ( param_env_ty) . unwrap ( ) ) ;
218
-
219
- let const_val = op_to_const ( & ecx, & imm. into ( ) ) ;
220
- debug ! ( ?const_val) ;
221
-
222
- const_val
223
- }
224
- ty:: Tuple ( _) | ty:: Array ( _, _) | ty:: Adt ( ..) => {
225
- let mut place = create_mplace_from_layout ( & mut ecx, ty) ;
209
+ ty:: Ref ( _, _, _) | ty:: Tuple ( _) | ty:: Array ( _, _) | ty:: Adt ( ..) => {
210
+ let mut place = match ty. kind ( ) {
211
+ ty:: Ref ( _, inner_ty, _) => {
212
+ // Need to create a place for the pointee to fill for Refs
213
+ create_pointee_place ( & mut ecx, * inner_ty, valtree)
214
+ }
215
+ _ => create_mplace_from_layout ( & mut ecx, ty) ,
216
+ } ;
226
217
debug ! ( ?place) ;
227
218
228
219
fill_place_recursively ( & mut ecx, & mut place, valtree) ;
229
220
dump_place ( & ecx, place. into ( ) ) ;
230
221
intern_const_alloc_recursive ( & mut ecx, InternKind :: Constant , & place) . unwrap ( ) ;
231
222
232
- let const_val = op_to_const ( & ecx, & place. into ( ) ) ;
223
+ let const_val = match ty. kind ( ) {
224
+ ty:: Ref ( _, _, _) => {
225
+ let ref_place = place. to_ref ( & tcx) ;
226
+ let imm =
227
+ ImmTy :: from_immediate ( ref_place, tcx. layout_of ( param_env_ty) . unwrap ( ) ) ;
228
+
229
+ op_to_const ( & ecx, & imm. into ( ) )
230
+ }
231
+ _ => op_to_const ( & ecx, & place. into ( ) ) ,
232
+ } ;
233
233
debug ! ( ?const_val) ;
234
234
235
235
const_val
236
236
}
237
237
ty:: Never
238
- | ty:: FnDef ( ..)
239
238
| ty:: Error ( _)
240
239
| ty:: Foreign ( ..)
241
240
| ty:: Infer ( ty:: FreshIntTy ( _) )
@@ -331,13 +330,6 @@ fn fill_place_recursively<'tcx>(
331
330
debug ! ( ?i, ?inner_valtree) ;
332
331
333
332
let mut place_inner = match * ty. kind ( ) {
334
- ty:: Adt ( def, substs) if !def. is_enum ( ) => {
335
- let field = & def. variant ( VariantIdx :: from_usize ( 0 ) ) . fields [ i] ;
336
- let field_ty = field. ty ( tcx, substs) ;
337
- let projection_elem = ProjectionElem :: Field ( Field :: from_usize ( i) , field_ty) ;
338
-
339
- ecx. mplace_projection ( & place_adjusted, projection_elem) . unwrap ( )
340
- }
341
333
ty:: Adt ( _, _) | ty:: Tuple ( _) => ecx. mplace_field ( & place_adjusted, i) . unwrap ( ) ,
342
334
ty:: Array ( _, _) | ty:: Str => {
343
335
ecx. mplace_index ( & place_adjusted, i as u64 ) . unwrap ( )
0 commit comments