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.
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.
11 // Check we reject structs that mix a `Drop` impl with `#[repr(C)]`.
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]`
16 #![feature(unsafe_no_drop_flag)]
17 #![deny(drop_with_repr_extern)]
18 //~^ NOTE lint level defined here
19 //~| NOTE lint level defined here
21 #[repr(C)] struct As { x: Box<i8> }
22 #[repr(C)] enum Ae { Ae(Box<i8>), _None }
24 struct Bs { x: Box<i8> }
25 enum Be { Be(Box<i8>), _None }
27 #[repr(C)] struct Cs { x: Box<i8> }
28 //~^ NOTE the `#[repr(C)]` attribute is attached here
30 impl Drop
for Cs { fn drop(&mut self) { }
}
31 //~^ ERROR implementing Drop adds hidden state to types, possibly conflicting with `#[repr(C)]`
33 #[repr(C)] enum Ce { Ce(Box<i8>), _None }
34 //~^ NOTE the `#[repr(C)]` attribute is attached here
36 impl Drop
for Ce { fn drop(&mut self) { }
}
37 //~^ ERROR implementing Drop adds hidden state to types, possibly conflicting with `#[repr(C)]`
39 #[unsafe_no_drop_flag]
40 #[repr(C)] struct Ds { x: Box<i8> }
42 impl Drop
for Ds { fn drop(&mut self) { }
}
44 #[unsafe_no_drop_flag]
45 #[repr(C)] enum De { De(Box<i8>), _None }
47 impl Drop
for De { fn drop(&mut self) { }
}
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) }
;
55 println
!("{:?}", (*a
.x
, *b
.x
, *c
.x
, *d
.x
));
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));