| Oneirical | 75e0263 | 2025-07-13 16:56:31 -0400 | [diff] [blame] | 1 | // https://github.com/rust-lang/rust/issues/8860 |
| 许杰友 Jieyou Xu (Joe) | ec2cc761 | 2024-02-16 20:02:50 +0000 | [diff] [blame] | 2 | //@ run-pass |
| Obei Sideg | 3b0ce1b | 2024-08-24 06:49:09 +0300 | [diff] [blame] | 3 | // FIXME(static_mut_refs): this could use an atomic |
| 4 | #![allow(static_mut_refs)] |
| Felix S. Klock II | c9d9cc6 | 2018-09-25 23:51:35 +0200 | [diff] [blame] | 5 | #![allow(dead_code)] |
| Brian Anderson | 8c93a79 | 2015-03-22 13:13:15 -0700 | [diff] [blame] | 6 | |
| Alex Crichton | 43bfaa4 | 2015-03-25 17:06:52 -0700 | [diff] [blame] | 7 | static mut DROP: isize = 0; |
| 8 | static mut DROP_S: isize = 0; |
| 9 | static mut DROP_T: isize = 0; |
| Edward Wang | c1fac65 | 2014-02-14 13:27:05 +0800 | [diff] [blame] | 10 | |
| Edward Wang | c1fac65 | 2014-02-14 13:27:05 +0800 | [diff] [blame] | 11 | struct S; |
| 12 | impl Drop for S { |
| 13 | fn drop(&mut self) { |
| 14 | unsafe { |
| 15 | DROP_S += 1; |
| 16 | DROP += 1; |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | fn f(ref _s: S) {} |
| 21 | |
| Alex Crichton | 43bfaa4 | 2015-03-25 17:06:52 -0700 | [diff] [blame] | 22 | struct T { i: isize } |
| Edward Wang | c1fac65 | 2014-02-14 13:27:05 +0800 | [diff] [blame] | 23 | impl Drop for T { |
| 24 | fn drop(&mut self) { |
| 25 | unsafe { |
| 26 | DROP_T += 1; |
| 27 | DROP += 1; |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | fn g(ref _t: T) {} |
| 32 | |
| Aaron Turon | 40c78ab0 | 2014-11-14 14:38:41 -0800 | [diff] [blame] | 33 | fn do_test() { |
| Edward Wang | c1fac65 | 2014-02-14 13:27:05 +0800 | [diff] [blame] | 34 | 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 Turon | 40c78ab0 | 2014-11-14 14:38:41 -0800 | [diff] [blame] | 44 | |
| 45 | fn 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 | } |