blob: 1a67caf021cf7fc1a461e040925d53e832fe4526 [file] [log] [blame]
Oneirical75e02632025-07-13 16:56:31 -04001// https://github.com/rust-lang/rust/issues/8860
许杰友 Jieyou Xu (Joe)ec2cc7612024-02-16 20:02:50 +00002//@ run-pass
Obei Sideg3b0ce1b2024-08-24 06:49:09 +03003// FIXME(static_mut_refs): this could use an atomic
4#![allow(static_mut_refs)]
Felix S. Klock IIc9d9cc62018-09-25 23:51:35 +02005#![allow(dead_code)]
Brian Anderson8c93a792015-03-22 13:13:15 -07006
Alex Crichton43bfaa42015-03-25 17:06:52 -07007static mut DROP: isize = 0;
8static mut DROP_S: isize = 0;
9static mut DROP_T: isize = 0;
Edward Wangc1fac652014-02-14 13:27:05 +080010
Edward Wangc1fac652014-02-14 13:27:05 +080011struct S;
12impl Drop for S {
13 fn drop(&mut self) {
14 unsafe {
15 DROP_S += 1;
16 DROP += 1;
17 }
18 }
19}
20fn f(ref _s: S) {}
21
Alex Crichton43bfaa42015-03-25 17:06:52 -070022struct T { i: isize }
Edward Wangc1fac652014-02-14 13:27:05 +080023impl Drop for T {
24 fn drop(&mut self) {
25 unsafe {
26 DROP_T += 1;
27 DROP += 1;
28 }
29 }
30}
31fn g(ref _t: T) {}
32
Aaron Turon40c78ab02014-11-14 14:38:41 -080033fn do_test() {
Edward Wangc1fac652014-02-14 13:27:05 +080034 let s = S;
35 f(s);
36 unsafe {
37 assert_eq!(1, DROP);
38 assert_eq!(1, DROP_S);
39 }
40 let t = T { i: 1 };
41 g(t);
42 unsafe { assert_eq!(1, DROP_T); }
43}
Aaron Turon40c78ab02014-11-14 14:38:41 -080044
45fn main() {
46 do_test();
47 unsafe {
48 assert_eq!(2, DROP);
49 assert_eq!(1, DROP_S);
50 assert_eq!(1, DROP_T);
51 }
52}