1
1
use std:: mem;
2
2
use std:: num;
3
3
use std:: ptr;
4
+ use std:: rc:: Rc ;
4
5
5
6
#[ derive( Copy , Clone , Default ) ]
6
7
struct Zst ;
@@ -60,8 +61,8 @@ fn test_abi_newtype<T: Copy + Default>() {
60
61
}
61
62
62
63
fn 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.
65
66
if cfg ! ( target_pointer_width = "32" ) {
66
67
test_abi_compat ( 0usize , 0u32 ) ;
67
68
test_abi_compat ( 0isize , 0i32 ) ;
@@ -70,15 +71,17 @@ fn main() {
70
71
test_abi_compat ( 0isize , 0i64 ) ;
71
72
}
72
73
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.
74
75
test_abi_compat ( & 0u32 , & 0u32 as * const u32 ) ;
75
76
test_abi_compat ( & mut 0u32 as * mut u32 , Box :: new ( 0u32 ) ) ;
76
77
test_abi_compat ( & ( ) , ptr:: NonNull :: < ( ) > :: dangling ( ) ) ;
77
- // Reference/pointer types with different but sized pointees.
78
+ // - Reference/pointer types with different but sized pointees.
78
79
test_abi_compat ( & 0u32 , & ( [ true ; 4 ] , [ 0u32 ; 0 ] ) ) ;
79
- // `fn` types
80
+ // - `fn` types
80
81
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.
82
85
test_abi_compat ( & 0u32 as * const u32 , Some ( & 0u32 ) ) ;
83
86
test_abi_compat ( main as fn ( ) , Some ( main as fn ( ) ) ) ;
84
87
test_abi_compat ( 0u32 , Some ( num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ) ;
@@ -96,4 +99,11 @@ fn main() {
96
99
test_abi_newtype :: < [ u32 ; 0 ] > ( ) ;
97
100
test_abi_newtype :: < [ u32 ; 2 ] > ( ) ;
98
101
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) ;
99
109
}
0 commit comments