]> git.proxmox.com Git - rustc.git/blob - src/test/ui/issues/issue-6892.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / ui / issues / issue-6892.rs
1 // run-pass
2 #![allow(dead_code)]
3 // Ensures that destructors are run for expressions of the form "let _ = e;"
4 // where `e` is a type which requires a destructor.
5
6
7 struct Foo;
8 struct Bar { x: isize }
9 struct Baz(isize);
10 enum FooBar { _Foo(Foo), _Bar(usize) }
11
12 static mut NUM_DROPS: usize = 0;
13
14 impl Drop for Foo {
15 fn drop(&mut self) {
16 unsafe { NUM_DROPS += 1; }
17 }
18 }
19 impl Drop for Bar {
20 fn drop(&mut self) {
21 unsafe { NUM_DROPS += 1; }
22 }
23 }
24 impl Drop for Baz {
25 fn drop(&mut self) {
26 unsafe { NUM_DROPS += 1; }
27 }
28 }
29 impl Drop for FooBar {
30 fn drop(&mut self) {
31 unsafe { NUM_DROPS += 1; }
32 }
33 }
34
35 fn main() {
36 assert_eq!(unsafe { NUM_DROPS }, 0);
37 { let _x = Foo; }
38 assert_eq!(unsafe { NUM_DROPS }, 1);
39 { let _x = Bar { x: 21 }; }
40 assert_eq!(unsafe { NUM_DROPS }, 2);
41 { let _x = Baz(21); }
42 assert_eq!(unsafe { NUM_DROPS }, 3);
43 { let _x = FooBar::_Foo(Foo); }
44 assert_eq!(unsafe { NUM_DROPS }, 5);
45 { let _x = FooBar::_Bar(42); }
46 assert_eq!(unsafe { NUM_DROPS }, 6);
47
48 { let _ = Foo; }
49 assert_eq!(unsafe { NUM_DROPS }, 7);
50 { let _ = Bar { x: 21 }; }
51 assert_eq!(unsafe { NUM_DROPS }, 8);
52 { let _ = Baz(21); }
53 assert_eq!(unsafe { NUM_DROPS }, 9);
54 { let _ = FooBar::_Foo(Foo); }
55 assert_eq!(unsafe { NUM_DROPS }, 11);
56 { let _ = FooBar::_Bar(42); }
57 assert_eq!(unsafe { NUM_DROPS }, 12);
58 }