]> git.proxmox.com Git - rustc.git/blob - src/test/ui/issues/issue-4734.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / src / test / ui / issues / issue-4734.rs
1 // run-pass
2 #![allow(dead_code)]
3 // Ensures that destructors are run for expressions of the form "e;" where
4 // `e` is a type which requires a destructor.
5
6
7 #![allow(path_statements)]
8
9 struct A { n: isize }
10 struct B;
11
12 static mut NUM_DROPS: usize = 0;
13
14 impl Drop for A {
15 fn drop(&mut self) {
16 unsafe { NUM_DROPS += 1; }
17 }
18 }
19
20 impl Drop for B {
21 fn drop(&mut self) {
22 unsafe { NUM_DROPS += 1; }
23 }
24 }
25
26 fn main() {
27 assert_eq!(unsafe { NUM_DROPS }, 0);
28 { let _a = A { n: 1 }; }
29 assert_eq!(unsafe { NUM_DROPS }, 1);
30 { A { n: 3 }; }
31 assert_eq!(unsafe { NUM_DROPS }, 2);
32
33 { let _b = B; }
34 assert_eq!(unsafe { NUM_DROPS }, 3);
35 { B; }
36 assert_eq!(unsafe { NUM_DROPS }, 4);
37 }