2025-07-13 16:56:31 -04:00
|
|
|
// https://github.com/rust-lang/rust/issues/8860
|
2024-02-16 20:02:50 +00:00
|
|
|
//@ run-pass
|
2024-08-24 06:49:09 +03:00
|
|
|
// FIXME(static_mut_refs): this could use an atomic
|
|
|
|
|
#![allow(static_mut_refs)]
|
2018-09-25 23:51:35 +02:00
|
|
|
#![allow(dead_code)]
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
static mut DROP: isize = 0;
|
|
|
|
|
static mut DROP_S: isize = 0;
|
|
|
|
|
static mut DROP_T: isize = 0;
|
2014-02-14 13:27:05 +08:00
|
|
|
|
|
|
|
|
struct S;
|
|
|
|
|
impl Drop for S {
|
|
|
|
|
fn drop(&mut self) {
|
|
|
|
|
unsafe {
|
|
|
|
|
DROP_S += 1;
|
|
|
|
|
DROP += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn f(ref _s: S) {}
|
|
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
struct T { i: isize }
|
2014-02-14 13:27:05 +08:00
|
|
|
impl Drop for T {
|
|
|
|
|
fn drop(&mut self) {
|
|
|
|
|
unsafe {
|
|
|
|
|
DROP_T += 1;
|
|
|
|
|
DROP += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn g(ref _t: T) {}
|
|
|
|
|
|
2014-11-14 14:38:41 -08:00
|
|
|
fn do_test() {
|
2014-02-14 13:27:05 +08:00
|
|
|
let s = S;
|
|
|
|
|
f(s);
|
|
|
|
|
unsafe {
|
|
|
|
|
assert_eq!(1, DROP);
|
|
|
|
|
assert_eq!(1, DROP_S);
|
|
|
|
|
}
|
|
|
|
|
let t = T { i: 1 };
|
|
|
|
|
g(t);
|
|
|
|
|
unsafe { assert_eq!(1, DROP_T); }
|
|
|
|
|
}
|
2014-11-14 14:38:41 -08:00
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
do_test();
|
|
|
|
|
unsafe {
|
|
|
|
|
assert_eq!(2, DROP);
|
|
|
|
|
assert_eq!(1, DROP_S);
|
|
|
|
|
assert_eq!(1, DROP_T);
|
|
|
|
|
}
|
|
|
|
|
}
|