@@ -7,7 +7,9 @@ use std::{
77 ops:: { Bound , Deref } ,
88} ;
99
10+ #[ cfg( feature = "randomize" ) ]
1011use rand:: { seq:: SliceRandom , SeedableRng } ;
12+ #[ cfg( feature = "randomize" ) ]
1113use rand_xoshiro:: Xoshiro128StarStar ;
1214
1315use tracing:: debug;
@@ -91,14 +93,16 @@ pub trait LayoutCalculator {
9193 // If `-Z randomize-layout` was enabled for the type definition we can shuffle
9294 // the field ordering to try and catch some code making assumptions about layouts
9395 // we don't guarantee
94- if repr. can_randomize_type_layout ( ) {
95- // `ReprOptions.layout_seed` is a deterministic seed that we can use to
96- // randomize field ordering with
97- let mut rng = Xoshiro128StarStar :: seed_from_u64 ( repr. field_shuffle_seed ) ;
98-
99- // Shuffle the ordering of the fields
100- optimizing. shuffle ( & mut rng) ;
96+ if repr. can_randomize_type_layout ( ) && cfg ! ( feature = "randomize" ) {
97+ #[ cfg( feature = "randomize" ) ]
98+ {
99+ // `ReprOptions.layout_seed` is a deterministic seed that we can use to
100+ // randomize field ordering with
101+ let mut rng = Xoshiro128StarStar :: seed_from_u64 ( repr. field_shuffle_seed ) ;
101102
103+ // Shuffle the ordering of the fields
104+ optimizing. shuffle ( & mut rng) ;
105+ }
102106 // Otherwise we just leave things alone and actually optimize the type's fields
103107 } else {
104108 match kind {
@@ -900,7 +904,7 @@ pub trait LayoutCalculator {
900904 let mut abi = Abi :: Aggregate { sized : true } ;
901905 let index = V :: new ( 0 ) ;
902906 for field in & variants[ index] {
903- assert ! ( ! field. is_unsized ( ) ) ;
907+ assert ! ( field. is_sized ( ) ) ;
904908 align = align. max ( field. align ) ;
905909
906910 // If all non-ZST fields have the same ABI, forward this ABI
0 commit comments