File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use crate::void;
44use core:: cell:: UnsafeCell ;
55use core:: marker:: { PhantomData , PhantomPinned } ;
66use core:: mem;
7+ use core:: panic:: RefUnwindSafe ;
78
89// . size = 0
910// . align = 1
@@ -12,13 +13,16 @@ use core::mem;
1213// . !Sync
1314// . !Unpin
1415// . not readonly
16+ // . unwind-safe
1517#[ repr( C , packed) ]
1618pub struct Opaque {
1719 _private : [ * const void ; 0 ] ,
1820 _pinned : PhantomData < PhantomPinned > ,
1921 _mutable : SyncUnsafeCell < PhantomData < ( ) > > ,
2022}
2123
24+ impl RefUnwindSafe for Opaque { }
25+
2226// TODO: https://github.com/rust-lang/rust/issues/95439
2327#[ repr( transparent) ]
2428struct SyncUnsafeCell < T > ( UnsafeCell < T > ) ;
Original file line number Diff line number Diff line change 1111 clippy:: unseparated_literal_suffix
1212) ]
1313
14- use cxx:: SharedPtr ;
14+ use cxx:: { SharedPtr , UniquePtr } ;
1515use cxx_test_suite:: module:: ffi2;
1616use cxx_test_suite:: { cast, ffi, R } ;
1717use std:: cell:: Cell ;
1818use std:: ffi:: CStr ;
19+ use std:: panic:: { self , RefUnwindSafe , UnwindSafe } ;
1920
2021thread_local ! {
2122 static CORRECT : Cell <bool > = const { Cell :: new( false ) } ;
@@ -380,3 +381,17 @@ fn test_raw_ptr() {
380381 assert_eq ! ( 2025 , unsafe { ffi:: c_take_const_ptr( c3) } ) ;
381382 assert_eq ! ( 2025 , unsafe { ffi:: c_take_mut_ptr( c3 as * mut ffi:: C ) } ) ; // deletes c3
382383}
384+
385+ #[ test]
386+ #[ allow( clippy:: items_after_statements, clippy:: no_effect_underscore_binding) ]
387+ fn test_unwind_safe ( ) {
388+ fn inspect ( _c : & ffi:: C ) { }
389+ let _unwind_safe = |c : UniquePtr < ffi:: C > | panic:: catch_unwind ( || drop ( c) ) ;
390+ let _ref_unwind_safe = |c : & ffi:: C | panic:: catch_unwind ( || inspect ( c) ) ;
391+
392+ fn require_unwind_safe < T : UnwindSafe > ( ) { }
393+ require_unwind_safe :: < ffi:: C > ( ) ;
394+
395+ fn require_ref_unwind_safe < T : RefUnwindSafe > ( ) { }
396+ require_ref_unwind_safe :: < ffi:: C > ( ) ;
397+ }
You can’t perform that action at this time.
0 commit comments