]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-8860.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / issue-8860.rs
1 // Copyright 2012-2014 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 static mut DROP: int = 0i;
12 static mut DROP_S: int = 0i;
13 static mut DROP_T: int = 0i;
14
15 struct S;
16 impl Drop for S {
17     fn drop(&mut self) {
18         unsafe {
19             DROP_S += 1;
20             DROP += 1;
21         }
22     }
23 }
24 fn f(ref _s: S) {}
25
26 struct T { i: int }
27 impl Drop for T {
28     fn drop(&mut self) {
29         unsafe {
30             DROP_T += 1;
31             DROP += 1;
32         }
33     }
34 }
35 fn g(ref _t: T) {}
36
37 fn do_test() {
38     let s = S;
39     f(s);
40     unsafe {
41         assert_eq!(1, DROP);
42         assert_eq!(1, DROP_S);
43     }
44     let t = T { i: 1 };
45     g(t);
46     unsafe { assert_eq!(1, DROP_T); }
47 }
48
49 fn main() {
50     do_test();
51     unsafe {
52         assert_eq!(2, DROP);
53         assert_eq!(1, DROP_S);
54         assert_eq!(1, DROP_T);
55     }
56 }