rust/tests/ui/mir/mir_dynamic_drops_1.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
656 B
Rust
Raw Normal View History

2020-04-16 06:50:32 +00:00
//@ run-fail
2016-01-31 13:07:18 +00:00
//@ error-pattern:drop 1
//@ error-pattern:drop 2
2020-05-07 15:39:02 +00:00
//@ ignore-emscripten no processes
2016-01-31 13:07:18 +00:00
/// Structure which will not allow to be dropped twice.
2016-02-24 18:36:20 +00:00
struct Droppable<'a>(&'a mut bool, u32);
impl<'a> Drop for Droppable<'a> {
2016-01-31 13:07:18 +00:00
fn drop(&mut self) {
2016-02-24 18:36:20 +00:00
if *self.0 {
eprintln!("{} dropped twice", self.1);
2016-01-31 13:07:18 +00:00
::std::process::exit(1);
}
eprintln!("drop {}", self.1);
2016-02-24 18:36:20 +00:00
*self.0 = true;
2016-01-31 13:07:18 +00:00
}
}
2016-05-27 02:39:36 +00:00
fn mir() {
2016-02-24 18:36:20 +00:00
let (mut xv, mut yv) = (false, false);
let x = Droppable(&mut xv, 1);
let y = Droppable(&mut yv, 2);
2016-01-31 13:07:18 +00:00
let mut z = x;
let k = y;
z = k;
}
fn main() {
mir();
panic!();
}