Skip to content

Commit d54d398

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#36140 - cristicbz:test-14875, r=nagisa
Add test for rust-lang#14875 You can check this out in the playground https://is.gd/oVKC2T . It will fail on stable, but pass on nightly as @nagisa suggested on the issue. Fixes rust-lang#14875
2 parents 5eb53d9 + 34e1817 commit d54d398

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/test/run-pass/issue-14875.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
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+
11+
// Check that values are not leaked when a dtor panics (#14875)
12+
13+
use std::panic::{self, UnwindSafe};
14+
15+
struct SetInnerOnDrop<'a>(&'a mut bool);
16+
17+
impl<'a> UnwindSafe for SetInnerOnDrop<'a> {}
18+
19+
impl<'a> Drop for SetInnerOnDrop<'a> {
20+
fn drop(&mut self) {
21+
*self.0 = true;
22+
}
23+
}
24+
25+
struct PanicOnDrop;
26+
impl Drop for PanicOnDrop {
27+
fn drop(&mut self) {
28+
panic!("test panic");
29+
}
30+
}
31+
32+
33+
fn main() {
34+
let mut set_on_drop = false;
35+
{
36+
let set_inner_on_drop = SetInnerOnDrop(&mut set_on_drop);
37+
let _ = panic::catch_unwind(|| {
38+
let _set_inner_on_drop = set_inner_on_drop;
39+
let _panic_on_drop = PanicOnDrop;
40+
});
41+
}
42+
assert!(set_on_drop);
43+
}

0 commit comments

Comments
 (0)