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)]
16 use std::marker::PhantomData;
18 trait Mirror { type It: ?Sized; }
19 impl<T: ?Sized> Mirror for T { type It = Self; }
21 pub struct StructWithProjection(*mut <StructWithProjection as Mirror>::It);
23 pub struct StructWithProjectionAndLifetime<'a>(
24 &'a mut <StructWithProjectionAndLifetime<'a> as Mirror>::It
26 pub type I32Pair = (i32, i32);
29 pub type RustFn = fn();
30 pub type RustBadRet = extern fn() -> Box<u32>;
31 pub type CVoidRet = ();
34 pub struct TransparentI128(i128);
36 pub struct TransparentStr(&'static str);
38 pub struct TransparentBadFn(RustBadRet);
40 pub struct TransparentInt(u32);
42 pub struct TransparentRef<'a>(&'a TransparentInt);
44 pub struct TransparentLifetime<'a>(*const u8, PhantomData<&'a ()>);
46 pub struct TransparentUnit<U>(f32, PhantomData<U>);
48 pub struct TransparentCustomZst(i32, ZeroSize);
51 pub struct ZeroSizeWithPhantomData(::std::marker::PhantomData<i32>);
54 pub fn ptr_type1(size: *const Foo); //~ ERROR: uses type `Foo`
55 pub fn ptr_type2(size: *const Foo); //~ ERROR: uses type `Foo`
56 pub fn slice_type(p: &[u32]); //~ ERROR: uses type `[u32]`
57 pub fn str_type(p: &str); //~ ERROR: uses type `str`
58 pub fn box_type(p: Box<u32>); //~ ERROR uses type `std::boxed::Box<u32>`
59 pub fn char_type(p: char); //~ ERROR uses type `char`
60 pub fn i128_type(p: i128); //~ ERROR uses type `i128`
61 pub fn u128_type(p: u128); //~ ERROR uses type `u128`
62 pub fn trait_type(p: &Clone); //~ ERROR uses type `dyn std::clone::Clone`
63 pub fn tuple_type(p: (i32, i32)); //~ ERROR uses type `(i32, i32)`
64 pub fn tuple_type2(p: I32Pair); //~ ERROR uses type `(i32, i32)`
65 pub fn zero_size(p: ZeroSize); //~ ERROR struct has no fields
66 pub fn zero_size_phantom(p: ZeroSizeWithPhantomData); //~ ERROR composed only of PhantomData
67 pub fn zero_size_phantom_toplevel()
68 -> ::std::marker::PhantomData<bool>; //~ ERROR: composed only of PhantomData
69 pub fn fn_type(p: RustFn); //~ ERROR function pointer has Rust-specific
70 pub fn fn_type2(p: fn()); //~ ERROR function pointer has Rust-specific
71 pub fn fn_contained(p: RustBadRet); //~ ERROR: uses type `std::boxed::Box<u32>`
72 pub fn transparent_i128(p: TransparentI128); //~ ERROR: uses type `i128`
73 pub fn transparent_str(p: TransparentStr); //~ ERROR: uses type `str`
74 pub fn transparent_fn(p: TransparentBadFn); //~ ERROR: uses type `std::boxed::Box<u32>`
76 pub fn good3(fptr: Option<extern fn()>);
77 pub fn good4(aptr: &[u8; 4 as usize]);
78 pub fn good5(s: StructWithProjection);
79 pub fn good6(s: StructWithProjectionAndLifetime);
80 pub fn good7(fptr: extern fn() -> ());
81 pub fn good8(fptr: extern fn() -> !);
83 pub fn good10() -> CVoidRet;
84 pub fn good11(size: isize);
85 pub fn good12(size: usize);
86 pub fn good13(n: TransparentInt);
87 pub fn good14(p: TransparentRef);
88 pub fn good15(p: TransparentLifetime);
89 pub fn good16(p: TransparentUnit<ZeroSize>);
90 pub fn good17(p: TransparentCustomZst);
91 #[allow(improper_ctypes)]
92 pub fn good18(_: &String);
95 #[allow(improper_ctypes)]
97 pub fn good19(_: &String);
100 #[cfg(not(target_arch = "wasm32"))]
102 pub fn good1(size: *const libc::c_int);
103 pub fn good2(size: *const libc::c_uint);