@@ -422,22 +422,23 @@ pub fn const_val_field<'a, 'tcx>(
422422 let mut ecx = mk_eval_cx ( tcx, instance, param_env) . unwrap ( ) ;
423423 let result = ( || {
424424 let value = ecx. const_value_to_value ( value, ty) ?;
425- let ( field, ty) = match value {
426- Value :: ByValPair ( ..) | Value :: ByVal ( _) =>
427- ecx. read_field ( value, variant, field, ty) ?. expect ( "const_val_field on non-field" ) ,
428- Value :: ByRef ( ptr, align) => {
429- let place = Place :: Ptr {
430- ptr,
431- align,
432- extra : variant. map_or ( PlaceExtra :: None , PlaceExtra :: DowncastVariant ) ,
433- } ;
434- let layout = ecx. layout_of ( ty) ?;
435- let ( place, layout) = ecx. place_field ( place, field, layout) ?;
436- let ( ptr, align) = place. to_ptr_align ( ) ;
437- ( Value :: ByRef ( ptr, align) , layout. ty )
438- }
425+ let layout = ecx. layout_of ( ty) ?;
426+ let ( ptr, align) = match value {
427+ Value :: ByRef ( ptr, align) => ( ptr, align) ,
428+ Value :: ByValPair ( ..) | Value :: ByVal ( _) => {
429+ let ptr = ecx. alloc_ptr ( ty) ?. into ( ) ;
430+ ecx. write_value_to_ptr ( value, ptr, ty) ?;
431+ ( ptr, layout. align )
432+ } ,
439433 } ;
440- Ok ( value_to_const_value ( & ecx, field, ty) )
434+ let place = Place :: Ptr {
435+ ptr,
436+ align,
437+ extra : variant. map_or ( PlaceExtra :: None , PlaceExtra :: DowncastVariant ) ,
438+ } ;
439+ let ( place, layout) = ecx. place_field ( place, field, layout) ?;
440+ let ( ptr, align) = place. to_ptr_align ( ) ;
441+ Ok ( ( Value :: ByRef ( ptr, align) , layout. ty ) )
441442 } ) ( ) ;
442443 result. map_err ( |err| {
443444 let ( trace, span) = ecx. generate_stacktrace ( None ) ;
@@ -478,7 +479,10 @@ pub fn const_value_to_allocation_provider<'a, 'tcx>(
478479 ( val, ty) : ( ConstValue < ' tcx > , Ty < ' tcx > ) ,
479480) -> & ' tcx Allocation {
480481 match val {
481- ConstValue :: ByRef ( alloc) => return alloc,
482+ ConstValue :: ByRef ( alloc, offset) => {
483+ assert_eq ! ( offset, 0 ) ;
484+ return alloc;
485+ } ,
482486 _ => ( )
483487 }
484488 let result = || -> EvalResult < ' tcx , & ' tcx Allocation > {
0 commit comments