Skip to content

Commit 020067d

Browse files
committed
make sure the types in the ABI compat test actually type-check
1 parent cd71a37 commit 020067d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

tests/ui/abi/compatibility.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
use std::marker::PhantomData;
55
use std::num::NonZeroI32;
66
use std::ptr::NonNull;
7+
use std::mem::ManuallyDrop;
78

89
macro_rules! assert_abi_compatible {
910
($name:ident, $t1:ty, $t2:ty) => {
1011
mod $name {
1112
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) {}
1215
// Test argument and return value, `Rust` and `C` ABIs.
1316
#[rustc_abi(assert_eq)]
1417
type TestRust = (fn($t1) -> $t1, fn($t2) -> $t2);
@@ -37,9 +40,9 @@ enum ReprCEnum<T> {
3740
Variant2(T),
3841
}
3942
#[repr(C)]
40-
union ReprCUnion<T: Copy> {
43+
union ReprCUnion<T> {
4144
nothing: (),
42-
something: T,
45+
something: ManuallyDrop<T>,
4346
}
4447

4548
macro_rules! test_abi_compatible {
@@ -76,15 +79,15 @@ test_abi_compatible!(nonzero_int, NonZeroI32, i32);
7679

7780
// `repr(transparent)` compatibility.
7881
#[repr(transparent)]
79-
struct Wrapper1<T>(T);
82+
struct Wrapper1<T: ?Sized>(T);
8083
#[repr(transparent)]
81-
struct Wrapper2<T>((), Zst, T);
84+
struct Wrapper2<T: ?Sized>((), Zst, T);
8285
#[repr(transparent)]
8386
struct Wrapper3<T>(T, [u8; 0], PhantomData<u64>);
8487
#[repr(transparent)]
85-
union WrapperUnion<T: Copy> {
88+
union WrapperUnion<T> {
8689
nothing: (),
87-
something: T,
90+
something: ManuallyDrop<T>,
8891
}
8992

9093
macro_rules! test_transparent {

0 commit comments

Comments
 (0)