@@ -1052,7 +1052,7 @@ fn clean_fn_or_proc_macro<'tcx>(
1052
1052
match macro_kind {
1053
1053
Some ( kind) => clean_proc_macro ( item, name, kind, cx) ,
1054
1054
None => {
1055
- let mut func = clean_function ( cx, sig, generics, FunctionArgs :: Body ( body_id) ) ;
1055
+ let mut func = clean_function ( cx, sig, generics, ParamsSrc :: Body ( body_id) ) ;
1056
1056
clean_fn_decl_legacy_const_generics ( & mut func, attrs) ;
1057
1057
FunctionItem ( func)
1058
1058
}
@@ -1071,16 +1071,11 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
1071
1071
for ( pos, literal) in meta_item_list. iter ( ) . filter_map ( |meta| meta. lit ( ) ) . enumerate ( ) {
1072
1072
match literal. kind {
1073
1073
ast:: LitKind :: Int ( a, _) => {
1074
- let param = func. generics . params . remove ( 0 ) ;
1075
- if let GenericParamDef {
1076
- name,
1077
- kind : GenericParamDefKind :: Const { ty, .. } ,
1078
- ..
1079
- } = param
1080
- {
1081
- func. decl . inputs . values . insert (
1074
+ let GenericParamDef { name, kind, .. } = func. generics . params . remove ( 0 ) ;
1075
+ if let GenericParamDefKind :: Const { ty, .. } = kind {
1076
+ func. decl . inputs . insert (
1082
1077
a. get ( ) as _ ,
1083
- Argument { name : Some ( name) , type_ : * ty, is_const : true } ,
1078
+ Parameter { name : Some ( name) , type_ : * ty, is_const : true } ,
1084
1079
) ;
1085
1080
} else {
1086
1081
panic ! ( "unexpected non const in position {pos}" ) ;
@@ -1092,7 +1087,7 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
1092
1087
}
1093
1088
}
1094
1089
1095
- enum FunctionArgs < ' tcx > {
1090
+ enum ParamsSrc < ' tcx > {
1096
1091
Body ( hir:: BodyId ) ,
1097
1092
Idents ( & ' tcx [ Option < Ident > ] ) ,
1098
1093
}
@@ -1101,30 +1096,26 @@ fn clean_function<'tcx>(
1101
1096
cx : & mut DocContext < ' tcx > ,
1102
1097
sig : & hir:: FnSig < ' tcx > ,
1103
1098
generics : & hir:: Generics < ' tcx > ,
1104
- args : FunctionArgs < ' tcx > ,
1099
+ params : ParamsSrc < ' tcx > ,
1105
1100
) -> Box < Function > {
1106
1101
let ( generics, decl) = enter_impl_trait ( cx, |cx| {
1107
- // NOTE: generics must be cleaned before args
1102
+ // NOTE: Generics must be cleaned before params.
1108
1103
let generics = clean_generics ( generics, cx) ;
1109
- let args = match args {
1110
- FunctionArgs :: Body ( body_id) => {
1111
- clean_args_from_types_and_body_id ( cx, sig. decl . inputs , body_id)
1112
- }
1113
- FunctionArgs :: Idents ( idents) => {
1114
- clean_args_from_types_and_names ( cx, sig. decl . inputs , idents)
1115
- }
1104
+ let params = match params {
1105
+ ParamsSrc :: Body ( body_id) => clean_params_via_body ( cx, sig. decl . inputs , body_id) ,
1106
+ ParamsSrc :: Idents ( idents) => clean_params ( cx, sig. decl . inputs , idents) ,
1116
1107
} ;
1117
- let decl = clean_fn_decl_with_args ( cx, sig. decl , Some ( & sig. header ) , args ) ;
1108
+ let decl = clean_fn_decl_with_params ( cx, sig. decl , Some ( & sig. header ) , params ) ;
1118
1109
( generics, decl)
1119
1110
} ) ;
1120
1111
Box :: new ( Function { decl, generics } )
1121
1112
}
1122
1113
1123
- fn clean_args_from_types_and_names < ' tcx > (
1114
+ fn clean_params < ' tcx > (
1124
1115
cx : & mut DocContext < ' tcx > ,
1125
1116
types : & [ hir:: Ty < ' tcx > ] ,
1126
1117
idents : & [ Option < Ident > ] ,
1127
- ) -> Arguments {
1118
+ ) -> Vec < Parameter > {
1128
1119
fn nonempty_name ( ident : & Option < Ident > ) -> Option < Symbol > {
1129
1120
if let Some ( ident) = ident
1130
1121
&& ident. name != kw:: Underscore
@@ -1143,44 +1134,38 @@ fn clean_args_from_types_and_names<'tcx>(
1143
1134
None
1144
1135
} ;
1145
1136
1146
- Arguments {
1147
- values : types
1148
- . iter ( )
1149
- . enumerate ( )
1150
- . map ( |( i, ty) | Argument {
1151
- type_ : clean_ty ( ty, cx) ,
1152
- name : idents. get ( i) . and_then ( nonempty_name) . or ( default_name) ,
1153
- is_const : false ,
1154
- } )
1155
- . collect ( ) ,
1156
- }
1137
+ types
1138
+ . iter ( )
1139
+ . enumerate ( )
1140
+ . map ( |( i, ty) | Parameter {
1141
+ name : idents. get ( i) . and_then ( nonempty_name) . or ( default_name) ,
1142
+ type_ : clean_ty ( ty, cx) ,
1143
+ is_const : false ,
1144
+ } )
1145
+ . collect ( )
1157
1146
}
1158
1147
1159
- fn clean_args_from_types_and_body_id < ' tcx > (
1148
+ fn clean_params_via_body < ' tcx > (
1160
1149
cx : & mut DocContext < ' tcx > ,
1161
1150
types : & [ hir:: Ty < ' tcx > ] ,
1162
1151
body_id : hir:: BodyId ,
1163
- ) -> Arguments {
1164
- let body = cx. tcx . hir_body ( body_id) ;
1165
-
1166
- Arguments {
1167
- values : types
1168
- . iter ( )
1169
- . zip ( body. params )
1170
- . map ( |( ty, param) | Argument {
1171
- name : Some ( name_from_pat ( param. pat ) ) ,
1172
- type_ : clean_ty ( ty, cx) ,
1173
- is_const : false ,
1174
- } )
1175
- . collect ( ) ,
1176
- }
1152
+ ) -> Vec < Parameter > {
1153
+ types
1154
+ . iter ( )
1155
+ . zip ( cx. tcx . hir_body ( body_id) . params )
1156
+ . map ( |( ty, param) | Parameter {
1157
+ name : Some ( name_from_pat ( param. pat ) ) ,
1158
+ type_ : clean_ty ( ty, cx) ,
1159
+ is_const : false ,
1160
+ } )
1161
+ . collect ( )
1177
1162
}
1178
1163
1179
- fn clean_fn_decl_with_args < ' tcx > (
1164
+ fn clean_fn_decl_with_params < ' tcx > (
1180
1165
cx : & mut DocContext < ' tcx > ,
1181
1166
decl : & hir:: FnDecl < ' tcx > ,
1182
1167
header : Option < & hir:: FnHeader > ,
1183
- args : Arguments ,
1168
+ params : Vec < Parameter > ,
1184
1169
) -> FnDecl {
1185
1170
let mut output = match decl. output {
1186
1171
hir:: FnRetTy :: Return ( typ) => clean_ty ( typ, cx) ,
@@ -1191,7 +1176,7 @@ fn clean_fn_decl_with_args<'tcx>(
1191
1176
{
1192
1177
output = output. sugared_async_return_type ( ) ;
1193
1178
}
1194
- FnDecl { inputs : args , output, c_variadic : decl. c_variadic }
1179
+ FnDecl { inputs : params , output, c_variadic : decl. c_variadic }
1195
1180
}
1196
1181
1197
1182
fn clean_poly_fn_sig < ' tcx > (
@@ -1201,8 +1186,6 @@ fn clean_poly_fn_sig<'tcx>(
1201
1186
) -> FnDecl {
1202
1187
let mut names = did. map_or ( & [ ] as & [ _ ] , |did| cx. tcx . fn_arg_idents ( did) ) . iter ( ) ;
1203
1188
1204
- // We assume all empty tuples are default return type. This theoretically can discard `-> ()`,
1205
- // but shouldn't change any code meaning.
1206
1189
let mut output = clean_middle_ty ( sig. output ( ) , cx, None , None ) ;
1207
1190
1208
1191
// If the return type isn't an `impl Trait`, we can safely assume that this
@@ -1215,25 +1198,21 @@ fn clean_poly_fn_sig<'tcx>(
1215
1198
output = output. sugared_async_return_type ( ) ;
1216
1199
}
1217
1200
1218
- FnDecl {
1219
- output,
1220
- c_variadic : sig. skip_binder ( ) . c_variadic ,
1221
- inputs : Arguments {
1222
- values : sig
1223
- . inputs ( )
1224
- . iter ( )
1225
- . map ( |t| Argument {
1226
- type_ : clean_middle_ty ( t. map_bound ( |t| * t) , cx, None , None ) ,
1227
- name : Some ( if let Some ( Some ( ident) ) = names. next ( ) {
1228
- ident. name
1229
- } else {
1230
- kw:: Underscore
1231
- } ) ,
1232
- is_const : false ,
1233
- } )
1234
- . collect ( ) ,
1235
- } ,
1236
- }
1201
+ let params = sig
1202
+ . inputs ( )
1203
+ . iter ( )
1204
+ . map ( |t| Parameter {
1205
+ type_ : clean_middle_ty ( t. map_bound ( |t| * t) , cx, None , None ) ,
1206
+ name : Some ( if let Some ( Some ( ident) ) = names. next ( ) {
1207
+ ident. name
1208
+ } else {
1209
+ kw:: Underscore
1210
+ } ) ,
1211
+ is_const : false ,
1212
+ } )
1213
+ . collect ( ) ;
1214
+
1215
+ FnDecl { inputs : params, output, c_variadic : sig. skip_binder ( ) . c_variadic }
1237
1216
}
1238
1217
1239
1218
fn clean_trait_ref < ' tcx > ( trait_ref : & hir:: TraitRef < ' tcx > , cx : & mut DocContext < ' tcx > ) -> Path {
@@ -1273,11 +1252,11 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
1273
1252
RequiredAssocConstItem ( generics, Box :: new ( clean_ty ( ty, cx) ) )
1274
1253
}
1275
1254
hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Provided ( body) ) => {
1276
- let m = clean_function ( cx, sig, trait_item. generics , FunctionArgs :: Body ( body) ) ;
1255
+ let m = clean_function ( cx, sig, trait_item. generics , ParamsSrc :: Body ( body) ) ;
1277
1256
MethodItem ( m, None )
1278
1257
}
1279
1258
hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Required ( idents) ) => {
1280
- let m = clean_function ( cx, sig, trait_item. generics , FunctionArgs :: Idents ( idents) ) ;
1259
+ let m = clean_function ( cx, sig, trait_item. generics , ParamsSrc :: Idents ( idents) ) ;
1281
1260
RequiredMethodItem ( m)
1282
1261
}
1283
1262
hir:: TraitItemKind :: Type ( bounds, Some ( default) ) => {
@@ -1318,7 +1297,7 @@ pub(crate) fn clean_impl_item<'tcx>(
1318
1297
type_ : clean_ty ( ty, cx) ,
1319
1298
} ) ) ,
1320
1299
hir:: ImplItemKind :: Fn ( ref sig, body) => {
1321
- let m = clean_function ( cx, sig, impl_. generics , FunctionArgs :: Body ( body) ) ;
1300
+ let m = clean_function ( cx, sig, impl_. generics , ParamsSrc :: Body ( body) ) ;
1322
1301
let defaultness = cx. tcx . defaultness ( impl_. owner_id ) ;
1323
1302
MethodItem ( m, Some ( defaultness) )
1324
1303
}
@@ -1390,14 +1369,14 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
1390
1369
}
1391
1370
ty:: AssocItemContainer :: Trait => tcx. types . self_param ,
1392
1371
} ;
1393
- let self_arg_ty =
1372
+ let self_param_ty =
1394
1373
tcx. fn_sig ( assoc_item. def_id ) . instantiate_identity ( ) . input ( 0 ) . skip_binder ( ) ;
1395
- if self_arg_ty == self_ty {
1396
- item. decl . inputs . values [ 0 ] . type_ = SelfTy ;
1397
- } else if let ty:: Ref ( _, ty, _) = * self_arg_ty . kind ( )
1374
+ if self_param_ty == self_ty {
1375
+ item. decl . inputs [ 0 ] . type_ = SelfTy ;
1376
+ } else if let ty:: Ref ( _, ty, _) = * self_param_ty . kind ( )
1398
1377
&& ty == self_ty
1399
1378
{
1400
- match item. decl . inputs . values [ 0 ] . type_ {
1379
+ match item. decl . inputs [ 0 ] . type_ {
1401
1380
BorrowedRef { ref mut type_, .. } => * * type_ = SelfTy ,
1402
1381
_ => unreachable ! ( ) ,
1403
1382
}
@@ -2611,15 +2590,15 @@ fn clean_bare_fn_ty<'tcx>(
2611
2590
cx : & mut DocContext < ' tcx > ,
2612
2591
) -> BareFunctionDecl {
2613
2592
let ( generic_params, decl) = enter_impl_trait ( cx, |cx| {
2614
- // NOTE: generics must be cleaned before args
2593
+ // NOTE: Generics must be cleaned before params.
2615
2594
let generic_params = bare_fn
2616
2595
. generic_params
2617
2596
. iter ( )
2618
2597
. filter ( |p| !is_elided_lifetime ( p) )
2619
2598
. map ( |x| clean_generic_param ( cx, None , x) )
2620
2599
. collect ( ) ;
2621
- let args = clean_args_from_types_and_names ( cx, bare_fn. decl . inputs , bare_fn. param_idents ) ;
2622
- let decl = clean_fn_decl_with_args ( cx, bare_fn. decl , None , args ) ;
2600
+ let params = clean_params ( cx, bare_fn. decl . inputs , bare_fn. param_idents ) ;
2601
+ let decl = clean_fn_decl_with_params ( cx, bare_fn. decl , None , params ) ;
2623
2602
( generic_params, decl)
2624
2603
} ) ;
2625
2604
BareFunctionDecl { safety : bare_fn. safety , abi : bare_fn. abi , decl, generic_params }
@@ -2629,7 +2608,6 @@ fn clean_unsafe_binder_ty<'tcx>(
2629
2608
unsafe_binder_ty : & hir:: UnsafeBinderTy < ' tcx > ,
2630
2609
cx : & mut DocContext < ' tcx > ,
2631
2610
) -> UnsafeBinderTy {
2632
- // NOTE: generics must be cleaned before args
2633
2611
let generic_params = unsafe_binder_ty
2634
2612
. generic_params
2635
2613
. iter ( )
@@ -3155,7 +3133,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
3155
3133
cx. with_param_env ( def_id, |cx| {
3156
3134
let kind = match item. kind {
3157
3135
hir:: ForeignItemKind :: Fn ( sig, idents, generics) => ForeignFunctionItem (
3158
- clean_function ( cx, & sig, generics, FunctionArgs :: Idents ( idents) ) ,
3136
+ clean_function ( cx, & sig, generics, ParamsSrc :: Idents ( idents) ) ,
3159
3137
sig. header . safety ( ) ,
3160
3138
) ,
3161
3139
hir:: ForeignItemKind :: Static ( ty, mutability, safety) => ForeignStaticItem (
0 commit comments