Skip to content

Commit f6ef555

Browse files
committed
merge transparent-abi test into general abi compatibility test, and test repr(transparent) unions
1 parent 02217d1 commit f6ef555

File tree

2 files changed

+42
-81
lines changed

2 files changed

+42
-81
lines changed

tests/ui/abi/compatibility.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// check-pass
2-
#![feature(rustc_attrs)]
2+
#![feature(rustc_attrs, transparent_unions)]
33
#![allow(unused, improper_ctypes_definitions)]
4+
use std::marker::PhantomData;
45
use std::num::NonZeroI32;
56
use std::ptr::NonNull;
67

@@ -27,7 +28,7 @@ struct ReprC2Int<T>(i32, T);
2728
#[repr(C)]
2829
struct ReprC2Float<T>(f32, T);
2930
#[repr(C)]
30-
struct ReprC4<T>(T, T, T, T);
31+
struct ReprC4<T>(T, Vec<i32>, Zst, T);
3132
#[repr(C)]
3233
struct ReprC4Mixed<T>(T, f32, i32, T);
3334
#[repr(C)]
@@ -73,6 +74,45 @@ test_abi_compatible!(zst_unit, Zst, ());
7374
test_abi_compatible!(zst_array, Zst, [u8; 0]);
7475
test_abi_compatible!(nonzero_int, NonZeroI32, i32);
7576

77+
// `repr(transparent)` compatibility.
78+
#[repr(transparent)]
79+
struct Wrapper1<T>(T);
80+
#[repr(transparent)]
81+
struct Wrapper2<T>((), Zst, T);
82+
#[repr(transparent)]
83+
struct Wrapper3<T>(T, [u8; 0], PhantomData<u64>);
84+
#[repr(transparent)]
85+
union WrapperUnion<T: Copy> {
86+
nothing: (),
87+
something: T,
88+
}
89+
90+
macro_rules! test_transparent {
91+
($name:ident, $t:ty) => {
92+
mod $name {
93+
use super::*;
94+
test_abi_compatible!(wrap1, $t, Wrapper1<$t>);
95+
test_abi_compatible!(wrap2, $t, Wrapper2<$t>);
96+
test_abi_compatible!(wrap3, $t, Wrapper3<$t>);
97+
test_abi_compatible!(wrap4, $t, WrapperUnion<$t>);
98+
}
99+
};
100+
}
101+
102+
test_transparent!(simple, i32);
103+
test_transparent!(reference, &'static i32);
104+
test_transparent!(zst, Zst);
105+
test_transparent!(unit, ());
106+
test_transparent!(pair, (i32, f32)); // mixing in some floats since they often get special treatment
107+
test_transparent!(triple, (i8, i16, f32)); // chosen to fit into 64bit
108+
test_transparent!(tuple, (i32, f32, i64, f64));
109+
test_transparent!(empty_array, [u32; 0]);
110+
test_transparent!(empty_1zst_array, [u8; 0]);
111+
test_transparent!(small_array, [i32; 2]); // chosen to fit into 64bit
112+
test_transparent!(large_array, [i32; 16]);
113+
test_transparent!(enum_, Option<i32>);
114+
test_transparent!(enum_niched, Option<&'static i32>);
115+
76116
// RFC 3391 <https://rust-lang.github.io/rfcs/3391-result_ffi_guarantees.html>.
77117
macro_rules! test_nonnull {
78118
($name:ident, $t:ty) => {

tests/ui/abi/transparent.rs

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)