]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/drop_on_array_elements.rs
Auto merge of #104915 - weihanglo:update-cargo, r=ehuss
[rust.git] / src / tools / miri / tests / pass / drop_on_array_elements.rs
1 struct Bar(u16); // ZSTs are tested separately
2
3 static mut DROP_COUNT: usize = 0;
4
5 impl Drop for Bar {
6     fn drop(&mut self) {
7         assert_eq!(self.0 as usize, unsafe { DROP_COUNT }); // tests whether we are called at a valid address
8         unsafe {
9             DROP_COUNT += 1;
10         }
11     }
12 }
13
14 fn main() {
15     let b = [Bar(0), Bar(1), Bar(2), Bar(3)];
16     assert_eq!(unsafe { DROP_COUNT }, 0);
17     drop(b);
18     assert_eq!(unsafe { DROP_COUNT }, 4);
19
20     // check empty case
21     let b: [Bar; 0] = [];
22     drop(b);
23     assert_eq!(unsafe { DROP_COUNT }, 4);
24 }