blob: 4bf241fee2b3f922fff507631af87431d148fecb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#![allow(static_mut_refs)]
struct Bar(u16); // ZSTs are tested separately
static mut DROP_COUNT: usize = 0;
impl Drop for Bar {
fn drop(&mut self) {
assert_eq!(self.0 as usize, unsafe { DROP_COUNT }); // tests whether we are called at a valid address
unsafe {
DROP_COUNT += 1;
}
}
}
fn main() {
let b = [Bar(0), Bar(1), Bar(2), Bar(3)];
assert_eq!(unsafe { DROP_COUNT }, 0);
drop(b);
assert_eq!(unsafe { DROP_COUNT }, 4);
// check empty case
let b: [Bar; 0] = [];
drop(b);
assert_eq!(unsafe { DROP_COUNT }, 4);
}
|