Skip to content

Commit bbd48e6

Browse files
committed
Auto merge of #63127 - kper:pr, r=nikomatsakis
Cleanup: Consistently use `Param` instead of `Arg` #62426 Fixes #62426
2 parents b7178cb + 97319b2 commit bbd48e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+391
-388
lines changed

src/librustc/error_codes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2231,15 +2231,15 @@ register_diagnostics! {
22312231
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
22322232
E0566, // conflicting representation hints
22332233
E0623, // lifetime mismatch where both parameters are anonymous regions
2234-
E0628, // generators cannot have explicit arguments
2234+
E0628, // generators cannot have explicit parameters
22352235
E0631, // type mismatch in closure arguments
22362236
E0637, // "'_" is not a valid lifetime bound
22372237
E0657, // `impl Trait` can only capture lifetimes bound at the fn level
22382238
E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
22392239
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
22402240
E0697, // closures cannot be static
22412241
E0707, // multiple elided lifetimes used in arguments of `async fn`
2242-
E0708, // `async` non-`move` closures with arguments are not currently supported
2242+
E0708, // `async` non-`move` closures with parameters are not currently supported
22432243
E0709, // multiple different lifetimes used in arguments of `async fn`
22442244
E0710, // an unknown tool name found in scoped lint
22452245
E0711, // a feature has been declared with conflicting stability attributes

src/librustc/hir/intravisit.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ pub trait Visitor<'v> : Sized {
210210
}
211211
}
212212

213-
fn visit_arg(&mut self, arg: &'v Arg) {
214-
walk_arg(self, arg)
213+
fn visit_param(&mut self, param: &'v Param) {
214+
walk_param(self, param)
215215
}
216216

217217
/// Visits the top-level item and (optionally) nested items / impl items. See
@@ -400,7 +400,7 @@ pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod, mod_hir_id
400400
}
401401

402402
pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body) {
403-
walk_list!(visitor, visit_arg, &body.arguments);
403+
walk_list!(visitor, visit_param, &body.params);
404404
visitor.visit_expr(&body.value);
405405
}
406406

@@ -454,10 +454,10 @@ pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef)
454454
visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id)
455455
}
456456

457-
pub fn walk_arg<'v, V: Visitor<'v>>(visitor: &mut V, arg: &'v Arg) {
458-
visitor.visit_id(arg.hir_id);
459-
visitor.visit_pat(&arg.pat);
460-
walk_list!(visitor, visit_attribute, &arg.attrs);
457+
pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param) {
458+
visitor.visit_id(param.hir_id);
459+
visitor.visit_pat(&param.pat);
460+
walk_list!(visitor, visit_attribute, &param.attrs);
461461
}
462462

463463
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {

src/librustc/hir/lowering.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,12 @@ impl<'a> LoweringContext<'a> {
510510
&f.generic_params
511511
);
512512
// Mirrors visit::walk_fn_decl
513-
for argument in &f.decl.inputs {
513+
for parameter in &f.decl.inputs {
514514
// We don't lower the ids of argument patterns
515515
self.with_hir_id_owner(None, |this| {
516-
this.visit_pat(&argument.pat);
516+
this.visit_pat(&parameter.pat);
517517
});
518-
self.visit_ty(&argument.ty)
518+
self.visit_ty(&parameter.ty)
519519
}
520520
self.visit_fn_ret_ty(&f.decl.output)
521521
}
@@ -735,7 +735,7 @@ impl<'a> LoweringContext<'a> {
735735
///
736736
/// Presuming that in-band lifetimes are enabled, then
737737
/// `self.anonymous_lifetime_mode` will be updated to match the
738-
/// argument while `f` is running (and restored afterwards).
738+
/// parameter while `f` is running (and restored afterwards).
739739
fn collect_in_band_defs<T, F>(
740740
&mut self,
741741
parent_id: DefId,
@@ -880,7 +880,7 @@ impl<'a> LoweringContext<'a> {
880880
///
881881
/// Presuming that in-band lifetimes are enabled, then
882882
/// `self.anonymous_lifetime_mode` will be updated to match the
883-
/// argument while `f` is running (and restored afterwards).
883+
/// parameter while `f` is running (and restored afterwards).
884884
fn add_in_band_defs<F, T>(
885885
&mut self,
886886
generics: &Generics,
@@ -1080,7 +1080,7 @@ impl<'a> LoweringContext<'a> {
10801080
ImplTraitContext::Disallowed(_) if self.is_in_dyn_type =>
10811081
(true, ImplTraitContext::OpaqueTy(None)),
10821082

1083-
// We are in the argument position, but not within a dyn type:
1083+
// We are in the parameter position, but not within a dyn type:
10841084
//
10851085
// fn foo(x: impl Iterator<Item: Debug>)
10861086
//
@@ -1204,7 +1204,7 @@ impl<'a> LoweringContext<'a> {
12041204
unsafety: this.lower_unsafety(f.unsafety),
12051205
abi: f.abi,
12061206
decl: this.lower_fn_decl(&f.decl, None, false, None),
1207-
arg_names: this.lower_fn_args_to_names(&f.decl),
1207+
param_names: this.lower_fn_params_to_names(&f.decl),
12081208
}))
12091209
},
12101210
)
@@ -2093,12 +2093,12 @@ impl<'a> LoweringContext<'a> {
20932093
}
20942094
}
20952095

2096-
fn lower_fn_args_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
2096+
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
20972097
decl.inputs
20982098
.iter()
2099-
.map(|arg| match arg.pat.node {
2099+
.map(|param| match param.pat.node {
21002100
PatKind::Ident(_, ident, _) => ident,
2101-
_ => Ident::new(kw::Invalid, arg.pat.span),
2101+
_ => Ident::new(kw::Invalid, param.pat.span),
21022102
})
21032103
.collect()
21042104
}
@@ -2136,11 +2136,11 @@ impl<'a> LoweringContext<'a> {
21362136
let inputs = self.with_anonymous_lifetime_mode(lt_mode, |this| {
21372137
decl.inputs
21382138
.iter()
2139-
.map(|arg| {
2139+
.map(|param| {
21402140
if let Some((_, ibty)) = &mut in_band_ty_params {
2141-
this.lower_ty_direct(&arg.ty, ImplTraitContext::Universal(ibty))
2141+
this.lower_ty_direct(&param.ty, ImplTraitContext::Universal(ibty))
21422142
} else {
2143-
this.lower_ty_direct(&arg.ty, ImplTraitContext::disallowed())
2143+
this.lower_ty_direct(&param.ty, ImplTraitContext::disallowed())
21442144
}
21452145
})
21462146
.collect::<HirVec<_>>()
@@ -2205,7 +2205,7 @@ impl<'a> LoweringContext<'a> {
22052205
//
22062206
// type OpaqueTy<generics_from_parent_fn> = impl Future<Output = T>;
22072207
//
2208-
// `inputs`: lowered types of arguments to the function (used to collect lifetimes)
2208+
// `inputs`: lowered types of parameters to the function (used to collect lifetimes)
22092209
// `output`: unlowered output type (`T` in `-> T`)
22102210
// `fn_def_id`: `DefId` of the parent function (used to create child impl trait definition)
22112211
// `opaque_ty_node_id`: `NodeId` of the opaque `impl Trait` type that should be created

src/librustc/hir/lowering/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ impl LoweringContext<'_> {
724724
self.sess,
725725
fn_decl_span,
726726
E0628,
727-
"generators cannot have explicit arguments"
727+
"generators cannot have explicit parameters"
728728
);
729729
self.sess.abort_if_errors();
730730
}
@@ -775,7 +775,7 @@ impl LoweringContext<'_> {
775775
this.sess,
776776
fn_decl_span,
777777
E0708,
778-
"`async` non-`move` closures with arguments are not currently supported",
778+
"`async` non-`move` closures with parameters are not currently supported",
779779
)
780780
.help(
781781
"consider using `let` statements to manually capture \

src/librustc/hir/lowering/item.rs

+40-40
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ impl LoweringContext<'_> {
720720
(
721721
// Disallow impl Trait in foreign items
722722
this.lower_fn_decl(fdec, None, false, None),
723-
this.lower_fn_args_to_names(fdec),
723+
this.lower_fn_params_to_names(fdec),
724724
)
725725
},
726726
);
@@ -827,7 +827,7 @@ impl LoweringContext<'_> {
827827
),
828828
),
829829
TraitItemKind::Method(ref sig, None) => {
830-
let names = self.lower_fn_args_to_names(&sig.decl);
830+
let names = self.lower_fn_params_to_names(&sig.decl);
831831
let (generics, sig) = self.lower_method_sig(
832832
&i.generics,
833833
sig,
@@ -1028,10 +1028,10 @@ impl LoweringContext<'_> {
10281028
}
10291029
}
10301030

1031-
fn record_body(&mut self, arguments: HirVec<hir::Arg>, value: hir::Expr) -> hir::BodyId {
1031+
fn record_body(&mut self, params: HirVec<hir::Param>, value: hir::Expr) -> hir::BodyId {
10321032
let body = hir::Body {
10331033
generator_kind: self.generator_kind,
1034-
arguments,
1034+
params,
10351035
value,
10361036
};
10371037
let id = body.id();
@@ -1041,21 +1041,21 @@ impl LoweringContext<'_> {
10411041

10421042
fn lower_body(
10431043
&mut self,
1044-
f: impl FnOnce(&mut LoweringContext<'_>) -> (HirVec<hir::Arg>, hir::Expr),
1044+
f: impl FnOnce(&mut LoweringContext<'_>) -> (HirVec<hir::Param>, hir::Expr),
10451045
) -> hir::BodyId {
10461046
let prev_gen_kind = self.generator_kind.take();
1047-
let (arguments, result) = f(self);
1048-
let body_id = self.record_body(arguments, result);
1047+
let (parameters, result) = f(self);
1048+
let body_id = self.record_body(parameters, result);
10491049
self.generator_kind = prev_gen_kind;
10501050
body_id
10511051
}
10521052

1053-
fn lower_arg(&mut self, arg: &Arg) -> hir::Arg {
1054-
hir::Arg {
1055-
attrs: self.lower_attrs(&arg.attrs),
1056-
hir_id: self.lower_node_id(arg.id),
1057-
pat: self.lower_pat(&arg.pat),
1058-
span: arg.span,
1053+
fn lower_param(&mut self, param: &Param) -> hir::Param {
1054+
hir::Param {
1055+
attrs: self.lower_attrs(&param.attrs),
1056+
hir_id: self.lower_node_id(param.id),
1057+
pat: self.lower_pat(&param.pat),
1058+
span: param.span,
10591059
}
10601060
}
10611061

@@ -1065,7 +1065,7 @@ impl LoweringContext<'_> {
10651065
body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr,
10661066
) -> hir::BodyId {
10671067
self.lower_body(|this| (
1068-
decl.inputs.iter().map(|x| this.lower_arg(x)).collect(),
1068+
decl.inputs.iter().map(|x| this.lower_param(x)).collect(),
10691069
body(this),
10701070
))
10711071
}
@@ -1093,10 +1093,10 @@ impl LoweringContext<'_> {
10931093
};
10941094

10951095
self.lower_body(|this| {
1096-
let mut arguments: Vec<hir::Arg> = Vec::new();
1096+
let mut parameters: Vec<hir::Param> = Vec::new();
10971097
let mut statements: Vec<hir::Stmt> = Vec::new();
10981098

1099-
// Async function arguments are lowered into the closure body so that they are
1099+
// Async function parameters are lowered into the closure body so that they are
11001100
// captured and so that the drop order matches the equivalent non-async functions.
11011101
//
11021102
// from:
@@ -1121,13 +1121,13 @@ impl LoweringContext<'_> {
11211121
//
11221122
// If `<pattern>` is a simple ident, then it is lowered to a single
11231123
// `let <pattern> = <pattern>;` statement as an optimization.
1124-
for (index, argument) in decl.inputs.iter().enumerate() {
1125-
let argument = this.lower_arg(argument);
1126-
let span = argument.pat.span;
1124+
for (index, parameter) in decl.inputs.iter().enumerate() {
1125+
let parameter = this.lower_param(parameter);
1126+
let span = parameter.pat.span;
11271127

11281128
// Check if this is a binding pattern, if so, we can optimize and avoid adding a
1129-
// `let <pat> = __argN;` statement. In this case, we do not rename the argument.
1130-
let (ident, is_simple_argument) = match argument.pat.node {
1129+
// `let <pat> = __argN;` statement. In this case, we do not rename the parameter.
1130+
let (ident, is_simple_parameter) = match parameter.pat.node {
11311131
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, _) =>
11321132
(ident, true),
11331133
_ => {
@@ -1142,32 +1142,32 @@ impl LoweringContext<'_> {
11421142
let desugared_span =
11431143
this.mark_span_with_reason(DesugaringKind::Async, span, None);
11441144

1145-
// Construct an argument representing `__argN: <ty>` to replace the argument of the
1145+
// Construct a parameter representing `__argN: <ty>` to replace the parameter of the
11461146
// async function.
11471147
//
1148-
// If this is the simple case, this argument will end up being the same as the
1149-
// original argument, but with a different pattern id.
1148+
// If this is the simple case, this parameter will end up being the same as the
1149+
// original parameter, but with a different pattern id.
11501150
let mut stmt_attrs = ThinVec::new();
1151-
stmt_attrs.extend(argument.attrs.iter().cloned());
1152-
let (new_argument_pat, new_argument_id) = this.pat_ident(desugared_span, ident);
1153-
let new_argument = hir::Arg {
1154-
attrs: argument.attrs,
1155-
hir_id: argument.hir_id,
1156-
pat: new_argument_pat,
1157-
span: argument.span,
1151+
stmt_attrs.extend(parameter.attrs.iter().cloned());
1152+
let (new_parameter_pat, new_parameter_id) = this.pat_ident(desugared_span, ident);
1153+
let new_parameter = hir::Param {
1154+
attrs: parameter.attrs,
1155+
hir_id: parameter.hir_id,
1156+
pat: new_parameter_pat,
1157+
span: parameter.span,
11581158
};
11591159

11601160

1161-
if is_simple_argument {
1161+
if is_simple_parameter {
11621162
// If this is the simple case, then we only insert one statement that is
11631163
// `let <pat> = <pat>;`. We re-use the original argument's pattern so that
11641164
// `HirId`s are densely assigned.
1165-
let expr = this.expr_ident(desugared_span, ident, new_argument_id);
1165+
let expr = this.expr_ident(desugared_span, ident, new_parameter_id);
11661166
let stmt = this.stmt_let_pat(
11671167
stmt_attrs,
11681168
desugared_span,
11691169
Some(P(expr)),
1170-
argument.pat,
1170+
parameter.pat,
11711171
hir::LocalSource::AsyncFn
11721172
);
11731173
statements.push(stmt);
@@ -1179,7 +1179,7 @@ impl LoweringContext<'_> {
11791179
// let <pat> = __argN;
11801180
// ```
11811181
//
1182-
// The first statement moves the argument into the closure and thus ensures
1182+
// The first statement moves the parameter into the closure and thus ensures
11831183
// that the drop order is correct.
11841184
//
11851185
// The second statement creates the bindings that the user wrote.
@@ -1189,7 +1189,7 @@ impl LoweringContext<'_> {
11891189
// statement.
11901190
let (move_pat, move_id) = this.pat_ident_binding_mode(
11911191
desugared_span, ident, hir::BindingAnnotation::Mutable);
1192-
let move_expr = this.expr_ident(desugared_span, ident, new_argument_id);
1192+
let move_expr = this.expr_ident(desugared_span, ident, new_parameter_id);
11931193
let move_stmt = this.stmt_let_pat(
11941194
ThinVec::new(),
11951195
desugared_span,
@@ -1199,21 +1199,21 @@ impl LoweringContext<'_> {
11991199
);
12001200

12011201
// Construct the `let <pat> = __argN;` statement. We re-use the original
1202-
// argument's pattern so that `HirId`s are densely assigned.
1202+
// parameter's pattern so that `HirId`s are densely assigned.
12031203
let pattern_expr = this.expr_ident(desugared_span, ident, move_id);
12041204
let pattern_stmt = this.stmt_let_pat(
12051205
stmt_attrs,
12061206
desugared_span,
12071207
Some(P(pattern_expr)),
1208-
argument.pat,
1208+
parameter.pat,
12091209
hir::LocalSource::AsyncFn
12101210
);
12111211

12121212
statements.push(move_stmt);
12131213
statements.push(pattern_stmt);
12141214
};
12151215

1216-
arguments.push(new_argument);
1216+
parameters.push(new_parameter);
12171217
}
12181218

12191219
let async_expr = this.make_async_expr(
@@ -1222,7 +1222,7 @@ impl LoweringContext<'_> {
12221222
let body = this.lower_block_with_stmts(body, false, statements);
12231223
this.expr_block(body, ThinVec::new())
12241224
});
1225-
(HirVec::from(arguments), this.expr(body.span, async_expr, ThinVec::new()))
1225+
(HirVec::from(parameters), this.expr(body.span, async_expr, ThinVec::new()))
12261226
})
12271227
}
12281228

src/librustc/hir/map/collector.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,11 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
363363
self.currently_in_body = prev_in_body;
364364
}
365365

366-
fn visit_arg(&mut self, arg: &'hir Arg) {
367-
let node = Node::Arg(arg);
368-
self.insert(arg.pat.span, arg.hir_id, node);
369-
self.with_parent(arg.hir_id, |this| {
370-
intravisit::walk_arg(this, arg);
366+
fn visit_param(&mut self, param: &'hir Param) {
367+
let node = Node::Param(param);
368+
self.insert(param.pat.span, param.hir_id, node);
369+
self.with_parent(param.hir_id, |this| {
370+
intravisit::walk_param(this, param);
371371
});
372372
}
373373

0 commit comments

Comments
 (0)