Skip to content

Commit

Permalink
Auto merge of #63127 - kper:pr, r=nikomatsakis
Browse files Browse the repository at this point in the history
Cleanup: Consistently use `Param` instead of `Arg` #62426

Fixes #62426
  • Loading branch information
bors committed Aug 28, 2019
2 parents b7178cb + 97319b2 commit bbd48e6
Show file tree
Hide file tree
Showing 56 changed files with 391 additions and 388 deletions.
4 changes: 2 additions & 2 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2231,15 +2231,15 @@ register_diagnostics! {
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
E0566, // conflicting representation hints
E0623, // lifetime mismatch where both parameters are anonymous regions
E0628, // generators cannot have explicit arguments
E0628, // generators cannot have explicit parameters
E0631, // type mismatch in closure arguments
E0637, // "'_" is not a valid lifetime bound
E0657, // `impl Trait` can only capture lifetimes bound at the fn level
E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
E0697, // closures cannot be static
E0707, // multiple elided lifetimes used in arguments of `async fn`
E0708, // `async` non-`move` closures with arguments are not currently supported
E0708, // `async` non-`move` closures with parameters are not currently supported
E0709, // multiple different lifetimes used in arguments of `async fn`
E0710, // an unknown tool name found in scoped lint
E0711, // a feature has been declared with conflicting stability attributes
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ pub trait Visitor<'v> : Sized {
}
}

fn visit_arg(&mut self, arg: &'v Arg) {
walk_arg(self, arg)
fn visit_param(&mut self, param: &'v Param) {
walk_param(self, param)
}

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

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

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

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

pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
Expand Down
28 changes: 14 additions & 14 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,12 @@ impl<'a> LoweringContext<'a> {
&f.generic_params
);
// Mirrors visit::walk_fn_decl
for argument in &f.decl.inputs {
for parameter in &f.decl.inputs {
// We don't lower the ids of argument patterns
self.with_hir_id_owner(None, |this| {
this.visit_pat(&argument.pat);
this.visit_pat(&parameter.pat);
});
self.visit_ty(&argument.ty)
self.visit_ty(&parameter.ty)
}
self.visit_fn_ret_ty(&f.decl.output)
}
Expand Down Expand Up @@ -735,7 +735,7 @@ impl<'a> LoweringContext<'a> {
///
/// Presuming that in-band lifetimes are enabled, then
/// `self.anonymous_lifetime_mode` will be updated to match the
/// argument while `f` is running (and restored afterwards).
/// parameter while `f` is running (and restored afterwards).
fn collect_in_band_defs<T, F>(
&mut self,
parent_id: DefId,
Expand Down Expand Up @@ -880,7 +880,7 @@ impl<'a> LoweringContext<'a> {
///
/// Presuming that in-band lifetimes are enabled, then
/// `self.anonymous_lifetime_mode` will be updated to match the
/// argument while `f` is running (and restored afterwards).
/// parameter while `f` is running (and restored afterwards).
fn add_in_band_defs<F, T>(
&mut self,
generics: &Generics,
Expand Down Expand Up @@ -1080,7 +1080,7 @@ impl<'a> LoweringContext<'a> {
ImplTraitContext::Disallowed(_) if self.is_in_dyn_type =>
(true, ImplTraitContext::OpaqueTy(None)),

// We are in the argument position, but not within a dyn type:
// We are in the parameter position, but not within a dyn type:
//
// fn foo(x: impl Iterator<Item: Debug>)
//
Expand Down Expand Up @@ -1204,7 +1204,7 @@ impl<'a> LoweringContext<'a> {
unsafety: this.lower_unsafety(f.unsafety),
abi: f.abi,
decl: this.lower_fn_decl(&f.decl, None, false, None),
arg_names: this.lower_fn_args_to_names(&f.decl),
param_names: this.lower_fn_params_to_names(&f.decl),
}))
},
)
Expand Down Expand Up @@ -2093,12 +2093,12 @@ impl<'a> LoweringContext<'a> {
}
}

fn lower_fn_args_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
decl.inputs
.iter()
.map(|arg| match arg.pat.node {
.map(|param| match param.pat.node {
PatKind::Ident(_, ident, _) => ident,
_ => Ident::new(kw::Invalid, arg.pat.span),
_ => Ident::new(kw::Invalid, param.pat.span),
})
.collect()
}
Expand Down Expand Up @@ -2136,11 +2136,11 @@ impl<'a> LoweringContext<'a> {
let inputs = self.with_anonymous_lifetime_mode(lt_mode, |this| {
decl.inputs
.iter()
.map(|arg| {
.map(|param| {
if let Some((_, ibty)) = &mut in_band_ty_params {
this.lower_ty_direct(&arg.ty, ImplTraitContext::Universal(ibty))
this.lower_ty_direct(&param.ty, ImplTraitContext::Universal(ibty))
} else {
this.lower_ty_direct(&arg.ty, ImplTraitContext::disallowed())
this.lower_ty_direct(&param.ty, ImplTraitContext::disallowed())
}
})
.collect::<HirVec<_>>()
Expand Down Expand Up @@ -2205,7 +2205,7 @@ impl<'a> LoweringContext<'a> {
//
// type OpaqueTy<generics_from_parent_fn> = impl Future<Output = T>;
//
// `inputs`: lowered types of arguments to the function (used to collect lifetimes)
// `inputs`: lowered types of parameters to the function (used to collect lifetimes)
// `output`: unlowered output type (`T` in `-> T`)
// `fn_def_id`: `DefId` of the parent function (used to create child impl trait definition)
// `opaque_ty_node_id`: `NodeId` of the opaque `impl Trait` type that should be created
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ impl LoweringContext<'_> {
self.sess,
fn_decl_span,
E0628,
"generators cannot have explicit arguments"
"generators cannot have explicit parameters"
);
self.sess.abort_if_errors();
}
Expand Down Expand Up @@ -775,7 +775,7 @@ impl LoweringContext<'_> {
this.sess,
fn_decl_span,
E0708,
"`async` non-`move` closures with arguments are not currently supported",
"`async` non-`move` closures with parameters are not currently supported",
)
.help(
"consider using `let` statements to manually capture \
Expand Down
80 changes: 40 additions & 40 deletions src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ impl LoweringContext<'_> {
(
// Disallow impl Trait in foreign items
this.lower_fn_decl(fdec, None, false, None),
this.lower_fn_args_to_names(fdec),
this.lower_fn_params_to_names(fdec),
)
},
);
Expand Down Expand Up @@ -827,7 +827,7 @@ impl LoweringContext<'_> {
),
),
TraitItemKind::Method(ref sig, None) => {
let names = self.lower_fn_args_to_names(&sig.decl);
let names = self.lower_fn_params_to_names(&sig.decl);
let (generics, sig) = self.lower_method_sig(
&i.generics,
sig,
Expand Down Expand Up @@ -1028,10 +1028,10 @@ impl LoweringContext<'_> {
}
}

fn record_body(&mut self, arguments: HirVec<hir::Arg>, value: hir::Expr) -> hir::BodyId {
fn record_body(&mut self, params: HirVec<hir::Param>, value: hir::Expr) -> hir::BodyId {
let body = hir::Body {
generator_kind: self.generator_kind,
arguments,
params,
value,
};
let id = body.id();
Expand All @@ -1041,21 +1041,21 @@ impl LoweringContext<'_> {

fn lower_body(
&mut self,
f: impl FnOnce(&mut LoweringContext<'_>) -> (HirVec<hir::Arg>, hir::Expr),
f: impl FnOnce(&mut LoweringContext<'_>) -> (HirVec<hir::Param>, hir::Expr),
) -> hir::BodyId {
let prev_gen_kind = self.generator_kind.take();
let (arguments, result) = f(self);
let body_id = self.record_body(arguments, result);
let (parameters, result) = f(self);
let body_id = self.record_body(parameters, result);
self.generator_kind = prev_gen_kind;
body_id
}

fn lower_arg(&mut self, arg: &Arg) -> hir::Arg {
hir::Arg {
attrs: self.lower_attrs(&arg.attrs),
hir_id: self.lower_node_id(arg.id),
pat: self.lower_pat(&arg.pat),
span: arg.span,
fn lower_param(&mut self, param: &Param) -> hir::Param {
hir::Param {
attrs: self.lower_attrs(&param.attrs),
hir_id: self.lower_node_id(param.id),
pat: self.lower_pat(&param.pat),
span: param.span,
}
}

Expand All @@ -1065,7 +1065,7 @@ impl LoweringContext<'_> {
body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr,
) -> hir::BodyId {
self.lower_body(|this| (
decl.inputs.iter().map(|x| this.lower_arg(x)).collect(),
decl.inputs.iter().map(|x| this.lower_param(x)).collect(),
body(this),
))
}
Expand Down Expand Up @@ -1093,10 +1093,10 @@ impl LoweringContext<'_> {
};

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

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

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

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


if is_simple_argument {
if is_simple_parameter {
// If this is the simple case, then we only insert one statement that is
// `let <pat> = <pat>;`. We re-use the original argument's pattern so that
// `HirId`s are densely assigned.
let expr = this.expr_ident(desugared_span, ident, new_argument_id);
let expr = this.expr_ident(desugared_span, ident, new_parameter_id);
let stmt = this.stmt_let_pat(
stmt_attrs,
desugared_span,
Some(P(expr)),
argument.pat,
parameter.pat,
hir::LocalSource::AsyncFn
);
statements.push(stmt);
Expand All @@ -1179,7 +1179,7 @@ impl LoweringContext<'_> {
// let <pat> = __argN;
// ```
//
// The first statement moves the argument into the closure and thus ensures
// The first statement moves the parameter into the closure and thus ensures
// that the drop order is correct.
//
// The second statement creates the bindings that the user wrote.
Expand All @@ -1189,7 +1189,7 @@ impl LoweringContext<'_> {
// statement.
let (move_pat, move_id) = this.pat_ident_binding_mode(
desugared_span, ident, hir::BindingAnnotation::Mutable);
let move_expr = this.expr_ident(desugared_span, ident, new_argument_id);
let move_expr = this.expr_ident(desugared_span, ident, new_parameter_id);
let move_stmt = this.stmt_let_pat(
ThinVec::new(),
desugared_span,
Expand All @@ -1199,21 +1199,21 @@ impl LoweringContext<'_> {
);

// Construct the `let <pat> = __argN;` statement. We re-use the original
// argument's pattern so that `HirId`s are densely assigned.
// parameter's pattern so that `HirId`s are densely assigned.
let pattern_expr = this.expr_ident(desugared_span, ident, move_id);
let pattern_stmt = this.stmt_let_pat(
stmt_attrs,
desugared_span,
Some(P(pattern_expr)),
argument.pat,
parameter.pat,
hir::LocalSource::AsyncFn
);

statements.push(move_stmt);
statements.push(pattern_stmt);
};

arguments.push(new_argument);
parameters.push(new_parameter);
}

let async_expr = this.make_async_expr(
Expand All @@ -1222,7 +1222,7 @@ impl LoweringContext<'_> {
let body = this.lower_block_with_stmts(body, false, statements);
this.expr_block(body, ThinVec::new())
});
(HirVec::from(arguments), this.expr(body.span, async_expr, ThinVec::new()))
(HirVec::from(parameters), this.expr(body.span, async_expr, ThinVec::new()))
})
}

Expand Down
10 changes: 5 additions & 5 deletions src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
self.currently_in_body = prev_in_body;
}

fn visit_arg(&mut self, arg: &'hir Arg) {
let node = Node::Arg(arg);
self.insert(arg.pat.span, arg.hir_id, node);
self.with_parent(arg.hir_id, |this| {
intravisit::walk_arg(this, arg);
fn visit_param(&mut self, param: &'hir Param) {
let node = Node::Param(param);
self.insert(param.pat.span, param.hir_id, node);
self.with_parent(param.hir_id, |this| {
intravisit::walk_param(this, param);
});
}

Expand Down
Loading

0 comments on commit bbd48e6

Please sign in to comment.