@@ -390,78 +390,60 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
390
390
391
391
// Unpack newtype ABIs and find scalar pairs.
392
392
if sized && size. bytes ( ) > 0 {
393
- // All other fields must be ZSTs, and we need them to all start at 0.
394
- let mut zst_offsets = offsets. iter ( ) . enumerate ( ) . filter ( |& ( i, _) | fields[ i] . is_zst ( ) ) ;
395
- if zst_offsets. all ( |( _, o) | o. bytes ( ) == 0 ) {
396
- let mut non_zst_fields = fields. iter ( ) . enumerate ( ) . filter ( |& ( _, f) | !f. is_zst ( ) ) ;
397
-
398
- match ( non_zst_fields. next ( ) , non_zst_fields. next ( ) , non_zst_fields. next ( ) ) {
399
- // We have exactly one non-ZST field.
400
- ( Some ( ( i, field) ) , None , None ) => {
401
- // Field fills the struct and it has a scalar or scalar pair ABI.
402
- if offsets[ i] . bytes ( ) == 0
403
- && align. abi == field. align . abi
404
- && size == field. size
405
- {
406
- match field. abi {
407
- // For plain scalars, or vectors of them, we can't unpack
408
- // newtypes for `#[repr(C)]`, as that affects C ABIs.
409
- Abi :: Scalar ( _) | Abi :: Vector { .. } if optimize => {
410
- abi = field. abi . clone ( ) ;
411
- }
412
- // But scalar pairs are Rust-specific and get
413
- // treated as aggregates by C ABIs anyway.
414
- Abi :: ScalarPair ( ..) => {
415
- abi = field. abi . clone ( ) ;
416
- }
417
- _ => { }
393
+ // All other fields must be ZSTs.
394
+ let mut non_zst_fields = fields. iter ( ) . enumerate ( ) . filter ( |& ( _, f) | !f. is_zst ( ) ) ;
395
+
396
+ match ( non_zst_fields. next ( ) , non_zst_fields. next ( ) , non_zst_fields. next ( ) ) {
397
+ // We have exactly one non-ZST field.
398
+ ( Some ( ( i, field) ) , None , None ) => {
399
+ // Field fills the struct and it has a scalar or scalar pair ABI.
400
+ if offsets[ i] . bytes ( ) == 0 && align. abi == field. align . abi && size == field. size
401
+ {
402
+ match field. abi {
403
+ // For plain scalars, or vectors of them, we can't unpack
404
+ // newtypes for `#[repr(C)]`, as that affects C ABIs.
405
+ Abi :: Scalar ( _) | Abi :: Vector { .. } if optimize => {
406
+ abi = field. abi . clone ( ) ;
418
407
}
408
+ // But scalar pairs are Rust-specific and get
409
+ // treated as aggregates by C ABIs anyway.
410
+ Abi :: ScalarPair ( ..) => {
411
+ abi = field. abi . clone ( ) ;
412
+ }
413
+ _ => { }
419
414
}
420
415
}
416
+ }
421
417
422
- // Two non-ZST fields, and they're both scalars.
423
- (
424
- Some ( (
425
- i,
426
- & TyAndLayout {
427
- layout : & Layout { abi : Abi :: Scalar ( ref a) , .. } , ..
428
- } ,
429
- ) ) ,
430
- Some ( (
431
- j,
432
- & TyAndLayout {
433
- layout : & Layout { abi : Abi :: Scalar ( ref b) , .. } , ..
434
- } ,
435
- ) ) ,
436
- None ,
437
- ) => {
438
- // Order by the memory placement, not source order.
439
- let ( ( i, a) , ( j, b) ) = if offsets[ i] < offsets[ j] {
440
- ( ( i, a) , ( j, b) )
441
- } else {
442
- ( ( j, b) , ( i, a) )
443
- } ;
444
- let pair = self . scalar_pair ( a. clone ( ) , b. clone ( ) ) ;
445
- let pair_offsets = match pair. fields {
446
- FieldsShape :: Arbitrary { ref offsets, ref memory_index } => {
447
- assert_eq ! ( memory_index, & [ 0 , 1 ] ) ;
448
- offsets
449
- }
450
- _ => bug ! ( ) ,
451
- } ;
452
- if offsets[ i] == pair_offsets[ 0 ]
453
- && offsets[ j] == pair_offsets[ 1 ]
454
- && align == pair. align
455
- && size == pair. size
456
- {
457
- // We can use `ScalarPair` only when it matches our
458
- // already computed layout (including `#[repr(C)]`).
459
- abi = pair. abi ;
418
+ // Two non-ZST fields, and they're both scalars.
419
+ (
420
+ Some ( ( i, & TyAndLayout { layout : & Layout { abi : Abi :: Scalar ( ref a) , .. } , .. } ) ) ,
421
+ Some ( ( j, & TyAndLayout { layout : & Layout { abi : Abi :: Scalar ( ref b) , .. } , .. } ) ) ,
422
+ None ,
423
+ ) => {
424
+ // Order by the memory placement, not source order.
425
+ let ( ( i, a) , ( j, b) ) =
426
+ if offsets[ i] < offsets[ j] { ( ( i, a) , ( j, b) ) } else { ( ( j, b) , ( i, a) ) } ;
427
+ let pair = self . scalar_pair ( a. clone ( ) , b. clone ( ) ) ;
428
+ let pair_offsets = match pair. fields {
429
+ FieldsShape :: Arbitrary { ref offsets, ref memory_index } => {
430
+ assert_eq ! ( memory_index, & [ 0 , 1 ] ) ;
431
+ offsets
460
432
}
433
+ _ => bug ! ( ) ,
434
+ } ;
435
+ if offsets[ i] == pair_offsets[ 0 ]
436
+ && offsets[ j] == pair_offsets[ 1 ]
437
+ && align == pair. align
438
+ && size == pair. size
439
+ {
440
+ // We can use `ScalarPair` only when it matches our
441
+ // already computed layout (including `#[repr(C)]`).
442
+ abi = pair. abi ;
461
443
}
462
-
463
- _ => { }
464
444
}
445
+
446
+ _ => { }
465
447
}
466
448
}
467
449
0 commit comments