2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2018-08-31 13:02:01 +00:00
|
|
|
#![allow(non_upper_case_globals)]
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
static mut drop_count: usize = 0;
|
2013-12-01 07:55:55 +00:00
|
|
|
|
|
|
|
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 08:26:21 +00:00
|
|
|
pub fn main() {
|
2013-12-01 07:55:55 +00:00
|
|
|
// An `if true { expr }` statement should compile the same as `{ expr }`.
|
2013-11-30 08:26:21 +00:00
|
|
|
if true {
|
2013-12-01 07:55:55 +00:00
|
|
|
let _a = Foo{ dropped: false };
|
2013-11-30 08:26:21 +00:00
|
|
|
}
|
2013-12-01 07:55:55 +00:00
|
|
|
// Check that we dropped already (as expected from a `{ expr }`).
|
2015-06-07 18:00:38 +00:00
|
|
|
unsafe { assert_eq!(drop_count, 1); }
|
2013-12-01 07:55:55 +00:00
|
|
|
|
|
|
|
// An `if false {} else { expr }` statement should compile the same as `{ expr }`.
|
2013-11-30 08:26:21 +00:00
|
|
|
if false {
|
2014-10-09 19:17:22 +00:00
|
|
|
panic!();
|
2013-11-30 08:26:21 +00:00
|
|
|
} else {
|
2013-12-01 07:55:55 +00:00
|
|
|
let _a = Foo{ dropped: false };
|
2013-11-30 08:26:21 +00:00
|
|
|
}
|
2013-12-01 07:55:55 +00:00
|
|
|
// Check that we dropped already (as expected from a `{ expr }`).
|
2015-06-07 18:00:38 +00:00
|
|
|
unsafe { assert_eq!(drop_count, 2); }
|
2013-11-30 08:26:21 +00:00
|
|
|
}
|