@@ -36,13 +36,17 @@ fn branches<'tcx>(
3636 // For enums, we prepend their variant index before the variant's fields so we can figure out
3737 // the variant again when just seeing a valtree.
3838 if let Some ( variant) = variant {
39- branches. push ( ty:: ValTree :: from_scalar_int ( * ecx. tcx , variant. as_u32 ( ) . into ( ) ) ) ;
39+ branches. push ( ty:: Const :: new_value (
40+ * ecx. tcx ,
41+ ty:: ValTree :: from_scalar_int ( * ecx. tcx , variant. as_u32 ( ) . into ( ) ) ,
42+ ecx. tcx . types . u32 ,
43+ ) ) ;
4044 }
4145
4246 for i in 0 ..field_count {
4347 let field = ecx. project_field ( & place, FieldIdx :: from_usize ( i) ) . unwrap ( ) ;
4448 let valtree = const_to_valtree_inner ( ecx, & field, num_nodes) ?;
45- branches. push ( valtree) ;
49+ branches. push ( ty :: Const :: new_value ( * ecx . tcx , valtree, field . layout . ty ) ) ;
4650 }
4751
4852 // Have to account for ZSTs here
@@ -65,7 +69,7 @@ fn slice_branches<'tcx>(
6569 for i in 0 ..n {
6670 let place_elem = ecx. project_index ( place, i) . unwrap ( ) ;
6771 let valtree = const_to_valtree_inner ( ecx, & place_elem, num_nodes) ?;
68- elems. push ( valtree) ;
72+ elems. push ( ty :: Const :: new_value ( * ecx . tcx , valtree, place_elem . layout . ty ) ) ;
6973 }
7074
7175 Ok ( ty:: ValTree :: from_branches ( * ecx. tcx , elems) )
@@ -200,8 +204,8 @@ fn reconstruct_place_meta<'tcx>(
200204 & ObligationCause :: dummy ( ) ,
201205 |ty| ty,
202206 || {
203- let branches = last_valtree. unwrap_branch ( ) ;
204- last_valtree = * branches. last ( ) . unwrap ( ) ;
207+ let branches = last_valtree. to_branch ( ) ;
208+ last_valtree = branches. last ( ) . unwrap ( ) . to_value ( ) . valtree ;
205209 debug ! ( ?branches, ?last_valtree) ;
206210 } ,
207211 ) ;
@@ -212,7 +216,7 @@ fn reconstruct_place_meta<'tcx>(
212216 } ;
213217
214218 // Get the number of elements in the unsized field.
215- let num_elems = last_valtree. unwrap_branch ( ) . len ( ) ;
219+ let num_elems = last_valtree. to_branch ( ) . len ( ) ;
216220 MemPlaceMeta :: Meta ( Scalar :: from_target_usize ( num_elems as u64 , & tcx) )
217221}
218222
@@ -274,7 +278,7 @@ pub fn valtree_to_const_value<'tcx>(
274278 mir:: ConstValue :: ZeroSized
275279 }
276280 ty:: Bool | ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) | ty:: Char | ty:: RawPtr ( _, _) => {
277- mir:: ConstValue :: Scalar ( Scalar :: Int ( cv. valtree . unwrap_leaf ( ) ) )
281+ mir:: ConstValue :: Scalar ( Scalar :: Int ( cv. to_leaf ( ) ) )
278282 }
279283 ty:: Pat ( ty, _) => {
280284 let cv = ty:: Value { valtree : cv. valtree , ty } ;
@@ -301,12 +305,13 @@ pub fn valtree_to_const_value<'tcx>(
301305 || matches ! ( cv. ty. kind( ) , ty:: Adt ( def, _) if def. is_struct( ) ) )
302306 {
303307 // A Scalar tuple/struct; we can avoid creating an allocation.
304- let branches = cv. valtree . unwrap_branch ( ) ;
308+ let branches = cv. to_branch ( ) ;
305309 // Find the non-ZST field. (There can be aligned ZST!)
306310 for ( i, & inner_valtree) in branches. iter ( ) . enumerate ( ) {
307311 let field = layout. field ( & LayoutCx :: new ( tcx, typing_env) , i) ;
308312 if !field. is_zst ( ) {
309- let cv = ty:: Value { valtree : inner_valtree, ty : field. ty } ;
313+ let cv =
314+ ty:: Value { valtree : inner_valtree. to_value ( ) . valtree , ty : field. ty } ;
310315 return valtree_to_const_value ( tcx, typing_env, cv) ;
311316 }
312317 }
@@ -381,7 +386,7 @@ fn valtree_into_mplace<'tcx>(
381386 // Zero-sized type, nothing to do.
382387 }
383388 ty:: Bool | ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) | ty:: Char | ty:: RawPtr ( ..) => {
384- let scalar_int = valtree. unwrap_leaf ( ) ;
389+ let scalar_int = valtree. to_leaf ( ) ;
385390 debug ! ( "writing trivial valtree {:?} to place {:?}" , scalar_int, place) ;
386391 ecx. write_immediate ( Immediate :: Scalar ( scalar_int. into ( ) ) , place) . unwrap ( ) ;
387392 }
@@ -391,13 +396,13 @@ fn valtree_into_mplace<'tcx>(
391396 ecx. write_immediate ( imm, place) . unwrap ( ) ;
392397 }
393398 ty:: Adt ( _, _) | ty:: Tuple ( _) | ty:: Array ( _, _) | ty:: Str | ty:: Slice ( _) => {
394- let branches = valtree. unwrap_branch ( ) ;
399+ let branches = valtree. to_branch ( ) ;
395400
396401 // Need to downcast place for enums
397402 let ( place_adjusted, branches, variant_idx) = match ty. kind ( ) {
398403 ty:: Adt ( def, _) if def. is_enum ( ) => {
399404 // First element of valtree corresponds to variant
400- let scalar_int = branches[ 0 ] . unwrap_leaf ( ) ;
405+ let scalar_int = branches[ 0 ] . to_leaf ( ) ;
401406 let variant_idx = VariantIdx :: from_u32 ( scalar_int. to_u32 ( ) ) ;
402407 let variant = def. variant ( variant_idx) ;
403408 debug ! ( ?variant) ;
@@ -425,7 +430,7 @@ fn valtree_into_mplace<'tcx>(
425430 } ;
426431
427432 debug ! ( ?place_inner) ;
428- valtree_into_mplace ( ecx, & place_inner, * inner_valtree) ;
433+ valtree_into_mplace ( ecx, & place_inner, inner_valtree. to_value ( ) . valtree ) ;
429434 dump_place ( ecx, & place_inner) ;
430435 }
431436
0 commit comments