2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2014-04-07 22:03:13 +00:00
|
|
|
// Ensures that destructors are run for expressions of the form "e;" where
|
|
|
|
// `e` is a type which requires a destructor.
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2016-08-13 09:41:43 +00:00
|
|
|
#![allow(path_statements)]
|
2014-04-07 22:03:13 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
struct A { n: isize }
|
2014-04-07 22:03:13 +00:00
|
|
|
struct B;
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
static mut NUM_DROPS: usize = 0;
|
2014-04-07 22:03:13 +00:00
|
|
|
|
|
|
|
impl Drop for A {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe { NUM_DROPS += 1; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for B {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe { NUM_DROPS += 1; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 0);
|
|
|
|
{ let _a = A { n: 1 }; }
|
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 1);
|
|
|
|
{ A { n: 3 }; }
|
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 2);
|
|
|
|
|
|
|
|
{ let _b = B; }
|
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 3);
|
|
|
|
{ B; }
|
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 4);
|
|
|
|
}
|