1
1
use std:: mem;
2
2
use std:: num;
3
3
4
- #[ derive( Copy , Clone ) ]
4
+ #[ derive( Copy , Clone , Default ) ]
5
5
struct Zst ;
6
6
7
7
fn 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) {
31
31
}
32
32
33
33
/// 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 > ( ) {
35
35
#[ repr( transparent) ]
36
36
#[ derive( Copy , Clone ) ]
37
37
struct Wrapper1 < T > ( T ) ;
@@ -45,6 +45,7 @@ fn test_abi_newtype<T: Copy>(t: T) {
45
45
#[ derive( Copy , Clone ) ]
46
46
struct Wrapper3 < T > ( Zst , T , [ u8 ; 0 ] ) ;
47
47
48
+ let t = T :: default ( ) ;
48
49
test_abi_compat ( t, Wrapper1 ( t) ) ;
49
50
test_abi_compat ( t, Wrapper2 ( t, ( ) ) ) ;
50
51
test_abi_compat ( t, Wrapper2a ( ( ) , t) ) ;
@@ -62,21 +63,24 @@ fn main() {
62
63
// these would be stably guaranteed. Code that relies on this is equivalent to code that relies
63
64
// on the layout of `repr(Rust)` types. They are also fragile: the same mismatches in the fields
64
65
// 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`.
65
69
test_abi_compat ( 0u32 , 'x' ) ;
66
70
test_abi_compat ( 42u32 , num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ;
67
71
test_abi_compat ( 0u32 , Some ( num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ) ;
68
72
test_abi_compat ( & 0u32 , & 0u32 as * const u32 ) ;
69
73
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.
72
74
73
75
// These must work for *any* type, since we guarantee that `repr(transparent)` is ABI-compatible
74
76
// 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 ] > ( ) ;
82
86
}
0 commit comments