Skip to content

Commit 6214674

Browse files
committed
rustdoc/clean: Change terminology of items pertaining to (formal) fn params from "argument" to "parameter"
1 parent 79a272c commit 6214674

File tree

5 files changed

+107
-134
lines changed

5 files changed

+107
-134
lines changed

Diff for: src/librustdoc/clean/mod.rs

+64-86
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ fn clean_fn_or_proc_macro<'tcx>(
10521052
match macro_kind {
10531053
Some(kind) => clean_proc_macro(item, name, kind, cx),
10541054
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));
10561056
clean_fn_decl_legacy_const_generics(&mut func, attrs);
10571057
FunctionItem(func)
10581058
}
@@ -1071,16 +1071,11 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
10711071
for (pos, literal) in meta_item_list.iter().filter_map(|meta| meta.lit()).enumerate() {
10721072
match literal.kind {
10731073
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(
10821077
a.get() as _,
1083-
Argument { name: Some(name), type_: *ty, is_const: true },
1078+
Parameter { name: Some(name), type_: *ty, is_const: true },
10841079
);
10851080
} else {
10861081
panic!("unexpected non const in position {pos}");
@@ -1092,7 +1087,7 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
10921087
}
10931088
}
10941089

1095-
enum FunctionArgs<'tcx> {
1090+
enum ParamsSrc<'tcx> {
10961091
Body(hir::BodyId),
10971092
Idents(&'tcx [Option<Ident>]),
10981093
}
@@ -1101,30 +1096,26 @@ fn clean_function<'tcx>(
11011096
cx: &mut DocContext<'tcx>,
11021097
sig: &hir::FnSig<'tcx>,
11031098
generics: &hir::Generics<'tcx>,
1104-
args: FunctionArgs<'tcx>,
1099+
params: ParamsSrc<'tcx>,
11051100
) -> Box<Function> {
11061101
let (generics, decl) = enter_impl_trait(cx, |cx| {
1107-
// NOTE: generics must be cleaned before args
1102+
// NOTE: Generics must be cleaned before params.
11081103
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),
11161107
};
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);
11181109
(generics, decl)
11191110
});
11201111
Box::new(Function { decl, generics })
11211112
}
11221113

1123-
fn clean_args_from_types_and_names<'tcx>(
1114+
fn clean_params<'tcx>(
11241115
cx: &mut DocContext<'tcx>,
11251116
types: &[hir::Ty<'tcx>],
11261117
idents: &[Option<Ident>],
1127-
) -> Arguments {
1118+
) -> Vec<Parameter> {
11281119
fn nonempty_name(ident: &Option<Ident>) -> Option<Symbol> {
11291120
if let Some(ident) = ident
11301121
&& ident.name != kw::Underscore
@@ -1143,44 +1134,38 @@ fn clean_args_from_types_and_names<'tcx>(
11431134
None
11441135
};
11451136

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()
11571146
}
11581147

1159-
fn clean_args_from_types_and_body_id<'tcx>(
1148+
fn clean_params_via_body<'tcx>(
11601149
cx: &mut DocContext<'tcx>,
11611150
types: &[hir::Ty<'tcx>],
11621151
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()
11771162
}
11781163

1179-
fn clean_fn_decl_with_args<'tcx>(
1164+
fn clean_fn_decl_with_params<'tcx>(
11801165
cx: &mut DocContext<'tcx>,
11811166
decl: &hir::FnDecl<'tcx>,
11821167
header: Option<&hir::FnHeader>,
1183-
args: Arguments,
1168+
params: Vec<Parameter>,
11841169
) -> FnDecl {
11851170
let mut output = match decl.output {
11861171
hir::FnRetTy::Return(typ) => clean_ty(typ, cx),
@@ -1191,7 +1176,7 @@ fn clean_fn_decl_with_args<'tcx>(
11911176
{
11921177
output = output.sugared_async_return_type();
11931178
}
1194-
FnDecl { inputs: args, output, c_variadic: decl.c_variadic }
1179+
FnDecl { inputs: params, output, c_variadic: decl.c_variadic }
11951180
}
11961181

11971182
fn clean_poly_fn_sig<'tcx>(
@@ -1201,8 +1186,6 @@ fn clean_poly_fn_sig<'tcx>(
12011186
) -> FnDecl {
12021187
let mut names = did.map_or(&[] as &[_], |did| cx.tcx.fn_arg_idents(did)).iter();
12031188

1204-
// We assume all empty tuples are default return type. This theoretically can discard `-> ()`,
1205-
// but shouldn't change any code meaning.
12061189
let mut output = clean_middle_ty(sig.output(), cx, None, None);
12071190

12081191
// 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>(
12151198
output = output.sugared_async_return_type();
12161199
}
12171200

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 }
12371216
}
12381217

12391218
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
12731252
RequiredAssocConstItem(generics, Box::new(clean_ty(ty, cx)))
12741253
}
12751254
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));
12771256
MethodItem(m, None)
12781257
}
12791258
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));
12811260
RequiredMethodItem(m)
12821261
}
12831262
hir::TraitItemKind::Type(bounds, Some(default)) => {
@@ -1318,7 +1297,7 @@ pub(crate) fn clean_impl_item<'tcx>(
13181297
type_: clean_ty(ty, cx),
13191298
})),
13201299
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));
13221301
let defaultness = cx.tcx.defaultness(impl_.owner_id);
13231302
MethodItem(m, Some(defaultness))
13241303
}
@@ -1390,14 +1369,14 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
13901369
}
13911370
ty::AssocItemContainer::Trait => tcx.types.self_param,
13921371
};
1393-
let self_arg_ty =
1372+
let self_param_ty =
13941373
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()
13981377
&& ty == self_ty
13991378
{
1400-
match item.decl.inputs.values[0].type_ {
1379+
match item.decl.inputs[0].type_ {
14011380
BorrowedRef { ref mut type_, .. } => **type_ = SelfTy,
14021381
_ => unreachable!(),
14031382
}
@@ -2611,15 +2590,15 @@ fn clean_bare_fn_ty<'tcx>(
26112590
cx: &mut DocContext<'tcx>,
26122591
) -> BareFunctionDecl {
26132592
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.
26152594
let generic_params = bare_fn
26162595
.generic_params
26172596
.iter()
26182597
.filter(|p| !is_elided_lifetime(p))
26192598
.map(|x| clean_generic_param(cx, None, x))
26202599
.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);
26232602
(generic_params, decl)
26242603
});
26252604
BareFunctionDecl { safety: bare_fn.safety, abi: bare_fn.abi, decl, generic_params }
@@ -2629,7 +2608,6 @@ fn clean_unsafe_binder_ty<'tcx>(
26292608
unsafe_binder_ty: &hir::UnsafeBinderTy<'tcx>,
26302609
cx: &mut DocContext<'tcx>,
26312610
) -> UnsafeBinderTy {
2632-
// NOTE: generics must be cleaned before args
26332611
let generic_params = unsafe_binder_ty
26342612
.generic_params
26352613
.iter()
@@ -3155,7 +3133,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
31553133
cx.with_param_env(def_id, |cx| {
31563134
let kind = match item.kind {
31573135
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)),
31593137
sig.header.safety(),
31603138
),
31613139
hir::ForeignItemKind::Static(ty, mutability, safety) => ForeignStaticItem(

Diff for: src/librustdoc/clean/types.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1407,32 +1407,28 @@ pub(crate) struct Function {
14071407

14081408
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
14091409
pub(crate) struct FnDecl {
1410-
pub(crate) inputs: Arguments,
1410+
pub(crate) inputs: Vec<Parameter>,
14111411
pub(crate) output: Type,
14121412
pub(crate) c_variadic: bool,
14131413
}
14141414

14151415
impl FnDecl {
14161416
pub(crate) fn receiver_type(&self) -> Option<&Type> {
1417-
self.inputs.values.first().and_then(|v| v.to_receiver())
1417+
self.inputs.first().and_then(|v| v.to_receiver())
14181418
}
14191419
}
14201420

1421+
/// A function parameter.
14211422
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
1422-
pub(crate) struct Arguments {
1423-
pub(crate) values: Vec<Argument>,
1424-
}
1425-
1426-
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
1427-
pub(crate) struct Argument {
1428-
pub(crate) type_: Type,
1423+
pub(crate) struct Parameter {
14291424
pub(crate) name: Option<Symbol>,
1425+
pub(crate) type_: Type,
14301426
/// This field is used to represent "const" arguments from the `rustc_legacy_const_generics`
14311427
/// feature. More information in <https://github.com/rust-lang/rust/issues/83167>.
14321428
pub(crate) is_const: bool,
14331429
}
14341430

1435-
impl Argument {
1431+
impl Parameter {
14361432
pub(crate) fn to_receiver(&self) -> Option<&Type> {
14371433
if self.name == Some(kw::SelfLower) { Some(&self.type_) } else { None }
14381434
}

0 commit comments

Comments
 (0)