@@ -1819,6 +1819,27 @@ pub fn hash<T: ?Sized, S: hash::Hasher>(hashee: *const T, into: &mut S) {
1819
1819
hashee. hash ( into) ;
1820
1820
}
1821
1821
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
+
1822
1843
// FIXME(strict_provenance_magic): function pointers have buggy codegen that
1823
1844
// necessitates casting to a usize to get the backend to do the right thing.
1824
1845
// 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) {
1827
1848
// Impls for function pointers
1828
1849
macro_rules! fnptr_impls_safety_abi {
1829
1850
( $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
+ }
1835
1859
}
1836
1860
}
1837
1861
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
+ }
1840
1867
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
+ }
1846
1876
}
1847
1877
}
1848
1878
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
+ }
1854
1887
}
1855
1888
}
1856
1889
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
+ }
1861
1897
}
1862
1898
}
1863
1899
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
+ }
1868
1907
}
1869
1908
}
1870
1909
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
+ }
1875
1917
}
1876
1918
}
1877
1919
}
@@ -1896,7 +1938,7 @@ macro_rules! fnptr_impls_args {
1896
1938
}
1897
1939
1898
1940
fnptr_impls_args ! { }
1899
- fnptr_impls_args ! { A }
1941
+ fnptr_impls_args ! { T }
1900
1942
fnptr_impls_args ! { A , B }
1901
1943
fnptr_impls_args ! { A , B , C }
1902
1944
fnptr_impls_args ! { A , B , C , D }
0 commit comments