]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-6892.rs
Remove Ty prefix from Ty{Adt|Array|Slice|RawPtr|Ref|FnDef|FnPtr|Dynamic|Closure|Gener...
[rust.git] / src / test / run-pass / issue-6892.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Ensures that destructors are run for expressions of the form "let _ = e;"
12 // where `e` is a type which requires a destructor.
13
14
15 struct Foo;
16 struct Bar { x: isize }
17 struct Baz(isize);
18 enum FooBar { _Foo(Foo), _Bar(usize) }
19
20 static mut NUM_DROPS: usize = 0;
21
22 impl Drop for Foo {
23     fn drop(&mut self) {
24         unsafe { NUM_DROPS += 1; }
25     }
26 }
27 impl Drop for Bar {
28     fn drop(&mut self) {
29         unsafe { NUM_DROPS += 1; }
30     }
31 }
32 impl Drop for Baz {
33     fn drop(&mut self) {
34         unsafe { NUM_DROPS += 1; }
35     }
36 }
37 impl Drop for FooBar {
38     fn drop(&mut self) {
39         unsafe { NUM_DROPS += 1; }
40     }
41 }
42
43 fn main() {
44     assert_eq!(unsafe { NUM_DROPS }, 0);
45     { let _x = Foo; }
46     assert_eq!(unsafe { NUM_DROPS }, 1);
47     { let _x = Bar { x: 21 }; }
48     assert_eq!(unsafe { NUM_DROPS }, 2);
49     { let _x = Baz(21); }
50     assert_eq!(unsafe { NUM_DROPS }, 3);
51     { let _x = FooBar::_Foo(Foo); }
52     assert_eq!(unsafe { NUM_DROPS }, 5);
53     { let _x = FooBar::_Bar(42); }
54     assert_eq!(unsafe { NUM_DROPS }, 6);
55
56     { let _ = Foo; }
57     assert_eq!(unsafe { NUM_DROPS }, 7);
58     { let _ = Bar { x: 21 }; }
59     assert_eq!(unsafe { NUM_DROPS }, 8);
60     { let _ = Baz(21); }
61     assert_eq!(unsafe { NUM_DROPS }, 9);
62     { let _ = FooBar::_Foo(Foo); }
63     assert_eq!(unsafe { NUM_DROPS }, 11);
64     { let _ = FooBar::_Bar(42); }
65     assert_eq!(unsafe { NUM_DROPS }, 12);
66 }