@@ -754,13 +754,15 @@ pub unsafe trait FromZeroes {
754
754
return Box :: new ( Self :: new_zeroed ( ) ) ;
755
755
}
756
756
757
- // TODO(#61): Add a "SAFETY" comment and remove this `allow`.
757
+ // TODO(#429): Add a "SAFETY" comment and remove this `allow`.
758
+ #[ allow( clippy:: undocumented_unsafe_blocks) ]
759
+ let ptr = unsafe { alloc:: alloc:: alloc_zeroed ( layout) . cast :: < Self > ( ) } ;
760
+ if ptr. is_null ( ) {
761
+ alloc:: alloc:: handle_alloc_error ( layout) ;
762
+ }
763
+ // TODO(#429): Add a "SAFETY" comment and remove this `allow`.
758
764
#[ allow( clippy:: undocumented_unsafe_blocks) ]
759
765
unsafe {
760
- let ptr = alloc:: alloc:: alloc_zeroed ( layout) . cast :: < Self > ( ) ;
761
- if ptr. is_null ( ) {
762
- alloc:: alloc:: handle_alloc_error ( layout) ;
763
- }
764
766
Box :: from_raw ( ptr)
765
767
}
766
768
}
@@ -810,21 +812,25 @@ pub unsafe trait FromZeroes {
810
812
let layout =
811
813
Layout :: from_size_align ( size, align) . expect ( "total allocation size overflows `isize`" ) ;
812
814
813
- // TODO(#61): Add a "SAFETY" comment and remove this `allow`.
815
+ let ptr = if layout. size ( ) != 0 {
816
+ // TODO(#429): Add a "SAFETY" comment and remove this `allow`.
817
+ #[ allow( clippy:: undocumented_unsafe_blocks) ]
818
+ let ptr = unsafe { alloc:: alloc:: alloc_zeroed ( layout) . cast :: < Self > ( ) } ;
819
+ if ptr. is_null ( ) {
820
+ alloc:: alloc:: handle_alloc_error ( layout) ;
821
+ }
822
+ ptr
823
+ } else {
824
+ // `Box<[T]>` does not allocate when `T` is zero-sized or when `len`
825
+ // is zero, but it does require a non-null dangling pointer for its
826
+ // allocation.
827
+ NonNull :: < Self > :: dangling ( ) . as_ptr ( )
828
+ } ;
829
+
830
+ // TODO(#429): Add a "SAFETY" comment and remove this `allow`.
814
831
#[ allow( clippy:: undocumented_unsafe_blocks) ]
815
832
unsafe {
816
- if layout. size ( ) != 0 {
817
- let ptr = alloc:: alloc:: alloc_zeroed ( layout) . cast :: < Self > ( ) ;
818
- if ptr. is_null ( ) {
819
- alloc:: alloc:: handle_alloc_error ( layout) ;
820
- }
821
- Box :: from_raw ( slice:: from_raw_parts_mut ( ptr, len) )
822
- } else {
823
- // `Box<[T]>` does not allocate when `T` is zero-sized or when
824
- // `len` is zero, but it does require a non-null dangling
825
- // pointer for its allocation.
826
- Box :: from_raw ( slice:: from_raw_parts_mut ( NonNull :: < Self > :: dangling ( ) . as_ptr ( ) , len) )
827
- }
833
+ Box :: from_raw ( slice:: from_raw_parts_mut ( ptr, len) )
828
834
}
829
835
}
830
836
@@ -2328,7 +2334,7 @@ where
2328
2334
/// and no mutable references to the same memory may be constructed during
2329
2335
/// `'a`.
2330
2336
unsafe fn deref_helper < ' a > ( & self ) -> & ' a T {
2331
- // TODO(#61 ): Add a "SAFETY" comment and remove this `allow`.
2337
+ // TODO(#429 ): Add a "SAFETY" comment and remove this `allow`.
2332
2338
#[ allow( clippy:: undocumented_unsafe_blocks) ]
2333
2339
unsafe {
2334
2340
& * self . 0 . as_ptr ( ) . cast :: < T > ( )
@@ -2353,7 +2359,7 @@ where
2353
2359
/// and no other references - mutable or immutable - to the same memory may
2354
2360
/// be constructed during `'a`.
2355
2361
unsafe fn deref_mut_helper < ' a > ( & mut self ) -> & ' a mut T {
2356
- // TODO(#61 ): Add a "SAFETY" comment and remove this `allow`.
2362
+ // TODO(#429 ): Add a "SAFETY" comment and remove this `allow`.
2357
2363
#[ allow( clippy:: undocumented_unsafe_blocks) ]
2358
2364
unsafe {
2359
2365
& mut * self . 0 . as_mut_ptr ( ) . cast :: < T > ( )
@@ -2382,7 +2388,7 @@ where
2382
2388
debug_assert_eq ! ( len % elem_size, 0 ) ;
2383
2389
len / elem_size
2384
2390
} ;
2385
- // TODO(#61 ): Add a "SAFETY" comment and remove this `allow`.
2391
+ // TODO(#429 ): Add a "SAFETY" comment and remove this `allow`.
2386
2392
#[ allow( clippy:: undocumented_unsafe_blocks) ]
2387
2393
unsafe {
2388
2394
slice:: from_raw_parts ( self . 0 . as_ptr ( ) . cast :: < T > ( ) , elems)
@@ -2412,7 +2418,7 @@ where
2412
2418
debug_assert_eq ! ( len % elem_size, 0 ) ;
2413
2419
len / elem_size
2414
2420
} ;
2415
- // TODO(#61 ): Add a "SAFETY" comment and remove this `allow`.
2421
+ // TODO(#429 ): Add a "SAFETY" comment and remove this `allow`.
2416
2422
#[ allow( clippy:: undocumented_unsafe_blocks) ]
2417
2423
unsafe {
2418
2424
slice:: from_raw_parts_mut ( self . 0 . as_mut_ptr ( ) . cast :: < T > ( ) , elems)
@@ -2754,7 +2760,7 @@ pub unsafe trait ByteSliceMut: ByteSlice + DerefMut {
2754
2760
}
2755
2761
2756
2762
impl < ' a > sealed:: ByteSliceSealed for & ' a [ u8 ] { }
2757
- // TODO(#61 ): Add a "SAFETY" comment and remove this `allow`.
2763
+ // TODO(#429 ): Add a "SAFETY" comment and remove this `allow`.
2758
2764
#[ allow( clippy:: undocumented_unsafe_blocks) ]
2759
2765
unsafe impl < ' a > ByteSlice for & ' a [ u8 ] {
2760
2766
#[ inline]
@@ -2764,7 +2770,7 @@ unsafe impl<'a> ByteSlice for &'a [u8] {
2764
2770
}
2765
2771
2766
2772
impl < ' a > sealed:: ByteSliceSealed for & ' a mut [ u8 ] { }
2767
- // TODO(#61 ): Add a "SAFETY" comment and remove this `allow`.
2773
+ // TODO(#429 ): Add a "SAFETY" comment and remove this `allow`.
2768
2774
#[ allow( clippy:: undocumented_unsafe_blocks) ]
2769
2775
unsafe impl < ' a > ByteSlice for & ' a mut [ u8 ] {
2770
2776
#[ inline]
@@ -2774,7 +2780,7 @@ unsafe impl<'a> ByteSlice for &'a mut [u8] {
2774
2780
}
2775
2781
2776
2782
impl < ' a > sealed:: ByteSliceSealed for cell:: Ref < ' a , [ u8 ] > { }
2777
- // TODO(#61 ): Add a "SAFETY" comment and remove this `allow`.
2783
+ // TODO(#429 ): Add a "SAFETY" comment and remove this `allow`.
2778
2784
#[ allow( clippy:: undocumented_unsafe_blocks) ]
2779
2785
unsafe impl < ' a > ByteSlice for cell:: Ref < ' a , [ u8 ] > {
2780
2786
#[ inline]
@@ -2784,7 +2790,7 @@ unsafe impl<'a> ByteSlice for cell::Ref<'a, [u8]> {
2784
2790
}
2785
2791
2786
2792
impl < ' a > sealed:: ByteSliceSealed for RefMut < ' a , [ u8 ] > { }
2787
- // TODO(#61 ): Add a "SAFETY" comment and remove this `allow`.
2793
+ // TODO(#429 ): Add a "SAFETY" comment and remove this `allow`.
2788
2794
#[ allow( clippy:: undocumented_unsafe_blocks) ]
2789
2795
unsafe impl < ' a > ByteSlice for RefMut < ' a , [ u8 ] > {
2790
2796
#[ inline]
@@ -2793,11 +2799,11 @@ unsafe impl<'a> ByteSlice for RefMut<'a, [u8]> {
2793
2799
}
2794
2800
}
2795
2801
2796
- // TODO(#61 ): Add a "SAFETY" comment and remove this `allow`.
2802
+ // TODO(#429 ): Add a "SAFETY" comment and remove this `allow`.
2797
2803
#[ allow( clippy:: undocumented_unsafe_blocks) ]
2798
2804
unsafe impl < ' a > ByteSliceMut for & ' a mut [ u8 ] { }
2799
2805
2800
- // TODO(#61 ): Add a "SAFETY" comment and remove this `allow`.
2806
+ // TODO(#429 ): Add a "SAFETY" comment and remove this `allow`.
2801
2807
#[ allow( clippy:: undocumented_unsafe_blocks) ]
2802
2808
unsafe impl < ' a > ByteSliceMut for RefMut < ' a , [ u8 ] > { }
2803
2809
0 commit comments