1
1
use rustc:: hir:: def_id:: DefId ;
2
2
use rustc:: mir;
3
- use rustc:: ty:: layout:: Layout ;
3
+ use rustc:: ty:: layout:: { Layout , Size , Align } ;
4
4
use rustc:: ty:: subst:: Substs ;
5
5
use rustc:: ty:: { self , Ty } ;
6
6
@@ -426,17 +426,14 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
426
426
427
427
let ( sized_size, sized_align) = match * layout {
428
428
ty:: layout:: Layout :: Univariant { ref variant, .. } => {
429
- // The offset of the start of the last field gives the size of the
430
- // sized part of the type.
431
- let size = variant. offsets . last ( ) . map_or ( 0 , |f| f. bytes ( ) ) ;
432
- ( size, variant. align . abi ( ) )
429
+ ( variant. offsets . last ( ) . map_or ( 0 , |o| o. bytes ( ) ) , variant. align )
433
430
}
434
431
_ => {
435
432
bug ! ( "size_and_align_of_dst: expcted Univariant for `{}`, found {:#?}" ,
436
433
ty, layout) ;
437
434
}
438
435
} ;
439
- debug ! ( "DST {} statically sized prefix size: {} align: {}" ,
436
+ debug ! ( "DST {} statically sized prefix size: {} align: {:? }" ,
440
437
ty, sized_size, sized_align) ;
441
438
442
439
// Recurse to get the size of the dynamically sized field (must be
@@ -457,7 +454,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
457
454
458
455
// Choose max of two known alignments (combined value must
459
456
// be aligned according to more restrictive of the two).
460
- let align = :: std :: cmp :: max ( sized_align , unsized_align) ;
457
+ let align = sized_align . max ( Align :: from_bytes ( unsized_align , unsized_align) . unwrap ( ) ) ;
461
458
462
459
// Issue #27023: must add any necessary padding to `size`
463
460
// (to make it a multiple of `align`) before returning it.
@@ -470,11 +467,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
470
467
//
471
468
// `(size + (align-1)) & -align`
472
469
473
- if size & ( align - 1 ) != 0 {
474
- Ok ( ( size + align, align) )
475
- } else {
476
- Ok ( ( size, align) )
477
- }
470
+ let size = Size :: from_bytes ( size) . abi_align ( align) . bytes ( ) ;
471
+ Ok ( ( size, align. abi ( ) ) )
478
472
}
479
473
ty:: TyDynamic ( ..) => {
480
474
let ( _, vtable) = value. expect_ptr_vtable_pair ( & self . memory ) ?;
0 commit comments