@@ -1046,7 +1046,7 @@ fn clean_fn_or_proc_macro<'tcx>(
1046
1046
match macro_kind {
1047
1047
Some ( kind) => clean_proc_macro ( item, name, kind, cx) ,
1048
1048
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) ) ;
1050
1050
clean_fn_decl_legacy_const_generics ( & mut func, attrs) ;
1051
1051
FunctionItem ( func)
1052
1052
}
@@ -1074,8 +1074,7 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
1074
1074
{
1075
1075
func. decl
1076
1076
. 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 } ) ;
1079
1078
} else {
1080
1079
panic ! ( "unexpected non const in position {pos}" ) ;
1081
1080
}
@@ -1086,7 +1085,7 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
1086
1085
}
1087
1086
}
1088
1087
1089
- enum FunctionArgs < ' tcx > {
1088
+ enum ParamsSrc < ' tcx > {
1090
1089
Body ( hir:: BodyId ) ,
1091
1090
Idents ( & ' tcx [ Option < Ident > ] ) ,
1092
1091
}
@@ -1095,30 +1094,26 @@ fn clean_function<'tcx>(
1095
1094
cx : & mut DocContext < ' tcx > ,
1096
1095
sig : & hir:: FnSig < ' tcx > ,
1097
1096
generics : & hir:: Generics < ' tcx > ,
1098
- args : FunctionArgs < ' tcx > ,
1097
+ params : ParamsSrc < ' tcx > ,
1099
1098
) -> Box < Function > {
1100
1099
let ( generics, decl) = enter_impl_trait ( cx, |cx| {
1101
- // NOTE: generics must be cleaned before args
1100
+ // NOTE: Generics must be cleaned before params.
1102
1101
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) ,
1110
1105
} ;
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 ) ;
1112
1107
( generics, decl)
1113
1108
} ) ;
1114
1109
Box :: new ( Function { decl, generics } )
1115
1110
}
1116
1111
1117
- fn clean_args_from_types_and_names < ' tcx > (
1112
+ fn clean_params < ' tcx > (
1118
1113
cx : & mut DocContext < ' tcx > ,
1119
1114
types : & [ hir:: Ty < ' tcx > ] ,
1120
1115
idents : & [ Option < Ident > ] ,
1121
- ) -> Arguments {
1116
+ ) -> Vec < Parameter > {
1122
1117
fn nonempty_name ( ident : & Option < Ident > ) -> Option < Symbol > {
1123
1118
if let Some ( ident) = ident
1124
1119
&& ident. name != kw:: Underscore
@@ -1134,47 +1129,41 @@ fn clean_args_from_types_and_names<'tcx>(
1134
1129
let default_name = if idents. iter ( ) . any ( |ident| nonempty_name ( ident) . is_some ( ) ) {
1135
1130
kw:: Underscore
1136
1131
} else {
1137
- kw:: Empty
1132
+ kw:: Empty // FIXME: using kw::Empty is a bit of a hack
1138
1133
} ;
1139
1134
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 ( )
1151
1144
}
1152
1145
1153
- fn clean_args_from_types_and_body_id < ' tcx > (
1146
+ fn clean_params_via_body < ' tcx > (
1154
1147
cx : & mut DocContext < ' tcx > ,
1155
1148
types : & [ hir:: Ty < ' tcx > ] ,
1156
1149
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 ( )
1171
1160
}
1172
1161
1173
- fn clean_fn_decl_with_args < ' tcx > (
1162
+ fn clean_fn_decl_with_params < ' tcx > (
1174
1163
cx : & mut DocContext < ' tcx > ,
1175
1164
decl : & hir:: FnDecl < ' tcx > ,
1176
1165
header : Option < & hir:: FnHeader > ,
1177
- args : Arguments ,
1166
+ params : Vec < Parameter > ,
1178
1167
) -> FnDecl {
1179
1168
let mut output = match decl. output {
1180
1169
hir:: FnRetTy :: Return ( typ) => clean_ty ( typ, cx) ,
@@ -1185,7 +1174,7 @@ fn clean_fn_decl_with_args<'tcx>(
1185
1174
{
1186
1175
output = output. sugared_async_return_type ( ) ;
1187
1176
}
1188
- FnDecl { inputs : args , output, c_variadic : decl. c_variadic }
1177
+ FnDecl { inputs : params , output, c_variadic : decl. c_variadic }
1189
1178
}
1190
1179
1191
1180
fn clean_poly_fn_sig < ' tcx > (
@@ -1195,8 +1184,6 @@ fn clean_poly_fn_sig<'tcx>(
1195
1184
) -> FnDecl {
1196
1185
let mut names = did. map_or ( & [ ] as & [ _ ] , |did| cx. tcx . fn_arg_idents ( did) ) . iter ( ) ;
1197
1186
1198
- // We assume all empty tuples are default return type. This theoretically can discard `-> ()`,
1199
- // but shouldn't change any code meaning.
1200
1187
let mut output = clean_middle_ty ( sig. output ( ) , cx, None , None ) ;
1201
1188
1202
1189
// 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>(
1209
1196
output = output. sugared_async_return_type ( ) ;
1210
1197
}
1211
1198
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 }
1231
1210
}
1232
1211
1233
1212
fn 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
1267
1246
RequiredAssocConstItem ( generics, Box :: new ( clean_ty ( ty, cx) ) )
1268
1247
}
1269
1248
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) ) ;
1271
1250
MethodItem ( m, None )
1272
1251
}
1273
1252
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) ) ;
1275
1254
RequiredMethodItem ( m)
1276
1255
}
1277
1256
hir:: TraitItemKind :: Type ( bounds, Some ( default) ) => {
@@ -1312,7 +1291,7 @@ pub(crate) fn clean_impl_item<'tcx>(
1312
1291
type_ : clean_ty ( ty, cx) ,
1313
1292
} ) ) ,
1314
1293
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) ) ;
1316
1295
let defaultness = cx. tcx . defaultness ( impl_. owner_id ) ;
1317
1296
MethodItem ( m, Some ( defaultness) )
1318
1297
}
@@ -1384,14 +1363,14 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
1384
1363
}
1385
1364
ty:: AssocItemContainer :: Trait => tcx. types . self_param ,
1386
1365
} ;
1387
- let self_arg_ty =
1366
+ let self_param_ty =
1388
1367
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 ( )
1392
1371
&& ty == self_ty
1393
1372
{
1394
- match item. decl . inputs . values [ 0 ] . type_ {
1373
+ match item. decl . inputs [ 0 ] . type_ {
1395
1374
BorrowedRef { ref mut type_, .. } => * * type_ = SelfTy ,
1396
1375
_ => unreachable ! ( ) ,
1397
1376
}
@@ -2605,15 +2584,15 @@ fn clean_bare_fn_ty<'tcx>(
2605
2584
cx : & mut DocContext < ' tcx > ,
2606
2585
) -> BareFunctionDecl {
2607
2586
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.
2609
2588
let generic_params = bare_fn
2610
2589
. generic_params
2611
2590
. iter ( )
2612
2591
. filter ( |p| !is_elided_lifetime ( p) )
2613
2592
. map ( |x| clean_generic_param ( cx, None , x) )
2614
2593
. 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 ) ;
2617
2596
( generic_params, decl)
2618
2597
} ) ;
2619
2598
BareFunctionDecl { safety : bare_fn. safety , abi : bare_fn. abi , decl, generic_params }
@@ -2623,7 +2602,6 @@ fn clean_unsafe_binder_ty<'tcx>(
2623
2602
unsafe_binder_ty : & hir:: UnsafeBinderTy < ' tcx > ,
2624
2603
cx : & mut DocContext < ' tcx > ,
2625
2604
) -> UnsafeBinderTy {
2626
- // NOTE: generics must be cleaned before args
2627
2605
let generic_params = unsafe_binder_ty
2628
2606
. generic_params
2629
2607
. iter ( )
@@ -3149,7 +3127,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
3149
3127
cx. with_param_env ( def_id, |cx| {
3150
3128
let kind = match item. kind {
3151
3129
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) ) ,
3153
3131
sig. header . safety ( ) ,
3154
3132
) ,
3155
3133
hir:: ForeignItemKind :: Static ( ty, mutability, safety) => ForeignStaticItem (
0 commit comments