File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 77#![ feature( pointer_is_aligned_to) ]
88#![ feature( strict_provenance) ]
99
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+
1016use std:: mem:: size_of;
1117use std:: num:: NonZero ;
1218use std:: ptr;
@@ -238,6 +244,12 @@ struct VecDummy {
238244 len : usize ,
239245}
240246
247+
248+ struct DynTail {
249+ a : usize ,
250+ b : [ u8 ]
251+ }
252+
241253pub fn main ( ) {
242254 assert_eq ! ( size_of:: <u8 >( ) , 1 as usize ) ;
243255 assert_eq ! ( size_of:: <u32 >( ) , 4 as usize ) ;
@@ -355,4 +367,7 @@ pub fn main() {
355367 assert ! ( ptr:: from_ref( & v. a) . addr( ) > ptr:: from_ref( & v. b) . addr( ) ) ;
356368
357369
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 >( ) ) ;
358373}
You can’t perform that action at this time.
0 commit comments