@@ -1046,7 +1046,7 @@ fn clean_fn_or_proc_macro<'tcx>(
10461046 match macro_kind {
10471047 Some ( kind) => clean_proc_macro ( item, name, kind, cx) ,
10481048 None => {
1049- let mut func = clean_function ( cx, sig, generics, FunctionArgs :: Body ( body_id) ) ;
1049+ let mut func = clean_function ( cx, sig, generics, ParamsSrc :: Body ( body_id) ) ;
10501050 clean_fn_decl_legacy_const_generics ( & mut func, attrs) ;
10511051 FunctionItem ( func)
10521052 }
@@ -1074,8 +1074,7 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
10741074 {
10751075 func. decl
10761076 . inputs
1077- . values
1078- . insert ( a. get ( ) as _ , Argument { name, type_ : * ty, is_const : true } ) ;
1077+ . insert ( a. get ( ) as _ , Parameter { name, type_ : * ty, is_const : true } ) ;
10791078 } else {
10801079 panic ! ( "unexpected non const in position {pos}" ) ;
10811080 }
@@ -1086,7 +1085,7 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
10861085 }
10871086}
10881087
1089- enum FunctionArgs < ' tcx > {
1088+ enum ParamsSrc < ' tcx > {
10901089 Body ( hir:: BodyId ) ,
10911090 Idents ( & ' tcx [ Option < Ident > ] ) ,
10921091}
@@ -1095,30 +1094,26 @@ fn clean_function<'tcx>(
10951094 cx : & mut DocContext < ' tcx > ,
10961095 sig : & hir:: FnSig < ' tcx > ,
10971096 generics : & hir:: Generics < ' tcx > ,
1098- args : FunctionArgs < ' tcx > ,
1097+ params : ParamsSrc < ' tcx > ,
10991098) -> Box < Function > {
11001099 let ( generics, decl) = enter_impl_trait ( cx, |cx| {
1101- // NOTE: generics must be cleaned before args
1100+ // NOTE: Generics must be cleaned before params.
11021101 let generics = clean_generics ( generics, cx) ;
1103- let args = match args {
1104- FunctionArgs :: Body ( body_id) => {
1105- clean_args_from_types_and_body_id ( cx, sig. decl . inputs , body_id)
1106- }
1107- FunctionArgs :: Idents ( idents) => {
1108- clean_args_from_types_and_names ( cx, sig. decl . inputs , idents)
1109- }
1102+ let params = match params {
1103+ ParamsSrc :: Body ( body_id) => clean_params_via_body ( cx, sig. decl . inputs , body_id) ,
1104+ ParamsSrc :: Idents ( idents) => clean_params ( cx, sig. decl . inputs , idents) ,
11101105 } ;
1111- let decl = clean_fn_decl_with_args ( cx, sig. decl , Some ( & sig. header ) , args ) ;
1106+ let decl = clean_fn_decl_with_params ( cx, sig. decl , Some ( & sig. header ) , params ) ;
11121107 ( generics, decl)
11131108 } ) ;
11141109 Box :: new ( Function { decl, generics } )
11151110}
11161111
1117- fn clean_args_from_types_and_names < ' tcx > (
1112+ fn clean_params < ' tcx > (
11181113 cx : & mut DocContext < ' tcx > ,
11191114 types : & [ hir:: Ty < ' tcx > ] ,
11201115 idents : & [ Option < Ident > ] ,
1121- ) -> Arguments {
1116+ ) -> Vec < Parameter > {
11221117 fn nonempty_name ( ident : & Option < Ident > ) -> Option < Symbol > {
11231118 if let Some ( ident) = ident
11241119 && ident. name != kw:: Underscore
@@ -1134,47 +1129,41 @@ fn clean_args_from_types_and_names<'tcx>(
11341129 let default_name = if idents. iter ( ) . any ( |ident| nonempty_name ( ident) . is_some ( ) ) {
11351130 kw:: Underscore
11361131 } else {
1137- kw:: Empty
1132+ kw:: Empty // FIXME: using kw::Empty is a bit of a hack
11381133 } ;
11391134
1140- Arguments {
1141- values : types
1142- . iter ( )
1143- . enumerate ( )
1144- . map ( |( i, ty) | Argument {
1145- type_ : clean_ty ( ty, cx) ,
1146- name : idents. get ( i) . and_then ( nonempty_name) . unwrap_or ( default_name) ,
1147- is_const : false ,
1148- } )
1149- . collect ( ) ,
1150- }
1135+ types
1136+ . iter ( )
1137+ . enumerate ( )
1138+ . map ( |( i, ty) | Parameter {
1139+ name : idents. get ( i) . and_then ( nonempty_name) . unwrap_or ( default_name) ,
1140+ type_ : clean_ty ( ty, cx) ,
1141+ is_const : false ,
1142+ } )
1143+ . collect ( )
11511144}
11521145
1153- fn clean_args_from_types_and_body_id < ' tcx > (
1146+ fn clean_params_via_body < ' tcx > (
11541147 cx : & mut DocContext < ' tcx > ,
11551148 types : & [ hir:: Ty < ' tcx > ] ,
11561149 body_id : hir:: BodyId ,
1157- ) -> Arguments {
1158- let body = cx. tcx . hir_body ( body_id) ;
1159-
1160- Arguments {
1161- values : types
1162- . iter ( )
1163- . zip ( body. params )
1164- . map ( |( ty, param) | Argument {
1165- name : name_from_pat ( param. pat ) ,
1166- type_ : clean_ty ( ty, cx) ,
1167- is_const : false ,
1168- } )
1169- . collect ( ) ,
1170- }
1150+ ) -> Vec < Parameter > {
1151+ types
1152+ . iter ( )
1153+ . zip ( cx. tcx . hir_body ( body_id) . params )
1154+ . map ( |( ty, param) | Parameter {
1155+ name : name_from_pat ( param. pat ) ,
1156+ type_ : clean_ty ( ty, cx) ,
1157+ is_const : false ,
1158+ } )
1159+ . collect ( )
11711160}
11721161
1173- fn clean_fn_decl_with_args < ' tcx > (
1162+ fn clean_fn_decl_with_params < ' tcx > (
11741163 cx : & mut DocContext < ' tcx > ,
11751164 decl : & hir:: FnDecl < ' tcx > ,
11761165 header : Option < & hir:: FnHeader > ,
1177- args : Arguments ,
1166+ params : Vec < Parameter > ,
11781167) -> FnDecl {
11791168 let mut output = match decl. output {
11801169 hir:: FnRetTy :: Return ( typ) => clean_ty ( typ, cx) ,
@@ -1185,7 +1174,7 @@ fn clean_fn_decl_with_args<'tcx>(
11851174 {
11861175 output = output. sugared_async_return_type ( ) ;
11871176 }
1188- FnDecl { inputs : args , output, c_variadic : decl. c_variadic }
1177+ FnDecl { inputs : params , output, c_variadic : decl. c_variadic }
11891178}
11901179
11911180fn clean_poly_fn_sig < ' tcx > (
@@ -1195,8 +1184,6 @@ fn clean_poly_fn_sig<'tcx>(
11951184) -> FnDecl {
11961185 let mut names = did. map_or ( & [ ] as & [ _ ] , |did| cx. tcx . fn_arg_idents ( did) ) . iter ( ) ;
11971186
1198- // We assume all empty tuples are default return type. This theoretically can discard `-> ()`,
1199- // but shouldn't change any code meaning.
12001187 let mut output = clean_middle_ty ( sig. output ( ) , cx, None , None ) ;
12011188
12021189 // If the return type isn't an `impl Trait`, we can safely assume that this
@@ -1209,25 +1196,17 @@ fn clean_poly_fn_sig<'tcx>(
12091196 output = output. sugared_async_return_type ( ) ;
12101197 }
12111198
1212- FnDecl {
1213- output,
1214- c_variadic : sig. skip_binder ( ) . c_variadic ,
1215- inputs : Arguments {
1216- values : sig
1217- . inputs ( )
1218- . iter ( )
1219- . map ( |t| Argument {
1220- type_ : clean_middle_ty ( t. map_bound ( |t| * t) , cx, None , None ) ,
1221- name : if let Some ( Some ( ident) ) = names. next ( ) {
1222- ident. name
1223- } else {
1224- kw:: Underscore
1225- } ,
1226- is_const : false ,
1227- } )
1228- . collect ( ) ,
1229- } ,
1230- }
1199+ let params = sig
1200+ . inputs ( )
1201+ . iter ( )
1202+ . map ( |t| Parameter {
1203+ type_ : clean_middle_ty ( t. map_bound ( |t| * t) , cx, None , None ) ,
1204+ name : if let Some ( Some ( ident) ) = names. next ( ) { ident. name } else { kw:: Underscore } ,
1205+ is_const : false ,
1206+ } )
1207+ . collect ( ) ;
1208+
1209+ FnDecl { inputs : params, output, c_variadic : sig. skip_binder ( ) . c_variadic }
12311210}
12321211
12331212fn clean_trait_ref < ' tcx > ( trait_ref : & hir:: TraitRef < ' tcx > , cx : & mut DocContext < ' tcx > ) -> Path {
@@ -1267,11 +1246,11 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
12671246 RequiredAssocConstItem ( generics, Box :: new ( clean_ty ( ty, cx) ) )
12681247 }
12691248 hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Provided ( body) ) => {
1270- let m = clean_function ( cx, sig, trait_item. generics , FunctionArgs :: Body ( body) ) ;
1249+ let m = clean_function ( cx, sig, trait_item. generics , ParamsSrc :: Body ( body) ) ;
12711250 MethodItem ( m, None )
12721251 }
12731252 hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Required ( idents) ) => {
1274- let m = clean_function ( cx, sig, trait_item. generics , FunctionArgs :: Idents ( idents) ) ;
1253+ let m = clean_function ( cx, sig, trait_item. generics , ParamsSrc :: Idents ( idents) ) ;
12751254 RequiredMethodItem ( m)
12761255 }
12771256 hir:: TraitItemKind :: Type ( bounds, Some ( default) ) => {
@@ -1312,7 +1291,7 @@ pub(crate) fn clean_impl_item<'tcx>(
13121291 type_ : clean_ty ( ty, cx) ,
13131292 } ) ) ,
13141293 hir:: ImplItemKind :: Fn ( ref sig, body) => {
1315- let m = clean_function ( cx, sig, impl_. generics , FunctionArgs :: Body ( body) ) ;
1294+ let m = clean_function ( cx, sig, impl_. generics , ParamsSrc :: Body ( body) ) ;
13161295 let defaultness = cx. tcx . defaultness ( impl_. owner_id ) ;
13171296 MethodItem ( m, Some ( defaultness) )
13181297 }
@@ -1384,14 +1363,14 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
13841363 }
13851364 ty:: AssocItemContainer :: Trait => tcx. types . self_param ,
13861365 } ;
1387- let self_arg_ty =
1366+ let self_param_ty =
13881367 tcx. fn_sig ( assoc_item. def_id ) . instantiate_identity ( ) . input ( 0 ) . skip_binder ( ) ;
1389- if self_arg_ty == self_ty {
1390- item. decl . inputs . values [ 0 ] . type_ = SelfTy ;
1391- } else if let ty:: Ref ( _, ty, _) = * self_arg_ty . kind ( )
1368+ if self_param_ty == self_ty {
1369+ item. decl . inputs [ 0 ] . type_ = SelfTy ;
1370+ } else if let ty:: Ref ( _, ty, _) = * self_param_ty . kind ( )
13921371 && ty == self_ty
13931372 {
1394- match item. decl . inputs . values [ 0 ] . type_ {
1373+ match item. decl . inputs [ 0 ] . type_ {
13951374 BorrowedRef { ref mut type_, .. } => * * type_ = SelfTy ,
13961375 _ => unreachable ! ( ) ,
13971376 }
@@ -2605,15 +2584,15 @@ fn clean_bare_fn_ty<'tcx>(
26052584 cx : & mut DocContext < ' tcx > ,
26062585) -> BareFunctionDecl {
26072586 let ( generic_params, decl) = enter_impl_trait ( cx, |cx| {
2608- // NOTE: generics must be cleaned before args
2587+ // NOTE: Generics must be cleaned before params.
26092588 let generic_params = bare_fn
26102589 . generic_params
26112590 . iter ( )
26122591 . filter ( |p| !is_elided_lifetime ( p) )
26132592 . map ( |x| clean_generic_param ( cx, None , x) )
26142593 . collect ( ) ;
2615- let args = clean_args_from_types_and_names ( cx, bare_fn. decl . inputs , bare_fn. param_idents ) ;
2616- let decl = clean_fn_decl_with_args ( cx, bare_fn. decl , None , args ) ;
2594+ let params = clean_params ( cx, bare_fn. decl . inputs , bare_fn. param_idents ) ;
2595+ let decl = clean_fn_decl_with_params ( cx, bare_fn. decl , None , params ) ;
26172596 ( generic_params, decl)
26182597 } ) ;
26192598 BareFunctionDecl { safety : bare_fn. safety , abi : bare_fn. abi , decl, generic_params }
@@ -2623,7 +2602,6 @@ fn clean_unsafe_binder_ty<'tcx>(
26232602 unsafe_binder_ty : & hir:: UnsafeBinderTy < ' tcx > ,
26242603 cx : & mut DocContext < ' tcx > ,
26252604) -> UnsafeBinderTy {
2626- // NOTE: generics must be cleaned before args
26272605 let generic_params = unsafe_binder_ty
26282606 . generic_params
26292607 . iter ( )
@@ -3149,7 +3127,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
31493127 cx. with_param_env ( def_id, |cx| {
31503128 let kind = match item. kind {
31513129 hir:: ForeignItemKind :: Fn ( sig, idents, generics) => ForeignFunctionItem (
3152- clean_function ( cx, & sig, generics, FunctionArgs :: Idents ( idents) ) ,
3130+ clean_function ( cx, & sig, generics, ParamsSrc :: Idents ( idents) ) ,
31533131 sig. header . safety ( ) ,
31543132 ) ,
31553133 hir:: ForeignItemKind :: Static ( ty, mutability, safety) => ForeignStaticItem (
0 commit comments