Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abi/compatibility test: remove tests inside repr(C) wrappers #130185

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
abi/compatibility test: remove tests inside repr(C) wrappers
  • Loading branch information
RalfJung committed Sep 10, 2024
commit 86075759cc96748e56d70f6e25bbf319141ea82f
52 changes: 11 additions & 41 deletions tests/ui/abi/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ mod prelude {
#[cfg(not(host))]
use prelude::*;

macro_rules! assert_abi_compatible {
macro_rules! test_abi_compatible {
($name:ident, $t1:ty, $t2:ty) => {
mod $name {
use super::*;
Expand All @@ -212,16 +212,6 @@ impl Clone for Zst {
}
}

#[repr(C)]
struct ReprC1<T: ?Sized>(T);
#[repr(C)]
struct ReprC2Int<T>(i32, T);
#[repr(C)]
struct ReprC2Float<T>(f32, T);
#[repr(C)]
struct ReprC4<T>(T, Vec<i32>, Zst, T);
#[repr(C)]
struct ReprC4Mixed<T>(T, f32, i32, T);
#[repr(C)]
enum ReprCEnum<T> {
Variant1,
Expand All @@ -233,23 +223,6 @@ union ReprCUnion<T> {
something: ManuallyDrop<T>,
}

macro_rules! test_abi_compatible {
($name:ident, $t1:ty, $t2:ty) => {
mod $name {
use super::*;
assert_abi_compatible!(plain, $t1, $t2);
// We also do some tests with differences in fields of `repr(C)` types.
assert_abi_compatible!(repr_c_1, ReprC1<$t1>, ReprC1<$t2>);
assert_abi_compatible!(repr_c_2_int, ReprC2Int<$t1>, ReprC2Int<$t2>);
assert_abi_compatible!(repr_c_2_float, ReprC2Float<$t1>, ReprC2Float<$t2>);
assert_abi_compatible!(repr_c_4, ReprC4<$t1>, ReprC4<$t2>);
assert_abi_compatible!(repr_c_4mixed, ReprC4Mixed<$t1>, ReprC4Mixed<$t2>);
assert_abi_compatible!(repr_c_enum, ReprCEnum<$t1>, ReprCEnum<$t2>);
assert_abi_compatible!(repr_c_union, ReprCUnion<$t1>, ReprCUnion<$t2>);
}
};
}

// Compatibility of pointers.
test_abi_compatible!(ptr_mut, *const i32, *mut i32);
test_abi_compatible!(ptr_pointee, *const i32, *const Vec<i32>);
Expand All @@ -268,7 +241,6 @@ test_abi_compatible!(isize_int, isize, i64);

// Compatibility of 1-ZST.
test_abi_compatible!(zst_unit, Zst, ());
#[cfg(not(any(target_arch = "sparc64")))]
test_abi_compatible!(zst_array, Zst, [u8; 0]);
test_abi_compatible!(nonzero_int, NonZero<i32>, i32);

Expand All @@ -285,13 +257,13 @@ test_abi_compatible!(arc, Arc<i32>, *mut i32);

// `repr(transparent)` compatibility.
#[repr(transparent)]
struct Wrapper1<T: ?Sized>(T);
struct TransparentWrapper1<T: ?Sized>(T);
#[repr(transparent)]
struct Wrapper2<T: ?Sized>((), Zst, T);
struct TransparentWrapper2<T: ?Sized>((), Zst, T);
#[repr(transparent)]
struct Wrapper3<T>(T, [u8; 0], PhantomData<u64>);
struct TransparentWrapper3<T>(T, [u8; 0], PhantomData<u64>);
#[repr(transparent)]
union WrapperUnion<T> {
union TransparentWrapperUnion<T> {
nothing: (),
something: ManuallyDrop<T>,
}
Expand All @@ -300,10 +272,10 @@ macro_rules! test_transparent {
($name:ident, $t:ty) => {
mod $name {
use super::*;
test_abi_compatible!(wrap1, $t, Wrapper1<$t>);
test_abi_compatible!(wrap2, $t, Wrapper2<$t>);
test_abi_compatible!(wrap3, $t, Wrapper3<$t>);
test_abi_compatible!(wrap4, $t, WrapperUnion<$t>);
test_abi_compatible!(wrap1, $t, TransparentWrapper1<$t>);
test_abi_compatible!(wrap2, $t, TransparentWrapper2<$t>);
test_abi_compatible!(wrap3, $t, TransparentWrapper3<$t>);
test_abi_compatible!(wrap4, $t, TransparentWrapperUnion<$t>);
}
};
}
Expand Down Expand Up @@ -342,10 +314,8 @@ macro_rules! test_transparent_unsized {
($name:ident, $t:ty) => {
mod $name {
use super::*;
assert_abi_compatible!(wrap1, $t, Wrapper1<$t>);
assert_abi_compatible!(wrap1_reprc, ReprC1<$t>, ReprC1<Wrapper1<$t>>);
assert_abi_compatible!(wrap2, $t, Wrapper2<$t>);
assert_abi_compatible!(wrap2_reprc, ReprC1<$t>, ReprC1<Wrapper2<$t>>);
test_abi_compatible!(wrap1, $t, TransparentWrapper1<$t>);
test_abi_compatible!(wrap2, $t, TransparentWrapper2<$t>);
}
};
}
Expand Down
Loading