2020-04-16 15:50:32 +09:00
|
|
|
// run-fail
|
2021-12-03 15:32:51 +00:00
|
|
|
// needs-unwind
|
2016-01-31 15:07:18 +02:00
|
|
|
// error-pattern:unwind happens
|
|
|
|
// error-pattern:drop 3
|
|
|
|
// error-pattern:drop 2
|
|
|
|
// error-pattern:drop 1
|
2020-05-08 00:39:02 +09:00
|
|
|
// ignore-emscripten no processes
|
2016-01-31 15:07:18 +02:00
|
|
|
|
|
|
|
/// Structure which will not allow to be dropped twice.
|
2016-02-24 20:36:20 +02:00
|
|
|
struct Droppable<'a>(&'a mut bool, u32);
|
|
|
|
impl<'a> Drop for Droppable<'a> {
|
2016-01-31 15:07:18 +02:00
|
|
|
fn drop(&mut self) {
|
2016-02-24 20:36:20 +02:00
|
|
|
if *self.0 {
|
2017-09-25 00:14:56 -04:00
|
|
|
eprintln!("{} dropped twice", self.1);
|
2016-01-31 15:07:18 +02:00
|
|
|
::std::process::exit(1);
|
|
|
|
}
|
2017-09-25 00:14:56 -04:00
|
|
|
eprintln!("drop {}", self.1);
|
2016-02-24 20:36:20 +02:00
|
|
|
*self.0 = true;
|
2016-01-31 15:07:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 20:36:20 +02:00
|
|
|
fn may_panic<'a>() -> Droppable<'a> {
|
2016-01-31 15:07:18 +02:00
|
|
|
panic!("unwind happens");
|
|
|
|
}
|
|
|
|
|
2016-05-27 08:09:36 +05:30
|
|
|
fn mir<'a>(d: Droppable<'a>) {
|
2016-02-24 20:36:20 +02:00
|
|
|
let (mut a, mut b) = (false, false);
|
|
|
|
let y = Droppable(&mut a, 2);
|
|
|
|
let x = [Droppable(&mut b, 1), y, d, may_panic()];
|
2016-01-31 15:07:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2016-02-24 20:36:20 +02:00
|
|
|
let mut c = false;
|
|
|
|
mir(Droppable(&mut c, 3));
|
2016-01-31 15:07:18 +02:00
|
|
|
}
|