2013-11-30 02:26:21 -06:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2015-02-11 06:57:40 -06:00
|
|
|
#![feature(unsafe_no_drop_flag)]
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
static mut drop_count: usize = 0;
|
2013-12-01 01:55:55 -06:00
|
|
|
|
|
|
|
#[unsafe_no_drop_flag]
|
|
|
|
struct Foo {
|
|
|
|
dropped: bool
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for Foo {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
// Test to make sure we haven't dropped already
|
|
|
|
assert!(!self.dropped);
|
|
|
|
self.dropped = true;
|
|
|
|
// And record the fact that we dropped for verification later
|
|
|
|
unsafe { drop_count += 1; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-30 02:26:21 -06:00
|
|
|
pub fn main() {
|
2013-12-01 01:55:55 -06:00
|
|
|
// An `if true { expr }` statement should compile the same as `{ expr }`.
|
2013-11-30 02:26:21 -06:00
|
|
|
if true {
|
2013-12-01 01:55:55 -06:00
|
|
|
let _a = Foo{ dropped: false };
|
2013-11-30 02:26:21 -06:00
|
|
|
}
|
2013-12-01 01:55:55 -06:00
|
|
|
// Check that we dropped already (as expected from a `{ expr }`).
|
|
|
|
unsafe { assert!(drop_count == 1); }
|
|
|
|
|
|
|
|
// An `if false {} else { expr }` statement should compile the same as `{ expr }`.
|
2013-11-30 02:26:21 -06:00
|
|
|
if false {
|
2014-10-09 14:17:22 -05:00
|
|
|
panic!();
|
2013-11-30 02:26:21 -06:00
|
|
|
} else {
|
2013-12-01 01:55:55 -06:00
|
|
|
let _a = Foo{ dropped: false };
|
2013-11-30 02:26:21 -06:00
|
|
|
}
|
2013-12-01 01:55:55 -06:00
|
|
|
// Check that we dropped already (as expected from a `{ expr }`).
|
|
|
|
unsafe { assert!(drop_count == 2); }
|
2013-11-30 02:26:21 -06:00
|
|
|
}
|