@@ -5,6 +5,10 @@ use std::ptr;
55#[ derive( Copy , Clone , Default ) ]
66struct Zst ;
77
8+ #[ repr( transparent) ]
9+ #[ derive( Copy , Clone ) ]
10+ struct Wrapper < T > ( T ) ;
11+
812fn id < T > ( x : T ) -> T { x }
913
1014fn 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) {
3539
3640/// Ensure that `T` is compatible with various repr(transparent) wrappers around `T`.
3741fn test_abi_newtype < T : Copy + Default > ( ) {
38- #[ repr( transparent) ]
39- #[ derive( Copy , Clone ) ]
40- struct Wrapper1 < T > ( T ) ;
4142 #[ repr( transparent) ]
4243 #[ derive( Copy , Clone ) ]
4344 struct Wrapper2 < T > ( T , ( ) ) ;
@@ -49,7 +50,7 @@ fn test_abi_newtype<T: Copy + Default>() {
4950 struct Wrapper3 < T > ( Zst , T , [ u8 ; 0 ] ) ;
5051
5152 let t = T :: default ( ) ;
52- test_abi_compat ( t, Wrapper1 ( t) ) ;
53+ test_abi_compat ( t, Wrapper ( t) ) ;
5354 test_abi_compat ( t, Wrapper2 ( t, ( ) ) ) ;
5455 test_abi_compat ( t, Wrapper2a ( ( ) , t) ) ;
5556 test_abi_compat ( t, Wrapper3 ( Zst , t, [ ] ) ) ;
@@ -66,6 +67,7 @@ fn main() {
6667 test_abi_compat ( 0usize , 0u64 ) ;
6768 test_abi_compat ( 0isize , 0i64 ) ;
6869 }
70+ test_abi_compat ( 42u32 , num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ;
6971 // Reference/pointer types with the same pointee.
7072 test_abi_compat ( & 0u32 , & 0u32 as * const u32 ) ;
7173 test_abi_compat ( & mut 0u32 as * mut u32 , Box :: new ( 0u32 ) ) ;
@@ -77,8 +79,9 @@ fn main() {
7779 // Guaranteed null-pointer-optimizations.
7880 test_abi_compat ( & 0u32 as * const u32 , Some ( & 0u32 ) ) ;
7981 test_abi_compat ( main as fn ( ) , Some ( main as fn ( ) ) ) ;
80- test_abi_compat ( 42u32 , num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ;
8182 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 ( ) ) ) ) ;
8285
8386 // These must work for *any* type, since we guarantee that `repr(transparent)` is ABI-compatible
8487 // with the wrapped field.
0 commit comments