11use std:: mem;
22use std:: num;
33use std:: ptr;
4+ use std:: rc:: Rc ;
45
56#[ derive( Copy , Clone , Default ) ]
67struct Zst ;
@@ -60,8 +61,8 @@ fn test_abi_newtype<T: Copy + Default>() {
6061}
6162
6263fn main ( ) {
63- // Here we check some of the guaranteed ABI compatibilities.
64- // Different integer types of the same size and sign.
64+ // Here we check some of the guaranteed ABI compatibilities:
65+ // - Different integer types of the same size and sign.
6566 if cfg ! ( target_pointer_width = "32" ) {
6667 test_abi_compat ( 0usize , 0u32 ) ;
6768 test_abi_compat ( 0isize , 0i32 ) ;
@@ -70,15 +71,17 @@ fn main() {
7071 test_abi_compat ( 0isize , 0i64 ) ;
7172 }
7273 test_abi_compat ( 42u32 , num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ;
73- // Reference/pointer types with the same pointee.
74+ // - Reference/pointer types with the same pointee.
7475 test_abi_compat ( & 0u32 , & 0u32 as * const u32 ) ;
7576 test_abi_compat ( & mut 0u32 as * mut u32 , Box :: new ( 0u32 ) ) ;
7677 test_abi_compat ( & ( ) , ptr:: NonNull :: < ( ) > :: dangling ( ) ) ;
77- // Reference/pointer types with different but sized pointees.
78+ // - Reference/pointer types with different but sized pointees.
7879 test_abi_compat ( & 0u32 , & ( [ true ; 4 ] , [ 0u32 ; 0 ] ) ) ;
79- // `fn` types
80+ // - `fn` types
8081 test_abi_compat ( main as fn ( ) , id :: < i32 > as fn ( i32 ) -> i32 ) ;
81- // Guaranteed null-pointer-optimizations.
82+ // - 1-ZST
83+ test_abi_compat ( ( ) , [ 0u8 ; 0 ] ) ;
84+ // - Guaranteed null-pointer-optimizations.
8285 test_abi_compat ( & 0u32 as * const u32 , Some ( & 0u32 ) ) ;
8386 test_abi_compat ( main as fn ( ) , Some ( main as fn ( ) ) ) ;
8487 test_abi_compat ( 0u32 , Some ( num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ) ;
@@ -96,4 +99,11 @@ fn main() {
9699 test_abi_newtype :: < [ u32 ; 0 ] > ( ) ;
97100 test_abi_newtype :: < [ u32 ; 2 ] > ( ) ;
98101 test_abi_newtype :: < [ u32 ; 32 ] > ( ) ;
102+ test_abi_newtype :: < Option < i32 > > ( ) ;
103+ test_abi_newtype :: < Option < num:: NonZeroU32 > > ( ) ;
104+
105+ // Extra test for assumptions made by arbitrary-self-dyn-receivers.
106+ let rc = Rc :: new ( 0 ) ;
107+ let rc_ptr: * mut i32 = unsafe { mem:: transmute_copy ( & rc) } ;
108+ test_abi_compat ( rc, rc_ptr) ;
99109}
0 commit comments