1- #![ feature( portable_simd) ]
21use std:: mem;
32use std:: num;
4- use std:: simd;
53
6- #[ derive( Copy , Clone ) ]
4+ #[ derive( Copy , Clone , Default ) ]
75struct Zst ;
86
97fn test_abi_compat < T : Copy , U : Copy > ( t : T , u : U ) {
@@ -33,7 +31,7 @@ fn test_abi_compat<T: Copy, U: Copy>(t: T, u: U) {
3331}
3432
3533/// Ensure that `T` is compatible with various repr(transparent) wrappers around `T`.
36- fn test_abi_newtype < T : Copy > ( t : T ) {
34+ fn test_abi_newtype < T : Copy + Default > ( ) {
3735 #[ repr( transparent) ]
3836 #[ derive( Copy , Clone ) ]
3937 struct Wrapper1 < T > ( T ) ;
@@ -47,6 +45,7 @@ fn test_abi_newtype<T: Copy>(t: T) {
4745 #[ derive( Copy , Clone ) ]
4846 struct Wrapper3 < T > ( Zst , T , [ u8 ; 0 ] ) ;
4947
48+ let t = T :: default ( ) ;
5049 test_abi_compat ( t, Wrapper1 ( t) ) ;
5150 test_abi_compat ( t, Wrapper2 ( t, ( ) ) ) ;
5251 test_abi_compat ( t, Wrapper2a ( ( ) , t) ) ;
@@ -56,36 +55,32 @@ fn test_abi_newtype<T: Copy>(t: T) {
5655
5756fn main ( ) {
5857 // Here we check:
59- // - unsigned vs signed integer is allowed
60- // - u32/i32 vs char is allowed
58+ // - u32 vs char is allowed
6159 // - u32 vs NonZeroU32/Option<NonZeroU32> is allowed
6260 // - reference vs raw pointer is allowed
6361 // - references to things of the same size and alignment are allowed
6462 // These are very basic tests that should work on all ABIs. However it is not clear that any of
6563 // these would be stably guaranteed. Code that relies on this is equivalent to code that relies
6664 // on the layout of `repr(Rust)` types. They are also fragile: the same mismatches in the fields
6765 // of a struct (even with `repr(C)`) will not always be accepted by Miri.
68- test_abi_compat ( 0u32 , 0i32 ) ;
69- test_abi_compat ( simd:: u32x8:: splat ( 1 ) , simd:: i32x8:: splat ( 1 ) ) ;
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`.
7069 test_abi_compat ( 0u32 , 'x' ) ;
71- test_abi_compat ( 0i32 , 'x' ) ;
7270 test_abi_compat ( 42u32 , num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ;
7371 test_abi_compat ( 0u32 , Some ( num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ) ;
7472 test_abi_compat ( & 0u32 , & 0u32 as * const u32 ) ;
7573 test_abi_compat ( & 0u32 , & ( [ true ; 4 ] , [ 0u32 ; 0 ] ) ) ;
76- // Note that `bool` and `u8` are *not* compatible, at least on x86-64!
77- // One of them has `arg_ext: Zext`, the other does not.
7874
7975 // These must work for *any* type, since we guarantee that `repr(transparent)` is ABI-compatible
8076 // with the wrapped field.
81- test_abi_newtype ( ( ) ) ;
82- // FIXME: this still fails! test_abi_newtype(Zst);
83- test_abi_newtype ( 0u32 ) ;
84- test_abi_newtype ( 0f32 ) ;
85- test_abi_newtype ( ( 0u32 , 1u32 , 2u32 ) ) ;
86- // FIXME: skipping the array tests on mips64 due to https://github.com/rust-lang/rust/issues/115404
87- if !cfg ! ( target_arch = "mips64" ) {
88- test_abi_newtype ( [ 0u32 , 1u32 , 2u32 ] ) ;
89- test_abi_newtype ( [ 0i32 ; 0 ] ) ;
90- }
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 ] > ( ) ;
9186}
0 commit comments