@@ -749,11 +749,42 @@ fn clean_fn_or_proc_macro(
749749 } else {
750750 hir:: Constness :: NotConst
751751 } ;
752+ clean_fn_decl_legacy_const_generics ( & mut func, attrs) ;
752753 FunctionItem ( func)
753754 }
754755 }
755756}
756757
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+
757788impl < ' a > Clean < Function > for ( & ' a hir:: FnSig < ' a > , & ' a hir:: Generics < ' a > , hir:: BodyId ) {
758789 fn clean ( & self , cx : & mut DocContext < ' _ > ) -> Function {
759790 let ( generics, decl) = enter_impl_trait ( cx, |cx| {
@@ -779,7 +810,7 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], &'a [Ident]) {
779810 if name. is_empty ( ) {
780811 name = kw:: Underscore ;
781812 }
782- Argument { name, type_ : ty. clean ( cx) }
813+ Argument { name, type_ : ty. clean ( cx) , is_const : false }
783814 } )
784815 . collect ( ) ,
785816 }
@@ -798,6 +829,7 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], hir::BodyId) {
798829 . map ( |( i, ty) | Argument {
799830 name : name_from_pat ( body. params [ i] . pat ) ,
800831 type_ : ty. clean ( cx) ,
832+ is_const : false ,
801833 } )
802834 . collect ( ) ,
803835 }
@@ -828,6 +860,7 @@ impl<'tcx> Clean<FnDecl> for (DefId, ty::PolyFnSig<'tcx>) {
828860 . map ( |t| Argument {
829861 type_ : t. clean ( cx) ,
830862 name : names. next ( ) . map_or ( kw:: Empty , |i| i. name ) ,
863+ is_const : false ,
831864 } )
832865 . collect ( ) ,
833866 } ,
0 commit comments