2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2018-09-25 23:51:35 +02:00
|
|
|
#![allow(dead_code)]
|
2014-04-07 15:03:13 -07:00
|
|
|
// Ensures that destructors are run for expressions of the form "let _ = e;"
|
|
|
|
|
// where `e` is a type which requires a destructor.
|
|
|
|
|
|
2024-08-24 06:49:09 +03:00
|
|
|
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
|
|
|
|
|
#![allow(static_mut_refs)]
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2014-04-07 15:03:13 -07:00
|
|
|
struct Foo;
|
2015-03-25 17:06:52 -07:00
|
|
|
struct Bar { x: isize }
|
|
|
|
|
struct Baz(isize);
|
|
|
|
|
enum FooBar { _Foo(Foo), _Bar(usize) }
|
2014-04-07 15:03:13 -07:00
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
static mut NUM_DROPS: usize = 0;
|
2014-04-07 15:03:13 -07:00
|
|
|
|
|
|
|
|
impl Drop for Foo {
|
|
|
|
|
fn drop(&mut self) {
|
|
|
|
|
unsafe { NUM_DROPS += 1; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl Drop for Bar {
|
|
|
|
|
fn drop(&mut self) {
|
|
|
|
|
unsafe { NUM_DROPS += 1; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl Drop for Baz {
|
|
|
|
|
fn drop(&mut self) {
|
|
|
|
|
unsafe { NUM_DROPS += 1; }
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-14 15:55:55 +02:00
|
|
|
impl Drop for FooBar {
|
|
|
|
|
fn drop(&mut self) {
|
|
|
|
|
unsafe { NUM_DROPS += 1; }
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-07 15:03:13 -07:00
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 0);
|
|
|
|
|
{ let _x = Foo; }
|
|
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 1);
|
|
|
|
|
{ let _x = Bar { x: 21 }; }
|
|
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 2);
|
|
|
|
|
{ let _x = Baz(21); }
|
|
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 3);
|
2014-11-06 00:05:53 -08:00
|
|
|
{ let _x = FooBar::_Foo(Foo); }
|
2014-06-14 15:55:55 +02:00
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 5);
|
2015-03-03 10:42:26 +02:00
|
|
|
{ let _x = FooBar::_Bar(42); }
|
2014-06-14 15:55:55 +02:00
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 6);
|
2014-04-07 15:03:13 -07:00
|
|
|
|
|
|
|
|
{ let _ = Foo; }
|
2014-06-14 15:55:55 +02:00
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 7);
|
2014-04-07 15:03:13 -07:00
|
|
|
{ let _ = Bar { x: 21 }; }
|
2014-06-14 15:55:55 +02:00
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 8);
|
2014-04-07 15:03:13 -07:00
|
|
|
{ let _ = Baz(21); }
|
2014-06-14 15:55:55 +02:00
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 9);
|
2014-11-06 00:05:53 -08:00
|
|
|
{ let _ = FooBar::_Foo(Foo); }
|
2014-06-14 15:55:55 +02:00
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 11);
|
2015-03-03 10:42:26 +02:00
|
|
|
{ let _ = FooBar::_Bar(42); }
|
2014-06-14 15:55:55 +02:00
|
|
|
assert_eq!(unsafe { NUM_DROPS }, 12);
|
2014-04-07 15:03:13 -07:00
|
|
|
}
|