]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/lint-ctypes.rs
Rollup merge of #39604 - est31:i128_tests, r=alexcrichton
[rust.git] / src / test / compile-fail / 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 extern crate libc;
15
16 trait Mirror { type It: ?Sized; }
17 impl<T: ?Sized> Mirror for T { type It = Self; }
18 #[repr(C)]
19 pub struct StructWithProjection(*mut <StructWithProjection as Mirror>::It);
20 #[repr(C)]
21 pub struct StructWithProjectionAndLifetime<'a>(
22     &'a mut <StructWithProjectionAndLifetime<'a> as Mirror>::It
23 );
24 pub type I32Pair = (i32, i32);
25 #[repr(C)]
26 pub struct ZeroSize;
27 pub type RustFn = fn();
28 pub type RustBadRet = extern fn() -> Box<u32>;
29 pub type CVoidRet = ();
30 pub struct Foo;
31
32 #[repr(C)]
33 pub struct ZeroSizeWithPhantomData(::std::marker::PhantomData<i32>);
34
35 extern {
36     pub fn ptr_type1(size: *const Foo); //~ ERROR: found struct without
37     pub fn ptr_type2(size: *const Foo); //~ ERROR: found struct without
38     pub fn slice_type(p: &[u32]); //~ ERROR: found Rust slice type
39     pub fn str_type(p: &str); //~ ERROR: found Rust type
40     pub fn box_type(p: Box<u32>); //~ ERROR found struct without
41     pub fn char_type(p: char); //~ ERROR found Rust type
42     pub fn trait_type(p: &Clone); //~ ERROR found Rust trait type
43     pub fn tuple_type(p: (i32, i32)); //~ ERROR found Rust tuple type
44     pub fn tuple_type2(p: I32Pair); //~ ERROR found Rust tuple type
45     pub fn zero_size(p: ZeroSize); //~ ERROR found zero-size struct
46     pub fn zero_size_phantom(p: ZeroSizeWithPhantomData); //~ ERROR found zero-sized type
47     pub fn zero_size_phantom_toplevel()
48         -> ::std::marker::PhantomData<bool>; //~ ERROR: found zero-sized type
49     pub fn fn_type(p: RustFn); //~ ERROR found function pointer with Rust
50     pub fn fn_type2(p: fn()); //~ ERROR found function pointer with Rust
51     pub fn fn_contained(p: RustBadRet); //~ ERROR: found struct without
52
53     pub fn good1(size: *const libc::c_int);
54     pub fn good2(size: *const libc::c_uint);
55     pub fn good3(fptr: Option<extern fn()>);
56     pub fn good4(aptr: &[u8; 4 as usize]);
57     pub fn good5(s: StructWithProjection);
58     pub fn good6(s: StructWithProjectionAndLifetime);
59     pub fn good7(fptr: extern fn() -> ());
60     pub fn good8(fptr: extern fn() -> !);
61     pub fn good9() -> ();
62     pub fn good10() -> CVoidRet;
63     pub fn good11(size: isize);
64     pub fn good12(size: usize);
65 }
66
67 fn main() {
68 }