2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2018-09-25 16:51:35 -05:00
|
|
|
#![allow(dead_code)]
|
2014-04-07 17:03:13 -05:00
|
|
|
// Ensures that destructors are run for expressions of the form "e;" where
|
|
|
|
// `e` is a type which requires a destructor.
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2016-08-13 04:41:43 -05:00
|
|
|
#![allow(path_statements)]
|
2014-04-07 17:03:13 -05:00
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
struct A { n: isize }
|
2014-04-07 17:03:13 -05:00
|
|
|
struct B;
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
static mut NUM_DROPS: usize = 0;
|
2014-04-07 17:03:13 -05: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);
|
|
|
|
}
|