11use std:: mem;
22use std:: num;
33
4- #[ derive( Copy , Clone ) ]
4+ #[ derive( Copy , Clone , Default ) ]
55struct Zst ;
66
77fn test_abi_compat < T : Copy , U : Copy > ( t : T , u : U ) {
@@ -31,7 +31,7 @@ fn test_abi_compat<T: Copy, U: Copy>(t: T, u: U) {
3131}
3232
3333/// Ensure that `T` is compatible with various repr(transparent) wrappers around `T`.
34- fn test_abi_newtype < T : Copy > ( t : T ) {
34+ fn test_abi_newtype < T : Copy + Default > ( ) {
3535 #[ repr( transparent) ]
3636 #[ derive( Copy , Clone ) ]
3737 struct Wrapper1 < T > ( T ) ;
@@ -45,6 +45,7 @@ fn test_abi_newtype<T: Copy>(t: T) {
4545 #[ derive( Copy , Clone ) ]
4646 struct Wrapper3 < T > ( Zst , T , [ u8 ; 0 ] ) ;
4747
48+ let t = T :: default ( ) ;
4849 test_abi_compat ( t, Wrapper1 ( t) ) ;
4950 test_abi_compat ( t, Wrapper2 ( t, ( ) ) ) ;
5051 test_abi_compat ( t, Wrapper2a ( ( ) , t) ) ;
@@ -62,21 +63,24 @@ fn main() {
6263 // these would be stably guaranteed. Code that relies on this is equivalent to code that relies
6364 // on the layout of `repr(Rust)` types. They are also fragile: the same mismatches in the fields
6465 // of a struct (even with `repr(C)`) will not always be accepted by Miri.
66+ // Note that `bool` and `u8` are *not* compatible, at least on x86-64!
67+ // One of them has `arg_ext: Zext`, the other does not.
68+ // Similarly, `i32` and `u32` are not compatible on s390x due to different `arg_ext`.
6569 test_abi_compat ( 0u32 , 'x' ) ;
6670 test_abi_compat ( 42u32 , num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ;
6771 test_abi_compat ( 0u32 , Some ( num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ) ;
6872 test_abi_compat ( & 0u32 , & 0u32 as * const u32 ) ;
6973 test_abi_compat ( & 0u32 , & ( [ true ; 4 ] , [ 0u32 ; 0 ] ) ) ;
70- // Note that `bool` and `u8` are *not* compatible, at least on x86-64!
71- // One of them has `arg_ext: Zext`, the other does not.
7274
7375 // These must work for *any* type, since we guarantee that `repr(transparent)` is ABI-compatible
7476 // with the wrapped field.
75- test_abi_newtype ( ( ) ) ;
76- // FIXME: this still fails! test_abi_newtype(Zst);
77- test_abi_newtype ( 0u32 ) ;
78- test_abi_newtype ( 0f32 ) ;
79- test_abi_newtype ( ( 0u32 , 1u32 , 2u32 ) ) ;
80- test_abi_newtype ( [ 0u32 , 1u32 , 2u32 ] ) ;
81- test_abi_newtype ( [ 0i32 ; 0 ] ) ;
77+ test_abi_newtype :: < ( ) > ( ) ;
78+ test_abi_newtype :: < Zst > ( ) ;
79+ test_abi_newtype :: < u32 > ( ) ;
80+ test_abi_newtype :: < f32 > ( ) ;
81+ test_abi_newtype :: < ( u8 , u16 , f32 ) > ( ) ;
82+ test_abi_newtype :: < [ u8 ; 0 ] > ( ) ;
83+ test_abi_newtype :: < [ u32 ; 0 ] > ( ) ;
84+ test_abi_newtype :: < [ u32 ; 2 ] > ( ) ;
85+ test_abi_newtype :: < [ u32 ; 32 ] > ( ) ;
8286}
0 commit comments