]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/lint-ctypes.rs
Move parse-fail tests to UI
[rust.git] / src / test / ui / lint / lint-ctypes.rs
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.
4 //
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.
10
11 #![deny(improper_ctypes)]
12 #![feature(libc)]
13
14 #![allow(private_in_public)]
15
16 extern crate libc;
17
18 use std::marker::PhantomData;
19
20 trait Mirror { type It: ?Sized; }
21 impl<T: ?Sized> Mirror for T { type It = Self; }
22 #[repr(C)]
23 pub struct StructWithProjection(*mut <StructWithProjection as Mirror>::It);
24 #[repr(C)]
25 pub struct StructWithProjectionAndLifetime<'a>(
26     &'a mut <StructWithProjectionAndLifetime<'a> as Mirror>::It
27 );
28 pub type I32Pair = (i32, i32);
29 #[repr(C)]
30 pub struct ZeroSize;
31 pub type RustFn = fn();
32 pub type RustBadRet = extern fn() -> Box<u32>;
33 pub type CVoidRet = ();
34 pub struct Foo;
35 #[repr(transparent)]
36 pub struct TransparentI128(i128);
37 #[repr(transparent)]
38 pub struct TransparentStr(&'static str);
39 #[repr(transparent)]
40 pub struct TransparentBadFn(RustBadRet);
41 #[repr(transparent)]
42 pub struct TransparentInt(u32);
43 #[repr(transparent)]
44 pub struct TransparentRef<'a>(&'a TransparentInt);
45 #[repr(transparent)]
46 pub struct TransparentLifetime<'a>(*const u8, PhantomData<&'a ()>);
47 #[repr(transparent)]
48 pub struct TransparentUnit<U>(f32, PhantomData<U>);
49 #[repr(transparent)]
50 pub struct TransparentCustomZst(i32, ZeroSize);
51
52 #[repr(C)]
53 pub struct ZeroSizeWithPhantomData(::std::marker::PhantomData<i32>);
54
55 extern {
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>`
77
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() -> !);
84     pub fn good9() -> ();
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);
95 }
96
97 #[allow(improper_ctypes)]
98 extern {
99     pub fn good19(_: &String);
100 }
101
102 #[cfg(not(target_arch = "wasm32"))]
103 extern {
104     pub fn good1(size: *const libc::c_int);
105     pub fn good2(size: *const libc::c_uint);
106 }
107
108 fn main() {
109 }