blob: 39e2e4537b17f535da80d5ced72c23c4fc492e7c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Test that `#[const_continue]` correctly emits cleanup paths for drops.
//
// Here, we first drop `DropBomb`, causing an unwind. Then `ExitOnDrop` should
// be dropped, causing us to exit with `0` rather than with some non-zero value
// due to the panic, which is what causes the test to pass.
//@ run-pass
//@ needs-unwind
#![allow(incomplete_features)]
#![feature(loop_match)]
enum State {
A,
B,
}
struct ExitOnDrop;
impl Drop for ExitOnDrop {
fn drop(&mut self) {
std::process::exit(0);
}
}
struct DropBomb;
impl Drop for DropBomb {
fn drop(&mut self) {
panic!("this must unwind");
}
}
fn main() {
let mut state = State::A;
#[loop_match]
'a: loop {
state = 'blk: {
match state {
State::A => {
let _exit = ExitOnDrop;
let _bomb = DropBomb;
#[const_continue]
break 'blk State::B;
}
State::B => break 'a,
}
};
}
unreachable!();
}
|