@@ -749,11 +749,42 @@ fn clean_fn_or_proc_macro(
749
749
} else {
750
750
hir:: Constness :: NotConst
751
751
} ;
752
+ clean_fn_decl_legacy_const_generics ( & mut func, attrs) ;
752
753
FunctionItem ( func)
753
754
}
754
755
}
755
756
}
756
757
758
+ /// This is needed to make it more "readable" when documenting functions using
759
+ /// `rustc_legacy_const_generics`. More information in
760
+ /// <https://github.com/rust-lang/rust/issues/83167>.
761
+ fn clean_fn_decl_legacy_const_generics ( func : & mut Function , attrs : & [ ast:: Attribute ] ) {
762
+ for meta_item_list in attrs
763
+ . iter ( )
764
+ . filter ( |a| a. has_name ( sym:: rustc_legacy_const_generics) )
765
+ . filter_map ( |a| a. meta_item_list ( ) )
766
+ {
767
+ for ( pos, literal) in meta_item_list. iter ( ) . filter_map ( |meta| meta. literal ( ) ) . enumerate ( ) {
768
+ match literal. kind {
769
+ ast:: LitKind :: Int ( a, _) => {
770
+ let gen = func. generics . params . remove ( 0 ) ;
771
+ if let GenericParamDef { name, kind : GenericParamDefKind :: Const { ty, .. } } =
772
+ gen
773
+ {
774
+ func. decl
775
+ . inputs
776
+ . values
777
+ . insert ( a as _ , Argument { name, type_ : * ty, is_const : true } ) ;
778
+ } else {
779
+ panic ! ( "unexpected non const in position {}" , pos) ;
780
+ }
781
+ }
782
+ _ => panic ! ( "invalid arg index" ) ,
783
+ }
784
+ }
785
+ }
786
+ }
787
+
757
788
impl < ' a > Clean < Function > for ( & ' a hir:: FnSig < ' a > , & ' a hir:: Generics < ' a > , hir:: BodyId ) {
758
789
fn clean ( & self , cx : & mut DocContext < ' _ > ) -> Function {
759
790
let ( generics, decl) = enter_impl_trait ( cx, |cx| {
@@ -779,7 +810,7 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], &'a [Ident]) {
779
810
if name. is_empty ( ) {
780
811
name = kw:: Underscore ;
781
812
}
782
- Argument { name, type_ : ty. clean ( cx) }
813
+ Argument { name, type_ : ty. clean ( cx) , is_const : false }
783
814
} )
784
815
. collect ( ) ,
785
816
}
@@ -798,6 +829,7 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], hir::BodyId) {
798
829
. map ( |( i, ty) | Argument {
799
830
name : name_from_pat ( body. params [ i] . pat ) ,
800
831
type_ : ty. clean ( cx) ,
832
+ is_const : false ,
801
833
} )
802
834
. collect ( ) ,
803
835
}
@@ -828,6 +860,7 @@ impl<'tcx> Clean<FnDecl> for (DefId, ty::PolyFnSig<'tcx>) {
828
860
. map ( |t| Argument {
829
861
type_ : t. clean ( cx) ,
830
862
name : names. next ( ) . map_or ( kw:: Empty , |i| i. name ) ,
863
+ is_const : false ,
831
864
} )
832
865
. collect ( ) ,
833
866
} ,
0 commit comments