]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/lint-ctypes.rs
generalize bindings_with_variant_name lint
[rust.git] / src / test / ui / lint / lint-ctypes.rs
1 #![feature(rustc_private)]
2
3 #![allow(private_in_public)]
4 #![deny(improper_ctypes)]
5
6 extern crate libc;
7
8 use std::marker::PhantomData;
9
10 trait Mirror { type It: ?Sized; }
11 impl<T: ?Sized> Mirror for T { type It = Self; }
12 #[repr(C)]
13 pub struct StructWithProjection(*mut <StructWithProjection as Mirror>::It);
14 #[repr(C)]
15 pub struct StructWithProjectionAndLifetime<'a>(
16     &'a mut <StructWithProjectionAndLifetime<'a> as Mirror>::It
17 );
18 pub type I32Pair = (i32, i32);
19 #[repr(C)]
20 pub struct ZeroSize;
21 pub type RustFn = fn();
22 pub type RustBadRet = extern fn() -> Box<u32>;
23 pub type CVoidRet = ();
24 pub struct Foo;
25 #[repr(transparent)]
26 pub struct TransparentI128(i128);
27 #[repr(transparent)]
28 pub struct TransparentStr(&'static str);
29 #[repr(transparent)]
30 pub struct TransparentBadFn(RustBadRet);
31 #[repr(transparent)]
32 pub struct TransparentInt(u32);
33 #[repr(transparent)]
34 pub struct TransparentRef<'a>(&'a TransparentInt);
35 #[repr(transparent)]
36 pub struct TransparentLifetime<'a>(*const u8, PhantomData<&'a ()>);
37 #[repr(transparent)]
38 pub struct TransparentUnit<U>(f32, PhantomData<U>);
39 #[repr(transparent)]
40 pub struct TransparentCustomZst(i32, ZeroSize);
41
42 #[repr(C)]
43 pub struct ZeroSizeWithPhantomData(::std::marker::PhantomData<i32>);
44
45 extern {
46     pub fn ptr_type1(size: *const Foo); //~ ERROR: uses type `Foo`
47     pub fn ptr_type2(size: *const Foo); //~ ERROR: uses type `Foo`
48     pub fn slice_type(p: &[u32]); //~ ERROR: uses type `[u32]`
49     pub fn str_type(p: &str); //~ ERROR: uses type `str`
50     pub fn box_type(p: Box<u32>); //~ ERROR uses type `std::boxed::Box<u32>`
51     pub fn char_type(p: char); //~ ERROR uses type `char`
52     pub fn i128_type(p: i128); //~ ERROR uses type `i128`
53     pub fn u128_type(p: u128); //~ ERROR uses type `u128`
54     pub fn trait_type(p: &dyn Clone); //~ ERROR uses type `dyn std::clone::Clone`
55     pub fn tuple_type(p: (i32, i32)); //~ ERROR uses type `(i32, i32)`
56     pub fn tuple_type2(p: I32Pair); //~ ERROR uses type `(i32, i32)`
57     pub fn zero_size(p: ZeroSize); //~ ERROR uses type `ZeroSize`
58     pub fn zero_size_phantom(p: ZeroSizeWithPhantomData);
59     //~^ ERROR uses type `ZeroSizeWithPhantomData`
60     pub fn zero_size_phantom_toplevel()
61         -> ::std::marker::PhantomData<bool>; //~ ERROR uses type `std::marker::PhantomData<bool>`
62     pub fn fn_type(p: RustFn); //~ ERROR uses type `fn()`
63     pub fn fn_type2(p: fn()); //~ ERROR uses type `fn()`
64     pub fn fn_contained(p: RustBadRet); //~ ERROR: uses type `std::boxed::Box<u32>`
65     pub fn transparent_i128(p: TransparentI128); //~ ERROR: uses type `i128`
66     pub fn transparent_str(p: TransparentStr); //~ ERROR: uses type `str`
67     pub fn transparent_fn(p: TransparentBadFn); //~ ERROR: uses type `std::boxed::Box<u32>`
68     pub fn raw_array(arr: [u8; 8]); //~ ERROR: uses type `[u8; 8]`
69
70     pub static static_u128_type: u128; //~ ERROR: uses type `u128`
71     pub static static_u128_array_type: [u128; 16]; //~ ERROR: uses type `u128`
72
73     pub fn good3(fptr: Option<extern fn()>);
74     pub fn good4(aptr: &[u8; 4 as usize]);
75     pub fn good5(s: StructWithProjection);
76     pub fn good6(s: StructWithProjectionAndLifetime);
77     pub fn good7(fptr: extern fn() -> ());
78     pub fn good8(fptr: extern fn() -> !);
79     pub fn good9() -> ();
80     pub fn good10() -> CVoidRet;
81     pub fn good11(size: isize);
82     pub fn good12(size: usize);
83     pub fn good13(n: TransparentInt);
84     pub fn good14(p: TransparentRef);
85     pub fn good15(p: TransparentLifetime);
86     pub fn good16(p: TransparentUnit<ZeroSize>);
87     pub fn good17(p: TransparentCustomZst);
88     #[allow(improper_ctypes)]
89     pub fn good18(_: &String);
90     pub fn good20(arr: *const [u8; 8]);
91     pub static good21: [u8; 8];
92
93 }
94
95 #[allow(improper_ctypes)]
96 extern {
97     pub fn good19(_: &String);
98 }
99
100 #[cfg(not(target_arch = "wasm32"))]
101 extern {
102     pub fn good1(size: *const libc::c_int);
103     pub fn good2(size: *const libc::c_uint);
104 }
105
106 fn main() {
107 }