]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/issue-10734.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / test / run-pass / issue-10734.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2013 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
c34b1796 11static mut drop_count: usize = 0;
1a4d82fc 12
1a4d82fc
JJ
13struct Foo {
14 dropped: bool
15}
16
17impl Drop for Foo {
18 fn drop(&mut self) {
19 // Test to make sure we haven't dropped already
20 assert!(!self.dropped);
21 self.dropped = true;
22 // And record the fact that we dropped for verification later
23 unsafe { drop_count += 1; }
24 }
25}
26
27pub fn main() {
28 // An `if true { expr }` statement should compile the same as `{ expr }`.
29 if true {
30 let _a = Foo{ dropped: false };
31 }
32 // Check that we dropped already (as expected from a `{ expr }`).
62682a34 33 unsafe { assert_eq!(drop_count, 1); }
1a4d82fc
JJ
34
35 // An `if false {} else { expr }` statement should compile the same as `{ expr }`.
36 if false {
37 panic!();
38 } else {
39 let _a = Foo{ dropped: false };
40 }
41 // Check that we dropped already (as expected from a `{ expr }`).
62682a34 42 unsafe { assert_eq!(drop_count, 2); }
1a4d82fc 43}