@@ -5,6 +5,10 @@ use std::ptr;
5
5
#[ derive( Copy , Clone , Default ) ]
6
6
struct Zst ;
7
7
8
+ #[ repr( transparent) ]
9
+ #[ derive( Copy , Clone ) ]
10
+ struct Wrapper < T > ( T ) ;
11
+
8
12
fn id < T > ( x : T ) -> T { x }
9
13
10
14
fn test_abi_compat < T : Clone , U : Clone > ( t : T , u : U ) {
@@ -35,9 +39,6 @@ fn test_abi_compat<T: Clone, U: Clone>(t: T, u: U) {
35
39
36
40
/// Ensure that `T` is compatible with various repr(transparent) wrappers around `T`.
37
41
fn test_abi_newtype < T : Copy + Default > ( ) {
38
- #[ repr( transparent) ]
39
- #[ derive( Copy , Clone ) ]
40
- struct Wrapper1 < T > ( T ) ;
41
42
#[ repr( transparent) ]
42
43
#[ derive( Copy , Clone ) ]
43
44
struct Wrapper2 < T > ( T , ( ) ) ;
@@ -49,7 +50,7 @@ fn test_abi_newtype<T: Copy + Default>() {
49
50
struct Wrapper3 < T > ( Zst , T , [ u8 ; 0 ] ) ;
50
51
51
52
let t = T :: default ( ) ;
52
- test_abi_compat ( t, Wrapper1 ( t) ) ;
53
+ test_abi_compat ( t, Wrapper ( t) ) ;
53
54
test_abi_compat ( t, Wrapper2 ( t, ( ) ) ) ;
54
55
test_abi_compat ( t, Wrapper2a ( ( ) , t) ) ;
55
56
test_abi_compat ( t, Wrapper3 ( Zst , t, [ ] ) ) ;
@@ -66,6 +67,7 @@ fn main() {
66
67
test_abi_compat ( 0usize , 0u64 ) ;
67
68
test_abi_compat ( 0isize , 0i64 ) ;
68
69
}
70
+ test_abi_compat ( 42u32 , num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ;
69
71
// Reference/pointer types with the same pointee.
70
72
test_abi_compat ( & 0u32 , & 0u32 as * const u32 ) ;
71
73
test_abi_compat ( & mut 0u32 as * mut u32 , Box :: new ( 0u32 ) ) ;
@@ -77,8 +79,9 @@ fn main() {
77
79
// Guaranteed null-pointer-optimizations.
78
80
test_abi_compat ( & 0u32 as * const u32 , Some ( & 0u32 ) ) ;
79
81
test_abi_compat ( main as fn ( ) , Some ( main as fn ( ) ) ) ;
80
- test_abi_compat ( 42u32 , num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ;
81
82
test_abi_compat ( 0u32 , Some ( num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ) ;
83
+ test_abi_compat ( & 0u32 as * const u32 , Some ( Wrapper ( & 0u32 ) ) ) ;
84
+ test_abi_compat ( 0u32 , Some ( Wrapper ( num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ) ) ;
82
85
83
86
// These must work for *any* type, since we guarantee that `repr(transparent)` is ABI-compatible
84
87
// with the wrapped field.
0 commit comments