Skip to content

Commit

Permalink
Rollup merge of #130185 - RalfJung:abi-compat-repr-c-wrappers, r=comp…
Browse files Browse the repository at this point in the history
…iler-errors

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

When I wrote the test I assumed we'd guarantee ABI compatibility to be "structural" wrt `repr(C)` types, i.e. if two `repr(C)` types have all their fields be pairwise ABI-compatible then the types are ABI-compatible. That got removed from the ABI compatibility docs before they landed, though, so let's also remove it from this test.
  • Loading branch information
matthiaskrgr authored Sep 10, 2024
2 parents 98222a5 + 8607575 commit a42d67e
Showing 1 changed file with 11 additions and 41 deletions.
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

0 comments on commit a42d67e

Please sign in to comment.