]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/issue-29948.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / test / run-pass / issue-29948.rs
CommitLineData
1a4d82fc 1// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
223e47cc
LB
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
abe05a73
XL
11// ignore-wasm32-bare compiled with panic=abort by default
12
cc61c64b
XL
13use std::panic;
14
15impl<'a> panic::UnwindSafe for Foo<'a> {}
16impl<'a> panic::RefUnwindSafe for Foo<'a> {}
17
7453a54e 18struct Foo<'a>(&'a mut bool);
223e47cc 19
7453a54e
SL
20impl<'a> Drop for Foo<'a> {
21 fn drop(&mut self) {
22 *self.0 = true;
23 }
24}
85aaf69f 25
7453a54e
SL
26fn f<T: FnOnce()>(t: T) {
27 t()
28}
85aaf69f 29
223e47cc 30fn main() {
7453a54e
SL
31 let mut ran_drop = false;
32 {
33 let x = Foo(&mut ran_drop);
34 let x = move || { let _ = x; };
35 f(x);
970d7e83 36 }
7453a54e 37 assert!(ran_drop);
7453a54e 38
cc61c64b
XL
39 let mut ran_drop = false;
40 {
41 let x = Foo(&mut ran_drop);
42 let result = panic::catch_unwind(move || {
43 let x = move || { let _ = x; panic!() };
44 f(x);
45 });
46 assert!(result.is_err());
47 }
48 assert!(ran_drop);
49}