@@ -1819,6 +1819,27 @@ pub fn hash<T: ?Sized, S: hash::Hasher>(hashee: *const T, into: &mut S) {
18191819 hashee. hash ( into) ;
18201820}
18211821
1822+ // If this is a unary fn pointer, it adds a doc comment.
1823+ // Otherwise, it hides the docs entirely.
1824+ macro_rules! maybe_fnptr_doc {
1825+ ( @ #[ $meta: meta] $item: item) => {
1826+ #[ doc( hidden) ]
1827+ #[ $meta]
1828+ $item
1829+ } ;
1830+ ( $a: ident @ #[ $meta: meta] $item: item) => {
1831+ #[ cfg_attr( not( bootstrap) , doc( fake_variadic) ) ]
1832+ #[ doc = "This trait is implemented for function pointers with up to twelve arguments." ]
1833+ #[ $meta]
1834+ $item
1835+ } ;
1836+ ( $a: ident $( $rest_a: ident) + @ #[ $meta: meta] $item: item) => {
1837+ #[ doc( hidden) ]
1838+ #[ $meta]
1839+ $item
1840+ } ;
1841+ }
1842+
18221843// FIXME(strict_provenance_magic): function pointers have buggy codegen that
18231844// necessitates casting to a usize to get the backend to do the right thing.
18241845// for now I will break AVR to silence *a billion* lints. We should probably
@@ -1827,51 +1848,72 @@ pub fn hash<T: ?Sized, S: hash::Hasher>(hashee: *const T, into: &mut S) {
18271848// Impls for function pointers
18281849macro_rules! fnptr_impls_safety_abi {
18291850 ( $FnTy: ty, $( $Arg: ident) ,* ) => {
1830- #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1831- impl <Ret , $( $Arg) ,* > PartialEq for $FnTy {
1832- #[ inline]
1833- fn eq( & self , other: & Self ) -> bool {
1834- * self as usize == * other as usize
1851+ maybe_fnptr_doc! {
1852+ $( $Arg) * @
1853+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1854+ impl <Ret , $( $Arg) ,* > PartialEq for $FnTy {
1855+ #[ inline]
1856+ fn eq( & self , other: & Self ) -> bool {
1857+ * self as usize == * other as usize
1858+ }
18351859 }
18361860 }
18371861
1838- #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1839- impl <Ret , $( $Arg) ,* > Eq for $FnTy { }
1862+ maybe_fnptr_doc! {
1863+ $( $Arg) * @
1864+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1865+ impl <Ret , $( $Arg) ,* > Eq for $FnTy { }
1866+ }
18401867
1841- #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1842- impl <Ret , $( $Arg) ,* > PartialOrd for $FnTy {
1843- #[ inline]
1844- fn partial_cmp( & self , other: & Self ) -> Option <Ordering > {
1845- ( * self as usize ) . partial_cmp( & ( * other as usize ) )
1868+ maybe_fnptr_doc! {
1869+ $( $Arg) * @
1870+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1871+ impl <Ret , $( $Arg) ,* > PartialOrd for $FnTy {
1872+ #[ inline]
1873+ fn partial_cmp( & self , other: & Self ) -> Option <Ordering > {
1874+ ( * self as usize ) . partial_cmp( & ( * other as usize ) )
1875+ }
18461876 }
18471877 }
18481878
1849- #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1850- impl <Ret , $( $Arg) ,* > Ord for $FnTy {
1851- #[ inline]
1852- fn cmp( & self , other: & Self ) -> Ordering {
1853- ( * self as usize ) . cmp( & ( * other as usize ) )
1879+ maybe_fnptr_doc! {
1880+ $( $Arg) * @
1881+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1882+ impl <Ret , $( $Arg) ,* > Ord for $FnTy {
1883+ #[ inline]
1884+ fn cmp( & self , other: & Self ) -> Ordering {
1885+ ( * self as usize ) . cmp( & ( * other as usize ) )
1886+ }
18541887 }
18551888 }
18561889
1857- #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1858- impl <Ret , $( $Arg) ,* > hash:: Hash for $FnTy {
1859- fn hash<HH : hash:: Hasher >( & self , state: & mut HH ) {
1860- state. write_usize( * self as usize )
1890+ maybe_fnptr_doc! {
1891+ $( $Arg) * @
1892+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1893+ impl <Ret , $( $Arg) ,* > hash:: Hash for $FnTy {
1894+ fn hash<HH : hash:: Hasher >( & self , state: & mut HH ) {
1895+ state. write_usize( * self as usize )
1896+ }
18611897 }
18621898 }
18631899
1864- #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1865- impl <Ret , $( $Arg) ,* > fmt:: Pointer for $FnTy {
1866- fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
1867- fmt:: pointer_fmt_inner( * self as usize , f)
1900+ maybe_fnptr_doc! {
1901+ $( $Arg) * @
1902+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1903+ impl <Ret , $( $Arg) ,* > fmt:: Pointer for $FnTy {
1904+ fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
1905+ fmt:: pointer_fmt_inner( * self as usize , f)
1906+ }
18681907 }
18691908 }
18701909
1871- #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1872- impl <Ret , $( $Arg) ,* > fmt:: Debug for $FnTy {
1873- fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
1874- fmt:: pointer_fmt_inner( * self as usize , f)
1910+ maybe_fnptr_doc! {
1911+ $( $Arg) * @
1912+ #[ stable( feature = "fnptr_impls" , since = "1.4.0" ) ]
1913+ impl <Ret , $( $Arg) ,* > fmt:: Debug for $FnTy {
1914+ fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
1915+ fmt:: pointer_fmt_inner( * self as usize , f)
1916+ }
18751917 }
18761918 }
18771919 }
0 commit comments