]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/lint-no-drop-on-repr-extern.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / lint-no-drop-on-repr-extern.rs
1 // Copyright 2015 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 // Check we reject structs that mix a `Drop` impl with `#[repr(C)]`.
12 //
13 // As a special case, also check that we do not warn on such structs
14 // if they also are declared with `#[unsafe_no_drop_flag]`
15
16 #![feature(unsafe_no_drop_flag)]
17 #![deny(drop_with_repr_extern)]
18 //~^ NOTE lint level defined here
19 //~| NOTE lint level defined here
20
21 #[repr(C)] struct As { x: Box<i8> }
22 #[repr(C)] enum Ae { Ae(Box<i8>), _None }
23
24 struct Bs { x: Box<i8> }
25 enum Be { Be(Box<i8>), _None }
26
27 #[repr(C)] struct Cs { x: Box<i8> }
28 //~^ NOTE the `#[repr(C)]` attribute is attached here
29
30 impl Drop for Cs { fn drop(&mut self) { } }
31 //~^ ERROR implementing Drop adds hidden state to types, possibly conflicting with `#[repr(C)]`
32
33 #[repr(C)] enum Ce { Ce(Box<i8>), _None }
34 //~^ NOTE the `#[repr(C)]` attribute is attached here
35
36 impl Drop for Ce { fn drop(&mut self) { } }
37 //~^ ERROR implementing Drop adds hidden state to types, possibly conflicting with `#[repr(C)]`
38
39 #[unsafe_no_drop_flag]
40 #[repr(C)] struct Ds { x: Box<i8> }
41
42 impl Drop for Ds { fn drop(&mut self) { } }
43
44 #[unsafe_no_drop_flag]
45 #[repr(C)] enum De { De(Box<i8>), _None }
46
47 impl Drop for De { fn drop(&mut self) { } }
48
49 fn main() {
50 let a = As { x: Box::new(3) };
51 let b = Bs { x: Box::new(3) };
52 let c = Cs { x: Box::new(3) };
53 let d = Ds { x: Box::new(3) };
54
55 println!("{:?}", (*a.x, *b.x, *c.x, *d.x));
56
57 let _a = Ae::Ae(Box::new(3));
58 let _b = Be::Be(Box::new(3));
59 let _c = Ce::Ce(Box::new(3));
60 let _d = De::De(Box::new(3));
61 }