@@ -968,8 +968,8 @@ fn univariant<
968968let mut align = if pack. is_some ( ) { dl. i8_align } else { dl. aggregate_align } ;
969969let mut max_repr_align = repr. align ;
970970let mut inverse_memory_index: IndexVec < u32 , FieldIdx > = fields. indices ( ) . collect ( ) ;
971- let optimize = !repr. inhibit_struct_field_reordering ( ) ;
972- if optimize && fields. len ( ) > 1 {
971+ let optimize_field_order = !repr. inhibit_struct_field_reordering ( ) ;
972+ if optimize_field_order && fields. len ( ) > 1 {
973973let end = if let StructKind :: MaybeUnsized = kind { fields. len ( ) - 1 } else { fields. len ( ) } ;
974974let optimizing = & mut inverse_memory_index. raw [ ..end] ;
975975let fields_excluding_tail = & fields. raw [ ..end] ;
@@ -1176,7 +1176,7 @@ fn univariant<
11761176// If field 5 has offset 0, offsets[0] is 5, and memory_index[5] should be 0.
11771177// Field 5 would be the first element, so memory_index is i:
11781178// Note: if we didn't optimize, it's already right.
1179- let memory_index = if optimize {
1179+ let memory_index = if optimize_field_order {
11801180 inverse_memory_index. invert_bijective_mapping ( )
11811181} else {
11821182debug_assert ! ( inverse_memory_index. iter( ) . copied( ) . eq( fields. indices( ) ) ) ;
@@ -1189,6 +1189,9 @@ fn univariant<
11891189}
11901190let mut layout_of_single_non_zst_field = None ;
11911191let mut abi = Abi :: Aggregate { sized } ;
1192+
1193+ let optimize_abi = !repr. inhibit_newtype_abi_optimization ( ) ;
1194+
11921195// Try to make this a Scalar/ScalarPair.
11931196if sized && size. bytes ( ) > 0 {
11941197// We skip *all* ZST here and later check if we are good in terms of alignment.
@@ -1205,7 +1208,7 @@ fn univariant<
12051208match field. abi {
12061209// For plain scalars, or vectors of them, we can't unpack
12071210// newtypes for `#[repr(C)]`, as that affects C ABIs.
1208- Abi :: Scalar ( _) | Abi :: Vector { .. } if optimize => {
1211+ Abi :: Scalar ( _) | Abi :: Vector { .. } if optimize_abi => {
12091212 abi = field. abi ;
12101213}
12111214// But scalar pairs are Rust-specific and get
0 commit comments