1 #![feature(rustc_private)]
3 #![allow(private_in_public)]
4 #![deny(improper_ctypes_definitions)]
8 use std::default::Default;
9 use std::marker::PhantomData;
13 trait Mirror { type It: ?Sized; }
15 impl<T: ?Sized> Mirror for T { type It = Self; }
18 pub struct StructWithProjection(*mut <StructWithProjection as Mirror>::It);
21 pub struct StructWithProjectionAndLifetime<'a>(
22 &'a mut <StructWithProjectionAndLifetime<'a> as Mirror>::It
25 pub type I32Pair = (i32, i32);
30 pub type RustFn = fn();
32 pub type RustBadRet = extern "C" fn() -> Box<u32>;
34 pub type CVoidRet = ();
39 pub struct TransparentI128(i128);
42 pub struct TransparentStr(&'static str);
45 pub struct TransparentBadFn(RustBadRet);
48 pub struct TransparentInt(u32);
51 pub struct TransparentRef<'a>(&'a TransparentInt);
54 pub struct TransparentLifetime<'a>(*const u8, PhantomData<&'a ()>);
57 pub struct TransparentUnit<U>(f32, PhantomData<U>);
60 pub struct TransparentCustomZst(i32, ZeroSize);
63 pub struct ZeroSizeWithPhantomData(PhantomData<i32>);
65 pub extern "C" fn ptr_type1(size: *const Foo) { }
67 pub extern "C" fn ptr_type2(size: *const Foo) { }
69 pub extern "C" fn slice_type(p: &[u32]) { }
70 //~^ ERROR: uses type `[u32]`
72 pub extern "C" fn str_type(p: &str) { }
73 //~^ ERROR: uses type `str`
75 pub extern "C" fn box_type(p: Box<u32>) { }
77 pub extern "C" fn opt_box_type(p: Option<Box<u32>>) { }
79 pub extern "C" fn boxed_slice(p: Box<[u8]>) { }
80 //~^ ERROR: uses type `Box<[u8]>`
82 pub extern "C" fn boxed_string(p: Box<str>) { }
83 //~^ ERROR: uses type `Box<str>`
85 pub extern "C" fn boxed_trait(p: Box<dyn Trait>) { }
86 //~^ ERROR: uses type `Box<dyn Trait>`
88 pub extern "C" fn char_type(p: char) { }
89 //~^ ERROR uses type `char`
91 pub extern "C" fn i128_type(p: i128) { }
92 //~^ ERROR uses type `i128`
94 pub extern "C" fn u128_type(p: u128) { }
95 //~^ ERROR uses type `u128`
97 pub extern "C" fn tuple_type(p: (i32, i32)) { }
98 //~^ ERROR uses type `(i32, i32)`
100 pub extern "C" fn tuple_type2(p: I32Pair) { }
101 //~^ ERROR uses type `(i32, i32)`
103 pub extern "C" fn zero_size(p: ZeroSize) { }
104 //~^ ERROR uses type `ZeroSize`
106 pub extern "C" fn zero_size_phantom(p: ZeroSizeWithPhantomData) { }
107 //~^ ERROR uses type `ZeroSizeWithPhantomData`
109 pub extern "C" fn zero_size_phantom_toplevel() -> PhantomData<bool> {
110 //~^ ERROR uses type `PhantomData<bool>`
114 pub extern "C" fn fn_type(p: RustFn) { }
115 //~^ ERROR uses type `fn()`
117 pub extern "C" fn fn_type2(p: fn()) { }
118 //~^ ERROR uses type `fn()`
120 pub extern "C" fn fn_contained(p: RustBadRet) { }
122 pub extern "C" fn transparent_i128(p: TransparentI128) { }
123 //~^ ERROR: uses type `i128`
125 pub extern "C" fn transparent_str(p: TransparentStr) { }
126 //~^ ERROR: uses type `str`
128 pub extern "C" fn transparent_fn(p: TransparentBadFn) { }
130 pub extern "C" fn good3(fptr: Option<extern "C" fn()>) { }
132 pub extern "C" fn good4(aptr: &[u8; 4 as usize]) { }
134 pub extern "C" fn good5(s: StructWithProjection) { }
136 pub extern "C" fn good6(s: StructWithProjectionAndLifetime) { }
138 pub extern "C" fn good7(fptr: extern "C" fn() -> ()) { }
140 pub extern "C" fn good8(fptr: extern "C" fn() -> !) { }
142 pub extern "C" fn good9() -> () { }
144 pub extern "C" fn good10() -> CVoidRet { }
146 pub extern "C" fn good11(size: isize) { }
148 pub extern "C" fn good12(size: usize) { }
150 pub extern "C" fn good13(n: TransparentInt) { }
152 pub extern "C" fn good14(p: TransparentRef) { }
154 pub extern "C" fn good15(p: TransparentLifetime) { }
156 pub extern "C" fn good16(p: TransparentUnit<ZeroSize>) { }
158 pub extern "C" fn good17(p: TransparentCustomZst) { }
160 #[allow(improper_ctypes_definitions)]
161 pub extern "C" fn good18(_: &String) { }
163 #[cfg(not(target_arch = "wasm32"))]
164 pub extern "C" fn good1(size: *const libc::c_int) { }
166 #[cfg(not(target_arch = "wasm32"))]
167 pub extern "C" fn good2(size: *const libc::c_uint) { }
169 pub extern "C" fn unused_generic1<T>(size: *const Foo) { }
171 pub extern "C" fn unused_generic2<T>() -> PhantomData<bool> {
172 //~^ ERROR uses type `PhantomData<bool>`
176 pub extern "C" fn used_generic1<T>(x: T) { }
178 pub extern "C" fn used_generic2<T>(x: T, size: *const Foo) { }
180 pub extern "C" fn used_generic3<T: Default>() -> T {
184 pub extern "C" fn used_generic4<T>(x: Vec<T>) { }
185 //~^ ERROR: uses type `Vec<T>`
187 pub extern "C" fn used_generic5<T>() -> Vec<T> {
188 //~^ ERROR: uses type `Vec<T>`