|
4 | 4 | use std::marker::PhantomData; |
5 | 5 | use std::num::NonZeroI32; |
6 | 6 | use std::ptr::NonNull; |
| 7 | +use std::mem::ManuallyDrop; |
7 | 8 |
|
8 | 9 | macro_rules! assert_abi_compatible { |
9 | 10 | ($name:ident, $t1:ty, $t2:ty) => { |
10 | 11 | mod $name { |
11 | 12 | use super::*; |
| 13 | + // Declaring a `type` doesn't even check well-formedness, so we also declare a function. |
| 14 | + fn check_wf(_x: $t1, _y: $t2) {} |
12 | 15 | // Test argument and return value, `Rust` and `C` ABIs. |
13 | 16 | #[rustc_abi(assert_eq)] |
14 | 17 | type TestRust = (fn($t1) -> $t1, fn($t2) -> $t2); |
@@ -37,9 +40,9 @@ enum ReprCEnum<T> { |
37 | 40 | Variant2(T), |
38 | 41 | } |
39 | 42 | #[repr(C)] |
40 | | -union ReprCUnion<T: Copy> { |
| 43 | +union ReprCUnion<T> { |
41 | 44 | nothing: (), |
42 | | - something: T, |
| 45 | + something: ManuallyDrop<T>, |
43 | 46 | } |
44 | 47 |
|
45 | 48 | macro_rules! test_abi_compatible { |
@@ -76,15 +79,15 @@ test_abi_compatible!(nonzero_int, NonZeroI32, i32); |
76 | 79 |
|
77 | 80 | // `repr(transparent)` compatibility. |
78 | 81 | #[repr(transparent)] |
79 | | -struct Wrapper1<T>(T); |
| 82 | +struct Wrapper1<T: ?Sized>(T); |
80 | 83 | #[repr(transparent)] |
81 | | -struct Wrapper2<T>((), Zst, T); |
| 84 | +struct Wrapper2<T: ?Sized>((), Zst, T); |
82 | 85 | #[repr(transparent)] |
83 | 86 | struct Wrapper3<T>(T, [u8; 0], PhantomData<u64>); |
84 | 87 | #[repr(transparent)] |
85 | | -union WrapperUnion<T: Copy> { |
| 88 | +union WrapperUnion<T> { |
86 | 89 | nothing: (), |
87 | | - something: T, |
| 90 | + something: ManuallyDrop<T>, |
88 | 91 | } |
89 | 92 |
|
90 | 93 | macro_rules! test_transparent { |
|
0 commit comments