1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![deny(improper_ctypes)]
14 #![allow(private_in_public)]
18 use std::marker::PhantomData;
20 trait Mirror { type It: ?Sized; }
21 impl<T: ?Sized> Mirror for T { type It = Self; }
23 pub struct StructWithProjection(*mut <StructWithProjection as Mirror>::It);
25 pub struct StructWithProjectionAndLifetime<'a>(
26 &'a mut <StructWithProjectionAndLifetime<'a> as Mirror>::It
28 pub type I32Pair = (i32, i32);
31 pub type RustFn = fn();
32 pub type RustBadRet = extern fn() -> Box<u32>;
33 pub type CVoidRet = ();
36 pub struct TransparentI128(i128);
38 pub struct TransparentStr(&'static str);
40 pub struct TransparentBadFn(RustBadRet);
42 pub struct TransparentInt(u32);
44 pub struct TransparentRef<'a>(&'a TransparentInt);
46 pub struct TransparentLifetime<'a>(*const u8, PhantomData<&'a ()>);
48 pub struct TransparentUnit<U>(f32, PhantomData<U>);
50 pub struct TransparentCustomZst(i32, ZeroSize);
53 pub struct ZeroSizeWithPhantomData(::std::marker::PhantomData<i32>);
56 pub fn ptr_type1(size: *const Foo); //~ ERROR: uses type `Foo`
57 pub fn ptr_type2(size: *const Foo); //~ ERROR: uses type `Foo`
58 pub fn slice_type(p: &[u32]); //~ ERROR: uses type `[u32]`
59 pub fn str_type(p: &str); //~ ERROR: uses type `str`
60 pub fn box_type(p: Box<u32>); //~ ERROR uses type `std::boxed::Box<u32>`
61 pub fn char_type(p: char); //~ ERROR uses type `char`
62 pub fn i128_type(p: i128); //~ ERROR uses type `i128`
63 pub fn u128_type(p: u128); //~ ERROR uses type `u128`
64 pub fn trait_type(p: &Clone); //~ ERROR uses type `dyn std::clone::Clone`
65 pub fn tuple_type(p: (i32, i32)); //~ ERROR uses type `(i32, i32)`
66 pub fn tuple_type2(p: I32Pair); //~ ERROR uses type `(i32, i32)`
67 pub fn zero_size(p: ZeroSize); //~ ERROR struct has no fields
68 pub fn zero_size_phantom(p: ZeroSizeWithPhantomData); //~ ERROR composed only of PhantomData
69 pub fn zero_size_phantom_toplevel()
70 -> ::std::marker::PhantomData<bool>; //~ ERROR: composed only of PhantomData
71 pub fn fn_type(p: RustFn); //~ ERROR function pointer has Rust-specific
72 pub fn fn_type2(p: fn()); //~ ERROR function pointer has Rust-specific
73 pub fn fn_contained(p: RustBadRet); //~ ERROR: uses type `std::boxed::Box<u32>`
74 pub fn transparent_i128(p: TransparentI128); //~ ERROR: uses type `i128`
75 pub fn transparent_str(p: TransparentStr); //~ ERROR: uses type `str`
76 pub fn transparent_fn(p: TransparentBadFn); //~ ERROR: uses type `std::boxed::Box<u32>`
78 pub fn good3(fptr: Option<extern fn()>);
79 pub fn good4(aptr: &[u8; 4 as usize]);
80 pub fn good5(s: StructWithProjection);
81 pub fn good6(s: StructWithProjectionAndLifetime);
82 pub fn good7(fptr: extern fn() -> ());
83 pub fn good8(fptr: extern fn() -> !);
85 pub fn good10() -> CVoidRet;
86 pub fn good11(size: isize);
87 pub fn good12(size: usize);
88 pub fn good13(n: TransparentInt);
89 pub fn good14(p: TransparentRef);
90 pub fn good15(p: TransparentLifetime);
91 pub fn good16(p: TransparentUnit<ZeroSize>);
92 pub fn good17(p: TransparentCustomZst);
93 #[allow(improper_ctypes)]
94 pub fn good18(_: &String);
97 #[allow(improper_ctypes)]
99 pub fn good19(_: &String);
102 #[cfg(not(target_arch = "wasm32"))]
104 pub fn good1(size: *const libc::c_int);
105 pub fn good2(size: *const libc::c_uint);