@@ -1915,12 +1915,13 @@ safety_comment! {
1915
1915
/// size_of::<T>()])` is sound and produces `Option::<T>::None`. These
1916
1916
/// cases are identified by the second column:
1917
1917
///
1918
- /// | `T` | `transmute::<_, Option<T>>([0u8; size_of::<T>()])` sound? |
1919
- /// |---------------------|-----------------------------------------------------------|
1920
- /// | [`Box<U>`] | when `U: Sized` |
1921
- /// | `&U` | when `U: Sized` |
1922
- /// | `&mut U` | when `U: Sized` |
1923
- /// | [`ptr::NonNull<U>`] | when `U: Sized` |
1918
+ /// | `T` | `transmute::<_, Option<T>>([0u8; size_of::<T>()])` sound? |
1919
+ /// |-----------------------|-----------------------------------------------------------|
1920
+ /// | [`Box<U>`] | when `U: Sized` |
1921
+ /// | `&U` | when `U: Sized` |
1922
+ /// | `&mut U` | when `U: Sized` |
1923
+ /// | [`ptr::NonNull<U>`] | when `U: Sized` |
1924
+ /// | `fn`, `extern "C" fn` | always |
1924
1925
///
1925
1926
/// TODO(#429), TODO(https://github.com/rust-lang/rust/pull/115333): Cite
1926
1927
/// the Stable docs once they're available.
@@ -1929,6 +1930,8 @@ safety_comment! {
1929
1930
unsafe_impl!( T => FromZeroes for Option <& ' _ T >) ;
1930
1931
unsafe_impl!( T => FromZeroes for Option <& ' _ mut T >) ;
1931
1932
unsafe_impl!( T => FromZeroes for Option <NonNull <T >>) ;
1933
+ unsafe_impl_for_power_set!( A , B , C , D , E , F , G , H , I , J , K , L -> M => FromZeroes for opt_fn!( ...) ) ;
1934
+ unsafe_impl_for_power_set!( A , B , C , D , E , F , G , H , I , J , K , L -> M => FromZeroes for opt_extern_c_fn!( ...) ) ;
1932
1935
}
1933
1936
1934
1937
safety_comment ! {
@@ -5575,6 +5578,18 @@ mod tests {
5575
5578
// Implements none of the ZC traits.
5576
5579
struct NotZerocopy ;
5577
5580
5581
+ #[ rustfmt:: skip]
5582
+ type FnManyArgs = fn (
5583
+ NotZerocopy , u8 , u8 , u8 , u8 , u8 , u8 , u8 , u8 , u8 , u8 , u8 ,
5584
+ ) -> ( NotZerocopy , NotZerocopy ) ;
5585
+
5586
+ // Allowed, because we're not actually using this type for FFI.
5587
+ #[ allow( improper_ctypes_definitions) ]
5588
+ #[ rustfmt:: skip]
5589
+ type ECFnManyArgs = extern "C" fn (
5590
+ NotZerocopy , u8 , u8 , u8 , u8 , u8 , u8 , u8 , u8 , u8 , u8 , u8 ,
5591
+ ) -> ( NotZerocopy , NotZerocopy ) ;
5592
+
5578
5593
#[ cfg( feature = "alloc" ) ]
5579
5594
assert_impls ! ( Option <Box <UnsafeCell <NotZerocopy >>>: KnownLayout , FromZeroes , !FromBytes , !AsBytes , !Unaligned ) ;
5580
5595
assert_impls ! ( Option <Box <[ UnsafeCell <NotZerocopy >] >>: KnownLayout , !FromZeroes , !FromBytes , !AsBytes , !Unaligned ) ;
@@ -5584,6 +5599,10 @@ mod tests {
5584
5599
assert_impls ! ( Option <& ' static mut [ UnsafeCell <NotZerocopy >] >: KnownLayout , !FromZeroes , !FromBytes , !AsBytes , !Unaligned ) ;
5585
5600
assert_impls ! ( Option <NonNull <UnsafeCell <NotZerocopy >>>: KnownLayout , FromZeroes , !FromBytes , !AsBytes , !Unaligned ) ;
5586
5601
assert_impls ! ( Option <NonNull <[ UnsafeCell <NotZerocopy >] >>: KnownLayout , !FromZeroes , !FromBytes , !AsBytes , !Unaligned ) ;
5602
+ assert_impls ! ( Option <fn ( ) >: KnownLayout , FromZeroes , !FromBytes , !AsBytes , !Unaligned ) ;
5603
+ assert_impls ! ( Option <FnManyArgs >: KnownLayout , FromZeroes , !FromBytes , !AsBytes , !Unaligned ) ;
5604
+ assert_impls ! ( Option <extern "C" fn ( ) >: KnownLayout , FromZeroes , !FromBytes , !AsBytes , !Unaligned ) ;
5605
+ assert_impls ! ( Option <ECFnManyArgs >: KnownLayout , FromZeroes , !FromBytes , !AsBytes , !Unaligned ) ;
5587
5606
5588
5607
assert_impls ! ( PhantomData <NotZerocopy >: KnownLayout , FromZeroes , FromBytes , AsBytes , Unaligned ) ;
5589
5608
assert_impls ! ( PhantomData <[ u8 ] >: KnownLayout , FromZeroes , FromBytes , AsBytes , Unaligned ) ;
0 commit comments