blob: 731af6590129a11202792022abbfffcefea9577b (
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
|
// Test that dropping values works in match arms, which is nontrivial
// because each match arm needs its own scope.
//@ run-pass
#![allow(incomplete_features)]
#![feature(loop_match)]
use std::sync::atomic::{AtomicBool, Ordering};
fn main() {
assert_eq!(helper(), 1);
assert!(DROPPED.load(Ordering::Relaxed));
}
static DROPPED: AtomicBool = AtomicBool::new(false);
struct X;
impl Drop for X {
fn drop(&mut self) {
DROPPED.store(true, Ordering::Relaxed);
}
}
#[no_mangle]
#[inline(never)]
fn helper() -> i32 {
let mut state = 0;
#[loop_match]
'a: loop {
state = 'blk: {
match state {
0 => match X {
_ => {
assert!(!DROPPED.load(Ordering::Relaxed));
break 'blk 1;
}
},
_ => {
assert!(DROPPED.load(Ordering::Relaxed));
break 'a state;
}
}
};
}
}
|