Skip to content

Commit a023fdc

Browse files
committed
unit test.
1 parent 04f8a2d commit a023fdc

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
19+
#[repr(C)] struct A { x: Box<i8> }
20+
21+
struct B { x: Box<i8> }
22+
23+
#[repr(C)] struct C { x: Box<i8> }
24+
//~^ ERROR The `#[repr(C)]` attribute is attached here
25+
26+
impl Drop for C { fn drop(&mut self) { } }
27+
//~^ ERROR Structs with `#[repr(C)]` attribute that implement Drop have extra hidden state
28+
29+
#[unsafe_no_drop_flag]
30+
#[repr(C)] struct D { x: Box<i8> }
31+
32+
impl Drop for D { fn drop(&mut self) { } }
33+
34+
fn main() {
35+
let a = A { x: Box::new(3) };
36+
let b = B { x: Box::new(3) };
37+
let c = C { x: Box::new(3) };
38+
let d = D { x: Box::new(3) };
39+
println!("{:?}", (*a.x, *b.x, *c.x, *d.x));
40+
}

0 commit comments

Comments
 (0)