File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments