File tree 1 file changed +15
-0
lines changed
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 7
7
#![ feature( pointer_is_aligned_to) ]
8
8
#![ feature( strict_provenance) ]
9
9
10
+
11
+ //! Tests type sizes, niches and field orderings.
12
+ //! Many asserts in this file are desirable optimizations, not guarantees.
13
+ //! Some of them are not even optimal, future layout improvements may break them.
14
+
15
+
10
16
use std:: mem:: size_of;
11
17
use std:: num:: NonZero ;
12
18
use std:: ptr;
@@ -238,6 +244,12 @@ struct VecDummy {
238
244
len : usize ,
239
245
}
240
246
247
+
248
+ struct DynTail {
249
+ a : usize ,
250
+ b : [ u8 ]
251
+ }
252
+
241
253
pub fn main ( ) {
242
254
assert_eq ! ( size_of:: <u8 >( ) , 1 as usize ) ;
243
255
assert_eq ! ( size_of:: <u32 >( ) , 4 as usize ) ;
@@ -355,4 +367,7 @@ pub fn main() {
355
367
assert ! ( ptr:: from_ref( & v. a) . addr( ) > ptr:: from_ref( & v. b) . addr( ) ) ;
356
368
357
369
370
+ // beyond NPO: address-space, alignment or metadata niches
371
+ assert_eq ! ( size_of:: <Option <Option <& ' static str >>>( ) , size_of:: <& ' static str >( ) ) ;
372
+ assert_eq ! ( size_of:: <Option <Option <& ' static DynTail >>>( ) , size_of:: <& ' static DynTail >( ) ) ;
358
373
}
You can’t perform that action at this time.
0 commit comments