1
- #![ feature( portable_simd) ]
2
1
use std:: mem;
3
2
use std:: num;
4
- use std:: simd;
5
3
6
- #[ derive( Copy , Clone ) ]
4
+ #[ derive( Copy , Clone , Default ) ]
7
5
struct Zst ;
8
6
9
7
fn 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) {
33
31
}
34
32
35
33
/// 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 > ( ) {
37
35
#[ repr( transparent) ]
38
36
#[ derive( Copy , Clone ) ]
39
37
struct Wrapper1 < T > ( T ) ;
@@ -47,6 +45,7 @@ fn test_abi_newtype<T: Copy>(t: T) {
47
45
#[ derive( Copy , Clone ) ]
48
46
struct Wrapper3 < T > ( Zst , T , [ u8 ; 0 ] ) ;
49
47
48
+ let t = T :: default ( ) ;
50
49
test_abi_compat ( t, Wrapper1 ( t) ) ;
51
50
test_abi_compat ( t, Wrapper2 ( t, ( ) ) ) ;
52
51
test_abi_compat ( t, Wrapper2a ( ( ) , t) ) ;
@@ -56,36 +55,32 @@ fn test_abi_newtype<T: Copy>(t: T) {
56
55
57
56
fn main ( ) {
58
57
// Here we check:
59
- // - unsigned vs signed integer is allowed
60
- // - u32/i32 vs char is allowed
58
+ // - u32 vs char is allowed
61
59
// - u32 vs NonZeroU32/Option<NonZeroU32> is allowed
62
60
// - reference vs raw pointer is allowed
63
61
// - references to things of the same size and alignment are allowed
64
62
// These are very basic tests that should work on all ABIs. However it is not clear that any of
65
63
// these would be stably guaranteed. Code that relies on this is equivalent to code that relies
66
64
// on the layout of `repr(Rust)` types. They are also fragile: the same mismatches in the fields
67
65
// 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`.
70
69
test_abi_compat ( 0u32 , 'x' ) ;
71
- test_abi_compat ( 0i32 , 'x' ) ;
72
70
test_abi_compat ( 42u32 , num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ;
73
71
test_abi_compat ( 0u32 , Some ( num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ) ;
74
72
test_abi_compat ( & 0u32 , & 0u32 as * const u32 ) ;
75
73
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.
78
74
79
75
// These must work for *any* type, since we guarantee that `repr(transparent)` is ABI-compatible
80
76
// 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 ] > ( ) ;
91
86
}
0 commit comments