File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use {
22 slice_dst:: * ,
33 std:: {
4- panic,
5- sync:: atomic:: { AtomicUsize , Ordering :: SeqCst } ,
4+ alloc:: Layout ,
5+ panic, ptr,
6+ rc:: Rc ,
7+ sync:: {
8+ atomic:: { AtomicUsize , Ordering :: SeqCst } ,
9+ Arc ,
10+ } ,
611 } ,
712} ;
813
@@ -66,3 +71,33 @@ fn bad_exactsizeiterator() {
6671 } ) ;
6772 assert_eq ! ( * counter. get_mut( ) , 0 ) ;
6873}
74+
75+ struct S ( u8 ) ;
76+
77+ unsafe impl SliceDst for S {
78+ fn layout_for ( _: usize ) -> Layout {
79+ Layout :: new :: < S > ( )
80+ }
81+
82+ fn retype ( ptr : ptr:: NonNull < [ ( ) ] > ) -> ptr:: NonNull < Self > {
83+ ptr. cast ( )
84+ }
85+ }
86+
87+ #[ test]
88+ #[ cfg_attr(
89+ all( miri, target_os = "windows" ) ,
90+ ignore = "miri does not support panicking on windows rust-lang/miri#1059"
91+ ) ]
92+ fn panic_in_init ( ) {
93+ // This relies on miri to catch leaks
94+ let _ = std:: panic:: catch_unwind ( || {
95+ let _: Box < S > = unsafe { AllocSliceDst :: new_slice_dst ( 0 , |_| panic ! ( ) ) } ;
96+ } ) ;
97+ let _ = std:: panic:: catch_unwind ( || {
98+ let _: Arc < S > = unsafe { AllocSliceDst :: new_slice_dst ( 0 , |_| panic ! ( ) ) } ;
99+ } ) ;
100+ let _ = std:: panic:: catch_unwind ( || {
101+ let _: Rc < S > = unsafe { AllocSliceDst :: new_slice_dst ( 0 , |_| panic ! ( ) ) } ;
102+ } ) ;
103+ }
You can’t perform that action at this time.
0 commit comments