@@ -968,8 +968,8 @@ fn univariant<
968
968
let mut align = if pack. is_some ( ) { dl. i8_align } else { dl. aggregate_align } ;
969
969
let mut max_repr_align = repr. align ;
970
970
let 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 {
973
973
let end = if let StructKind :: MaybeUnsized = kind { fields. len ( ) - 1 } else { fields. len ( ) } ;
974
974
let optimizing = & mut inverse_memory_index. raw [ ..end] ;
975
975
let fields_excluding_tail = & fields. raw [ ..end] ;
@@ -1176,7 +1176,7 @@ fn univariant<
1176
1176
// If field 5 has offset 0, offsets[0] is 5, and memory_index[5] should be 0.
1177
1177
// Field 5 would be the first element, so memory_index is i:
1178
1178
// Note: if we didn't optimize, it's already right.
1179
- let memory_index = if optimize {
1179
+ let memory_index = if optimize_field_order {
1180
1180
inverse_memory_index. invert_bijective_mapping ( )
1181
1181
} else {
1182
1182
debug_assert ! ( inverse_memory_index. iter( ) . copied( ) . eq( fields. indices( ) ) ) ;
@@ -1189,6 +1189,9 @@ fn univariant<
1189
1189
}
1190
1190
let mut layout_of_single_non_zst_field = None ;
1191
1191
let mut abi = Abi :: Aggregate { sized } ;
1192
+
1193
+ let optimize_abi = !repr. inhibit_newtype_abi_optimization ( ) ;
1194
+
1192
1195
// Try to make this a Scalar/ScalarPair.
1193
1196
if sized && size. bytes ( ) > 0 {
1194
1197
// We skip *all* ZST here and later check if we are good in terms of alignment.
@@ -1205,7 +1208,7 @@ fn univariant<
1205
1208
match field. abi {
1206
1209
// For plain scalars, or vectors of them, we can't unpack
1207
1210
// newtypes for `#[repr(C)]`, as that affects C ABIs.
1208
- Abi :: Scalar ( _) | Abi :: Vector { .. } if optimize => {
1211
+ Abi :: Scalar ( _) | Abi :: Vector { .. } if optimize_abi => {
1209
1212
abi = field. abi ;
1210
1213
}
1211
1214
// But scalar pairs are Rust-specific and get
0 commit comments