@@ -1050,15 +1050,15 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
1050
1050
let mut align = if pack. is_some ( ) { dl. i8_align } else { dl. aggregate_align } ;
1051
1051
let mut max_repr_align = repr. align ;
1052
1052
let mut inverse_memory_index: IndexVec < u32 , FieldIdx > = fields. indices ( ) . collect ( ) ;
1053
- let field_seed =
1054
- fields. raw . iter ( ) . fold ( 0u64 , |acc, f| acc. wrapping_add ( f. randomization_seed ) ) ;
1055
1053
let optimize_field_order = !repr. inhibit_struct_field_reordering ( ) ;
1056
- if optimize_field_order && fields. len ( ) > 1 {
1057
- let end =
1058
- if let StructKind :: MaybeUnsized = kind { fields. len ( ) - 1 } else { fields. len ( ) } ;
1059
- let optimizing = & mut inverse_memory_index. raw [ ..end] ;
1060
- let fields_excluding_tail = & fields. raw [ ..end] ;
1054
+ let end = if let StructKind :: MaybeUnsized = kind { fields. len ( ) - 1 } else { fields. len ( ) } ;
1055
+ let optimizing = & mut inverse_memory_index. raw [ ..end] ;
1056
+ let fields_excluding_tail = & fields. raw [ ..end] ;
1057
+ let field_seed = fields_excluding_tail
1058
+ . iter ( )
1059
+ . fold ( 0u64 , |acc, f| acc. wrapping_add ( f. randomization_seed ) ) ;
1061
1060
1061
+ if optimize_field_order && fields. len ( ) > 1 {
1062
1062
// If `-Z randomize-layout` was enabled for the type definition we can shuffle
1063
1063
// the field ordering to try and catch some code making assumptions about layouts
1064
1064
// we don't guarantee.
@@ -1370,6 +1370,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
1370
1370
} ;
1371
1371
1372
1372
// a transparent struct only has a single field, so its seed should be the same as the one we pass forward
1373
+ // if the field is also unsizable then we pass zero, which is the identity-element wrapping-add used for seed mixing
1373
1374
let seed = if repr. transparent ( ) {
1374
1375
field_seed
1375
1376
} else {
0 commit comments