]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/lint-ctypes.rs
Rollup merge of #74555 - GuillaumeGomez:important-traits-popup, r=Manishearth
[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 Bar { }
11 trait Mirror { type It: ?Sized; }
12 impl<T: ?Sized> Mirror for T { type It = Self; }
13 #[repr(C)]
14 pub struct StructWithProjection(*mut <StructWithProjection as Mirror>::It);
15 #[repr(C)]
16 pub struct StructWithProjectionAndLifetime<'a>(
17     &'a mut <StructWithProjectionAndLifetime<'a> as Mirror>::It
18 );
19 pub type I32Pair = (i32, i32);
20 #[repr(C)]
21 pub struct ZeroSize;
22 pub type RustFn = fn();
23 pub type RustBadRet = extern fn() -> Box<u32>;
24 pub type CVoidRet = ();
25 pub struct Foo;
26 #[repr(transparent)]
27 pub struct TransparentI128(i128);
28 #[repr(transparent)]
29 pub struct TransparentStr(&'static str);
30 #[repr(transparent)]
31 pub struct TransparentBadFn(RustBadRet);
32 #[repr(transparent)]
33 pub struct TransparentInt(u32);
34 #[repr(transparent)]
35 pub struct TransparentRef<'a>(&'a TransparentInt);
36 #[repr(transparent)]
37 pub struct TransparentLifetime<'a>(*const u8, PhantomData<&'a ()>);
38 #[repr(transparent)]
39 pub struct TransparentUnit<U>(f32, PhantomData<U>);
40 #[repr(transparent)]
41 pub struct TransparentCustomZst(i32, ZeroSize);
42
43 #[repr(C)]
44 pub struct ZeroSizeWithPhantomData(::std::marker::PhantomData<i32>);
45
46 extern {
47     pub fn ptr_type1(size: *const Foo); //~ ERROR: uses type `Foo`
48     pub fn ptr_type2(size: *const Foo); //~ ERROR: uses type `Foo`
49     pub fn slice_type(p: &[u32]); //~ ERROR: uses type `[u32]`
50     pub fn str_type(p: &str); //~ ERROR: uses type `str`
51     pub fn box_type(p: Box<u32>); //~ ERROR uses type `std::boxed::Box<u32>`
52     pub fn opt_box_type(p: Option<Box<u32>>);
53     //~^ ERROR uses type `std::option::Option<std::boxed::Box<u32>>`
54     pub fn char_type(p: char); //~ ERROR uses type `char`
55     pub fn i128_type(p: i128); //~ ERROR uses type `i128`
56     pub fn u128_type(p: u128); //~ ERROR uses type `u128`
57     pub fn trait_type(p: &dyn Bar); //~ ERROR uses type `dyn Bar`
58     pub fn tuple_type(p: (i32, i32)); //~ ERROR uses type `(i32, i32)`
59     pub fn tuple_type2(p: I32Pair); //~ ERROR uses type `(i32, i32)`
60     pub fn zero_size(p: ZeroSize); //~ ERROR uses type `ZeroSize`
61     pub fn zero_size_phantom(p: ZeroSizeWithPhantomData);
62     //~^ ERROR uses type `ZeroSizeWithPhantomData`
63     pub fn zero_size_phantom_toplevel()
64         -> ::std::marker::PhantomData<bool>; //~ ERROR uses type `std::marker::PhantomData<bool>`
65     pub fn fn_type(p: RustFn); //~ ERROR uses type `fn()`
66     pub fn fn_type2(p: fn()); //~ ERROR uses type `fn()`
67     pub fn fn_contained(p: RustBadRet); //~ ERROR: uses type `std::boxed::Box<u32>`
68     pub fn transparent_i128(p: TransparentI128); //~ ERROR: uses type `i128`
69     pub fn transparent_str(p: TransparentStr); //~ ERROR: uses type `str`
70     pub fn transparent_fn(p: TransparentBadFn); //~ ERROR: uses type `std::boxed::Box<u32>`
71     pub fn raw_array(arr: [u8; 8]); //~ ERROR: uses type `[u8; 8]`
72
73     pub static static_u128_type: u128; //~ ERROR: uses type `u128`
74     pub static static_u128_array_type: [u128; 16]; //~ ERROR: uses type `u128`
75
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() -> !);
82     pub fn good9() -> ();
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);
93     pub fn good20(arr: *const [u8; 8]);
94     pub static good21: [u8; 8];
95
96 }
97
98 #[allow(improper_ctypes)]
99 extern {
100     pub fn good19(_: &String);
101 }
102
103 #[cfg(not(target_arch = "wasm32"))]
104 extern {
105     pub fn good1(size: *const libc::c_int);
106     pub fn good2(size: *const libc::c_uint);
107 }
108
109 fn main() {
110 }