File tree 1 file changed +37
-2
lines changed
1 file changed +37
-2
lines changed Original file line number Diff line number Diff line change 1
1
use {
2
2
slice_dst:: * ,
3
3
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
+ } ,
6
11
} ,
7
12
} ;
8
13
@@ -66,3 +71,33 @@ fn bad_exactsizeiterator() {
66
71
} ) ;
67
72
assert_eq ! ( * counter. get_mut( ) , 0 ) ;
68
73
}
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