Auto merge of #63127 - kper:pr, r=nikomatsakis

Cleanup: Consistently use `Param` instead of `Arg` #62426

Fixes #62426
This commit is contained in:
bors 2019-08-28 03:42:00 +00:00
commit bbd48e6f16
56 changed files with 391 additions and 388 deletions

View File

@ -2231,7 +2231,7 @@ 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
@ -2239,7 +2239,7 @@ register_diagnostics! {
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

View File

@ -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
@ -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);
}
@ -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) {

View File

@ -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)
}
@ -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,
@ -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,
@ -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>)
//
@ -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),
}))
},
)
@ -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()
}
@ -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<_>>()
@ -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

View File

@ -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();
}
@ -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 \

View File

@ -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),
)
},
);
@ -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,
@ -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();
@ -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,
}
}
@ -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),
))
}
@ -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:
@ -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),
_ => {
@ -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);
@ -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.
@ -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,
@ -1199,13 +1199,13 @@ 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
);
@ -1213,7 +1213,7 @@ impl LoweringContext<'_> {
statements.push(pattern_stmt);
};
arguments.push(new_argument);
parameters.push(new_parameter);
}
let async_expr = this.make_async_expr(
@ -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()))
})
}

View File

@ -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);
});
}

View File

@ -360,7 +360,7 @@ impl<'hir> Map<'hir> {
Node::Pat(_) |
Node::Binding(_) |
Node::Local(_) |
Node::Arg(_) |
Node::Param(_) |
Node::Arm(_) |
Node::Lifetime(_) |
Node::Visibility(_) |
@ -964,7 +964,7 @@ impl<'hir> Map<'hir> {
pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] {
self.read(id); // reveals attributes on the node
let attrs = match self.find_entry(id).map(|entry| entry.node) {
Some(Node::Arg(a)) => Some(&a.attrs[..]),
Some(Node::Param(a)) => Some(&a.attrs[..]),
Some(Node::Local(l)) => Some(&l.attrs[..]),
Some(Node::Item(i)) => Some(&i.attrs[..]),
Some(Node::ForeignItem(fi)) => Some(&fi.attrs[..]),
@ -1028,7 +1028,7 @@ impl<'hir> Map<'hir> {
pub fn span(&self, hir_id: HirId) -> Span {
self.read(hir_id); // reveals span from node
match self.find_entry(hir_id).map(|entry| entry.node) {
Some(Node::Arg(arg)) => arg.span,
Some(Node::Param(param)) => param.span,
Some(Node::Item(item)) => item.span,
Some(Node::ForeignItem(foreign_item)) => foreign_item.span,
Some(Node::TraitItem(trait_method)) => trait_method.span,
@ -1223,7 +1223,7 @@ impl<'hir> print::PpAnn for Map<'hir> {
Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)),
Nested::ImplItem(id) => state.print_impl_item(self.impl_item(id)),
Nested::Body(id) => state.print_expr(&self.body(id).value),
Nested::BodyArgPat(id, i) => state.print_pat(&self.body(id).arguments[i].pat)
Nested::BodyParamPat(id, i) => state.print_pat(&self.body(id).params[i].pat)
}
}
}
@ -1231,7 +1231,7 @@ impl<'hir> print::PpAnn for Map<'hir> {
impl<'a> print::State<'a> {
pub fn print_node(&mut self, node: Node<'_>) {
match node {
Node::Arg(a) => self.print_arg(&a),
Node::Param(a) => self.print_param(&a),
Node::Item(a) => self.print_item(&a),
Node::ForeignItem(a) => self.print_foreign_item(&a),
Node::TraitItem(a) => self.print_trait_item(a),
@ -1373,8 +1373,8 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
Some(Node::Pat(_)) => {
format!("pat {}{}", map.hir_to_pretty_string(id), id_str)
}
Some(Node::Arg(_)) => {
format!("arg {}{}", map.hir_to_pretty_string(id), id_str)
Some(Node::Param(_)) => {
format!("param {}{}", map.hir_to_pretty_string(id), id_str)
}
Some(Node::Arm(_)) => {
format!("arm {}{}", map.hir_to_pretty_string(id), id_str)

View File

@ -1030,7 +1030,7 @@ pub enum Mutability {
}
impl Mutability {
/// Returns `MutMutable` only if both arguments are mutable.
/// Returns `MutMutable` only if both `self` and `other` are mutable.
pub fn and(self, other: Self) -> Self {
match self {
MutMutable => other,
@ -1324,7 +1324,7 @@ pub struct BodyId {
///
/// Here, the `Body` associated with `foo()` would contain:
///
/// - an `arguments` array containing the `(x, y)` pattern
/// - an `params` array containing the `(x, y)` pattern
/// - a `value` containing the `x + y` expression (maybe wrapped in a block)
/// - `generator_kind` would be `None`
///
@ -1332,7 +1332,7 @@ pub struct BodyId {
/// map using `body_owner_def_id()`.
#[derive(RustcEncodable, RustcDecodable, Debug)]
pub struct Body {
pub arguments: HirVec<Arg>,
pub params: HirVec<Param>,
pub value: Expr,
pub generator_kind: Option<GeneratorKind>,
}
@ -1644,7 +1644,7 @@ pub enum LocalSource {
/// A desugared `for _ in _ { .. }` loop.
ForLoopDesugar,
/// When lowering async functions, we create locals within the `async move` so that
/// all arguments are dropped after the future is polled.
/// all parameters are dropped after the future is polled.
///
/// ```ignore (pseudo-Rust)
/// async fn foo(<pattern> @ x: Type) {
@ -1940,7 +1940,7 @@ pub struct BareFnTy {
pub abi: Abi,
pub generic_params: HirVec<GenericParam>,
pub decl: P<FnDecl>,
pub arg_names: HirVec<Ident>,
pub param_names: HirVec<Ident>,
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
@ -2027,9 +2027,9 @@ pub struct InlineAsm {
pub dialect: AsmDialect,
}
/// Represents an argument in a function header.
/// Represents a parameter in a function header.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct Arg {
pub struct Param {
pub attrs: HirVec<Attribute>,
pub hir_id: HirId,
pub pat: P<Pat>,
@ -2039,9 +2039,9 @@ pub struct Arg {
/// Represents the header (not the body) of a function declaration.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct FnDecl {
/// The types of the function's arguments.
/// The types of the function's parameters.
///
/// Additional argument data is stored in the function's [body](Body::arguments).
/// Additional argument data is stored in the function's [body](Body::parameters).
pub inputs: HirVec<Ty>,
pub output: FunctionRetTy,
pub c_variadic: bool,
@ -2721,7 +2721,7 @@ impl CodegenFnAttrs {
#[derive(Copy, Clone, Debug)]
pub enum Node<'hir> {
Arg(&'hir Arg),
Param(&'hir Param),
Item(&'hir Item),
ForeignItem(&'hir ForeignItem),
TraitItem(&'hir TraitItem),

View File

@ -33,7 +33,7 @@ pub enum Nested {
TraitItem(hir::TraitItemId),
ImplItem(hir::ImplItemId),
Body(hir::BodyId),
BodyArgPat(hir::BodyId, usize)
BodyParamPat(hir::BodyId, usize)
}
pub trait PpAnn {
@ -62,7 +62,7 @@ impl PpAnn for hir::Crate {
Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)),
Nested::ImplItem(id) => state.print_impl_item(self.impl_item(id)),
Nested::Body(id) => state.print_expr(&self.body(id).value),
Nested::BodyArgPat(id, i) => state.print_pat(&self.body(id).arguments[i].pat)
Nested::BodyParamPat(id, i) => state.print_pat(&self.body(id).params[i].pat)
}
}
}
@ -318,7 +318,7 @@ impl<'a> State<'a> {
}
hir::TyKind::BareFn(ref f) => {
self.print_ty_fn(f.abi, f.unsafety, &f.decl, None, &f.generic_params,
&f.arg_names[..]);
&f.param_names[..]);
}
hir::TyKind::Def(..) => {},
hir::TyKind::Path(ref qpath) => {
@ -1290,7 +1290,7 @@ impl<'a> State<'a> {
hir::ExprKind::Closure(capture_clause, ref decl, body, _fn_decl_span, _gen) => {
self.print_capture_clause(capture_clause);
self.print_closure_args(&decl, body);
self.print_closure_params(&decl, body);
self.s.space();
// this is a bare expression
@ -1775,7 +1775,7 @@ impl<'a> State<'a> {
self.ann.post(self, AnnNode::Pat(pat))
}
pub fn print_arg(&mut self, arg: &hir::Arg) {
pub fn print_param(&mut self, arg: &hir::Param) {
self.print_outer_attributes(&arg.attrs);
self.print_pat(&arg.pat);
}
@ -1864,7 +1864,7 @@ impl<'a> State<'a> {
s.s.word(":");
s.s.space();
} else if let Some(body_id) = body_id {
s.ann.nested(s, Nested::BodyArgPat(body_id, i));
s.ann.nested(s, Nested::BodyParamPat(body_id, i));
s.s.word(":");
s.s.space();
}
@ -1881,13 +1881,13 @@ impl<'a> State<'a> {
self.print_where_clause(&generics.where_clause)
}
fn print_closure_args(&mut self, decl: &hir::FnDecl, body_id: hir::BodyId) {
fn print_closure_params(&mut self, decl: &hir::FnDecl, body_id: hir::BodyId) {
self.s.word("|");
let mut i = 0;
self.commasep(Inconsistent, &decl.inputs, |s, ty| {
s.ibox(INDENT_UNIT);
s.ann.nested(s, Nested::BodyArgPat(body_id, i));
s.ann.nested(s, Nested::BodyParamPat(body_id, i));
i += 1;
if let hir::TyKind::Infer = ty.node {

View File

@ -331,13 +331,13 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Body {
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let hir::Body {
arguments,
params,
value,
generator_kind,
} = self;
hcx.with_node_id_hashing_mode(NodeIdHashingMode::Ignore, |hcx| {
arguments.hash_stable(hcx, hasher);
params.hash_stable(hcx, hasher);
value.hash_stable(hcx, hasher);
generator_kind.hash_stable(hcx, hasher);
});

View File

@ -78,12 +78,12 @@ impl<'a, 'tcx> Visitor<'tcx> for FindLocalByTypeVisitor<'a, 'tcx> {
}
fn visit_body(&mut self, body: &'tcx Body) {
for argument in &body.arguments {
for param in &body.params {
if let (None, Some(ty)) = (
self.found_arg_pattern,
self.node_matches_type(argument.hir_id),
self.node_matches_type(param.hir_id),
) {
self.found_arg_pattern = Some(&*argument.pat);
self.found_arg_pattern = Some(&*param.pat);
self.found_ty = Some(ty);
}
}

View File

@ -2,7 +2,7 @@
//! where both the regions are anonymous.
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::infer::error_reporting::nice_region_error::util::AnonymousArgInfo;
use crate::infer::error_reporting::nice_region_error::util::AnonymousParamInfo;
use crate::util::common::ErrorReported;
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
@ -59,13 +59,13 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let ty_sub = self.find_anon_type(sub, &bregion_sub)?;
debug!(
"try_report_anon_anon_conflict: found_arg1={:?} sup={:?} br1={:?}",
"try_report_anon_anon_conflict: found_param1={:?} sup={:?} br1={:?}",
ty_sub,
sup,
bregion_sup
);
debug!(
"try_report_anon_anon_conflict: found_arg2={:?} sub={:?} br2={:?}",
"try_report_anon_anon_conflict: found_param2={:?} sub={:?} br2={:?}",
ty_sup,
sub,
bregion_sub
@ -74,24 +74,24 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let (ty_sup, ty_fndecl_sup) = ty_sup;
let (ty_sub, ty_fndecl_sub) = ty_sub;
let AnonymousArgInfo {
arg: anon_arg_sup, ..
} = self.find_arg_with_region(sup, sup)?;
let AnonymousArgInfo {
arg: anon_arg_sub, ..
} = self.find_arg_with_region(sub, sub)?;
let AnonymousParamInfo {
param: anon_param_sup, ..
} = self.find_param_with_region(sup, sup)?;
let AnonymousParamInfo {
param: anon_param_sub, ..
} = self.find_param_with_region(sub, sub)?;
let sup_is_ret_type =
self.is_return_type_anon(scope_def_id_sup, bregion_sup, ty_fndecl_sup);
let sub_is_ret_type =
self.is_return_type_anon(scope_def_id_sub, bregion_sub, ty_fndecl_sub);
let span_label_var1 = match anon_arg_sup.pat.simple_ident() {
let span_label_var1 = match anon_param_sup.pat.simple_ident() {
Some(simple_ident) => format!(" from `{}`", simple_ident),
None => String::new(),
};
let span_label_var2 = match anon_arg_sub.pat.simple_ident() {
let span_label_var2 = match anon_param_sub.pat.simple_ident() {
Some(simple_ident) => format!(" into `{}`", simple_ident),
None => String::new(),
};

View File

@ -6,7 +6,7 @@ use crate::ty;
use errors::{Applicability, DiagnosticBuilder};
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
/// When given a `ConcreteFailure` for a function with parameters containing a named region and
/// an anonymous region, emit an descriptive diagnostic error.
pub(super) fn try_report_named_anon_conflict(&self) -> Option<DiagnosticBuilder<'a>> {
let (span, sub, sup) = self.get_regions();
@ -24,23 +24,23 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
// only introduced anonymous regions in parameters) as well as a
// version new_ty of its type where the anonymous region is replaced
// with the named one.//scope_def_id
let (named, anon, anon_arg_info, region_info) = if self.is_named_region(sub)
let (named, anon, anon_param_info, region_info) = if self.is_named_region(sub)
&& self.tcx().is_suitable_region(sup).is_some()
&& self.find_arg_with_region(sup, sub).is_some()
&& self.find_param_with_region(sup, sub).is_some()
{
(
sub,
sup,
self.find_arg_with_region(sup, sub).unwrap(),
self.find_param_with_region(sup, sub).unwrap(),
self.tcx().is_suitable_region(sup).unwrap(),
)
} else if self.is_named_region(sup) && self.tcx().is_suitable_region(sub).is_some()
&& self.find_arg_with_region(sub, sup).is_some()
&& self.find_param_with_region(sub, sup).is_some()
{
(
sup,
sub,
self.find_arg_with_region(sub, sup).unwrap(),
self.find_param_with_region(sub, sup).unwrap(),
self.tcx().is_suitable_region(sub).unwrap(),
)
} else {
@ -49,20 +49,20 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
debug!("try_report_named_anon_conflict: named = {:?}", named);
debug!(
"try_report_named_anon_conflict: anon_arg_info = {:?}",
anon_arg_info
"try_report_named_anon_conflict: anon_param_info = {:?}",
anon_param_info
);
debug!(
"try_report_named_anon_conflict: region_info = {:?}",
region_info
);
let (arg, new_ty, new_ty_span, br, is_first, scope_def_id, is_impl_item) = (
anon_arg_info.arg,
anon_arg_info.arg_ty,
anon_arg_info.arg_ty_span,
anon_arg_info.bound_region,
anon_arg_info.is_first,
let (param, new_ty, new_ty_span, br, is_first, scope_def_id, is_impl_item) = (
anon_param_info.param,
anon_param_info.param_ty,
anon_param_info.param_ty_span,
anon_param_info.bound_region,
anon_param_info.is_first,
region_info.def_id,
region_info.is_impl_item,
);
@ -95,7 +95,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
}
}
let (error_var, span_label_var) = match arg.pat.simple_ident() {
let (error_var, span_label_var) = match param.pat.simple_ident() {
Some(simple_ident) => (
format!("the type of `{}`", simple_ident),
format!("the type of `{}`", simple_ident),

View File

@ -10,37 +10,37 @@ use syntax_pos::Span;
// The struct contains the information about the anonymous region
// we are searching for.
#[derive(Debug)]
pub(super) struct AnonymousArgInfo<'tcx> {
// the argument corresponding to the anonymous region
pub arg: &'tcx hir::Arg,
// the type corresponding to the anonymopus region argument
pub arg_ty: Ty<'tcx>,
pub(super) struct AnonymousParamInfo<'tcx> {
// the parameter corresponding to the anonymous region
pub param: &'tcx hir::Param,
// the type corresponding to the anonymopus region parameter
pub param_ty: Ty<'tcx>,
// the ty::BoundRegion corresponding to the anonymous region
pub bound_region: ty::BoundRegion,
// arg_ty_span contains span of argument type
pub arg_ty_span : Span,
// param_ty_span contains span of parameter type
pub param_ty_span : Span,
// corresponds to id the argument is the first parameter
// in the declaration
pub is_first: bool,
}
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
// This method walks the Type of the function body arguments using
// This method walks the Type of the function body parameters using
// `fold_regions()` function and returns the
// &hir::Arg of the function argument corresponding to the anonymous
// &hir::Param of the function parameter corresponding to the anonymous
// region and the Ty corresponding to the named region.
// Currently only the case where the function declaration consists of
// one named region and one anonymous region is handled.
// Consider the example `fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32`
// Here, we would return the hir::Arg for y, we return the type &'a
// Here, we would return the hir::Param for y, we return the type &'a
// i32, which is the type of y but with the anonymous region replaced
// with 'a, the corresponding bound region and is_first which is true if
// the hir::Arg is the first argument in the function declaration.
pub(super) fn find_arg_with_region(
// the hir::Param is the first parameter in the function declaration.
pub(super) fn find_param_with_region(
&self,
anon_region: Region<'tcx>,
replace_region: Region<'tcx>,
) -> Option<AnonymousArgInfo<'_>> {
) -> Option<AnonymousParamInfo<'_>> {
let (id, bound_region) = match *anon_region {
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
ty::ReEarlyBound(ebr) => (
@ -57,16 +57,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let owner_id = hir.body_owner(body_id);
let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap();
if let Some(tables) = self.tables {
body.arguments
body.params
.iter()
.enumerate()
.filter_map(|(index, arg)| {
.filter_map(|(index, param)| {
// May return None; sometimes the tables are not yet populated.
let ty_hir_id = fn_decl.inputs[index].hir_id;
let arg_ty_span = hir.span(ty_hir_id);
let ty = tables.node_type_opt(arg.hir_id)?;
let param_ty_span = hir.span(ty_hir_id);
let ty = tables.node_type_opt(param.hir_id)?;
let mut found_anon_region = false;
let new_arg_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| {
let new_param_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| {
if *r == *anon_region {
found_anon_region = true;
replace_region
@ -76,10 +76,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
});
if found_anon_region {
let is_first = index == 0;
Some(AnonymousArgInfo {
arg: arg,
arg_ty: new_arg_ty,
arg_ty_span : arg_ty_span,
Some(AnonymousParamInfo {
param: param,
param_ty: new_param_ty,
param_ty_span : param_ty_span,
bound_region: bound_region,
is_first: is_first,
})

View File

@ -966,10 +966,10 @@ for LateContextAndPass<'a, 'tcx, T> {
self.context.tables = old_tables;
}
fn visit_arg(&mut self, arg: &'tcx hir::Arg) {
self.with_lint_attrs(arg.hir_id, &arg.attrs, |cx| {
lint_callback!(cx, check_arg, arg);
hir_visit::walk_arg(cx, arg);
fn visit_param(&mut self, param: &'tcx hir::Param) {
self.with_lint_attrs(param.hir_id, &param.attrs, |cx| {
lint_callback!(cx, check_param, param);
hir_visit::walk_param(cx, param);
});
}
@ -1163,10 +1163,10 @@ for LateContextAndPass<'a, 'tcx, T> {
}
impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T> {
fn visit_arg(&mut self, arg: &'a ast::Arg) {
self.with_lint_attrs(arg.id, &arg.attrs, |cx| {
run_early_pass!(cx, check_arg, arg);
ast_visit::walk_arg(cx, arg);
fn visit_param(&mut self, param: &'a ast::Param) {
self.with_lint_attrs(param.id, &param.attrs, |cx| {
run_early_pass!(cx, check_param, param);
ast_visit::walk_param(cx, param);
});
}

View File

@ -206,7 +206,7 @@ macro_rules! declare_lint_pass {
macro_rules! late_lint_methods {
($macro:path, $args:tt, [$hir:tt]) => (
$macro!($args, [$hir], [
fn check_arg(a: &$hir hir::Arg);
fn check_param(a: &$hir hir::Param);
fn check_body(a: &$hir hir::Body);
fn check_body_post(a: &$hir hir::Body);
fn check_name(a: Span, b: ast::Name);
@ -349,7 +349,7 @@ macro_rules! declare_combined_late_lint_pass {
macro_rules! early_lint_methods {
($macro:path, $args:tt) => (
$macro!($args, [
fn check_arg(a: &ast::Arg);
fn check_param(a: &ast::Param);
fn check_ident(a: ast::Ident);
fn check_crate(a: &ast::Crate);
fn check_crate_post(a: &ast::Crate);
@ -792,9 +792,9 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'tcx> {
intravisit::NestedVisitorMap::All(&self.tcx.hir())
}
fn visit_arg(&mut self, arg: &'tcx hir::Arg) {
self.with_lint_attrs(arg.hir_id, &arg.attrs, |builder| {
intravisit::walk_arg(builder, arg);
fn visit_param(&mut self, param: &'tcx hir::Param) {
self.with_lint_attrs(param.hir_id, &param.attrs, |builder| {
intravisit::walk_param(builder, param);
});
}

View File

@ -313,9 +313,9 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
pub fn consume_body(&mut self, body: &hir::Body) {
debug!("consume_body(body={:?})", body);
for arg in &body.arguments {
let arg_ty = return_if_err!(self.mc.pat_ty_adjusted(&arg.pat));
debug!("consume_body: arg_ty = {:?}", arg_ty);
for param in &body.params {
let param_ty = return_if_err!(self.mc.pat_ty_adjusted(&param.pat));
debug!("consume_body: param_ty = {:?}", param_ty);
let fn_body_scope_r =
self.tcx().mk_region(ty::ReScope(
@ -323,13 +323,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
id: body.value.hir_id.local_id,
data: region::ScopeData::Node
}));
let arg_cmt = Rc::new(self.mc.cat_rvalue(
arg.hir_id,
arg.pat.span,
fn_body_scope_r, // Args live only as long as the fn body.
arg_ty));
let param_cmt = Rc::new(self.mc.cat_rvalue(
param.hir_id,
param.pat.span,
fn_body_scope_r, // Parameters live only as long as the fn body.
param_ty));
self.walk_irrefutable_pat(arg_cmt, &arg.pat);
self.walk_irrefutable_pat(param_cmt, &param.pat);
}
self.consume_expr(&body.value);

View File

@ -242,7 +242,7 @@ struct LocalInfo {
#[derive(Copy, Clone, Debug)]
enum VarKind {
Arg(HirId, ast::Name),
Param(HirId, ast::Name),
Local(LocalInfo),
CleanExit
}
@ -298,7 +298,7 @@ impl IrMaps<'tcx> {
self.num_vars += 1;
match vk {
Local(LocalInfo { id: node_id, .. }) | Arg(node_id, _) => {
Local(LocalInfo { id: node_id, .. }) | Param(node_id, _) => {
self.variable_map.insert(node_id, v);
},
CleanExit => {}
@ -320,7 +320,7 @@ impl IrMaps<'tcx> {
fn variable_name(&self, var: Variable) -> String {
match self.var_kinds[var.get()] {
Local(LocalInfo { name, .. }) | Arg(_, name) => {
Local(LocalInfo { name, .. }) | Param(_, name) => {
name.to_string()
},
CleanExit => "<clean-exit>".to_owned()
@ -330,7 +330,7 @@ impl IrMaps<'tcx> {
fn variable_is_shorthand(&self, var: Variable) -> bool {
match self.var_kinds[var.get()] {
Local(LocalInfo { is_shorthand, .. }) => is_shorthand,
Arg(..) | CleanExit => false
Param(..) | CleanExit => false
}
}
@ -371,13 +371,13 @@ fn visit_fn<'tcx>(
let body = ir.tcx.hir().body(body_id);
for arg in &body.arguments {
let is_shorthand = match arg.pat.node {
for param in &body.params {
let is_shorthand = match param.pat.node {
crate::hir::PatKind::Struct(..) => true,
_ => false,
};
arg.pat.each_binding(|_bm, hir_id, _x, ident| {
debug!("adding argument {:?}", hir_id);
param.pat.each_binding(|_bm, hir_id, _x, ident| {
debug!("adding parameters {:?}", hir_id);
let var = if is_shorthand {
Local(LocalInfo {
id: hir_id,
@ -385,7 +385,7 @@ fn visit_fn<'tcx>(
is_shorthand: true,
})
} else {
Arg(hir_id, ident.name)
Param(hir_id, ident.name)
};
fn_maps.add_variable(var);
})
@ -1525,8 +1525,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
fn warn_about_unused_args(&self, body: &hir::Body, entry_ln: LiveNode) {
for arg in &body.arguments {
arg.pat.each_binding(|_bm, hir_id, _, ident| {
for param in &body.params {
param.pat.each_binding(|_bm, hir_id, _, ident| {
let sp = ident.span;
let var = self.variable(hir_id, sp);
// Ignore unused self.

View File

@ -1383,8 +1383,8 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
// The arguments and `self` are parented to the fn.
self.cx.var_parent = self.cx.parent.take();
for argument in &body.arguments {
self.visit_pat(&argument.pat);
for param in &body.params {
self.visit_pat(&param.pat);
}
// The body of the every fn is a root scope.

View File

@ -2557,7 +2557,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
} = info;
let help_name = if let Some(ident) = parent.and_then(|body| {
self.tcx.hir().body(body).arguments[index].pat.simple_ident()
self.tcx.hir().body(body).params[index].pat.simple_ident()
}) {
format!("`{}`", ident)
} else {

View File

@ -1044,7 +1044,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
node: hir::ExprKind::Closure(_, ref _decl, id, span, _),
..
}) => {
(self.tcx.sess.source_map().def_span(span), self.tcx.hir().body(id).arguments.iter()
(self.tcx.sess.source_map().def_span(span),
self.tcx.hir().body(id).params.iter()
.map(|arg| {
if let hir::Pat {
node: hir::PatKind::Tuple(ref args, _),

View File

@ -186,8 +186,8 @@ fn build_local_id_to_index(body: Option<&hir::Body>,
index: &'a mut FxHashMap<hir::ItemLocalId, Vec<CFGIndex>>,
}
let mut formals = Formals { entry: entry, index: index };
for arg in &body.arguments {
formals.visit_pat(&arg.pat);
for param in &body.params {
formals.visit_pat(&param.pat);
}
impl<'a, 'v> Visitor<'v> for Formals<'a> {
fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'v> {

View File

@ -164,7 +164,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
// a `fn` when encoding, so the dep-tracking wouldn't work.
// This is only used by rustdoc anyway, which shouldn't have
// incremental recompilation ever enabled.
fn_arg_names => { cdata.get_fn_arg_names(def_id.index) }
fn_arg_names => { cdata.get_fn_param_names(def_id.index) }
rendered_const => { cdata.get_rendered_const(def_id.index) }
impl_parent => { cdata.get_parent_impl(def_id.index) }
trait_of_item => { cdata.get_trait_of_item(def_id.index) }

View File

@ -1135,14 +1135,14 @@ impl<'a, 'tcx> CrateMetadata {
}
}
pub fn get_fn_arg_names(&self, id: DefIndex) -> Vec<ast::Name> {
let arg_names = match self.entry(id).kind {
pub fn get_fn_param_names(&self, id: DefIndex) -> Vec<ast::Name> {
let param_names = match self.entry(id).kind {
EntryKind::Fn(data) |
EntryKind::ForeignFn(data) => data.decode(self).arg_names,
EntryKind::Method(data) => data.decode(self).fn_data.arg_names,
EntryKind::ForeignFn(data) => data.decode(self).param_names,
EntryKind::Method(data) => data.decode(self).fn_data.param_names,
_ => Lazy::empty(),
};
arg_names.decode(self).collect()
param_names.decode(self).collect()
}
pub fn exported_symbols(

View File

@ -869,18 +869,18 @@ impl EncodeContext<'tcx> {
}
ty::AssocKind::Method => {
let fn_data = if let hir::TraitItemKind::Method(_, ref m) = ast_item.node {
let arg_names = match *m {
let param_names = match *m {
hir::TraitMethod::Required(ref names) => {
self.encode_fn_arg_names(names)
self.encode_fn_param_names(names)
}
hir::TraitMethod::Provided(body) => {
self.encode_fn_arg_names_for_body(body)
self.encode_fn_param_names_for_body(body)
}
};
FnData {
constness: hir::Constness::NotConst,
arg_names,
sig: self.lazy(tcx.fn_sig(def_id)),
param_names,
sig: self.lazy(&tcx.fn_sig(def_id)),
}
} else {
bug!()
@ -976,8 +976,8 @@ impl EncodeContext<'tcx> {
let fn_data = if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
FnData {
constness: sig.header.constness,
arg_names: self.encode_fn_arg_names_for_body(body),
sig: self.lazy(tcx.fn_sig(def_id)),
param_names: self.encode_fn_param_names_for_body(body),
sig: self.lazy(&tcx.fn_sig(def_id)),
}
} else {
bug!()
@ -1033,11 +1033,11 @@ impl EncodeContext<'tcx> {
}
}
fn encode_fn_arg_names_for_body(&mut self, body_id: hir::BodyId)
fn encode_fn_param_names_for_body(&mut self, body_id: hir::BodyId)
-> Lazy<[ast::Name]> {
self.tcx.dep_graph.with_ignore(|| {
let body = self.tcx.hir().body(body_id);
self.lazy(body.arguments.iter().map(|arg| {
self.lazy(body.params.iter().map(|arg| {
match arg.pat.node {
PatKind::Binding(_, _, ident, _) => ident.name,
_ => kw::Invalid,
@ -1046,7 +1046,7 @@ impl EncodeContext<'tcx> {
})
}
fn encode_fn_arg_names(&mut self, param_names: &[ast::Ident]) -> Lazy<[ast::Name]> {
fn encode_fn_param_names(&mut self, param_names: &[ast::Ident]) -> Lazy<[ast::Name]> {
self.lazy(param_names.iter().map(|ident| ident.name))
}
@ -1122,7 +1122,7 @@ impl EncodeContext<'tcx> {
hir::ItemKind::Fn(_, header, .., body) => {
let data = FnData {
constness: header.constness,
arg_names: self.encode_fn_arg_names_for_body(body),
param_names: self.encode_fn_param_names_for_body(body),
sig: self.lazy(tcx.fn_sig(def_id)),
};
@ -1663,7 +1663,7 @@ impl EncodeContext<'tcx> {
hir::ForeignItemKind::Fn(_, ref names, _) => {
let data = FnData {
constness: hir::Constness::NotConst,
arg_names: self.encode_fn_arg_names(names),
param_names: self.encode_fn_param_names(names),
sig: self.lazy(tcx.fn_sig(def_id)),
};
EntryKind::ForeignFn(self.lazy(data))

View File

@ -295,7 +295,7 @@ pub struct MacroDef {
#[derive(RustcEncodable, RustcDecodable)]
pub struct FnData<'tcx> {
pub constness: hir::Constness,
pub arg_names: Lazy<[ast::Name]>,
pub param_names: Lazy<[ast::Name]>,
pub sig: Lazy<ty::PolyFnSig<'tcx>>,
}

View File

@ -94,7 +94,7 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> {
let body = tcx.hir().body(body_id);
let explicit_arguments =
body.arguments
body.params
.iter()
.enumerate()
.map(|(index, arg)| {
@ -511,7 +511,7 @@ fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: DefId, abi: Abi) -> bool {
///////////////////////////////////////////////////////////////////////////
/// the main entry point for building MIR for a function
struct ArgInfo<'tcx>(Ty<'tcx>, Option<Span>, Option<&'tcx hir::Arg>, Option<ImplicitSelfKind>);
struct ArgInfo<'tcx>(Ty<'tcx>, Option<Span>, Option<&'tcx hir::Param>, Option<ImplicitSelfKind>);
fn construct_fn<'a, 'tcx, A>(
hir: Cx<'a, 'tcx>,

View File

@ -91,9 +91,9 @@ impl<'a, 'tcx> Visitor<'tcx> for MatchVisitor<'a, 'tcx> {
fn visit_body(&mut self, body: &'tcx hir::Body) {
intravisit::walk_body(self, body);
for arg in &body.arguments {
self.check_irrefutable(&arg.pat, "function argument");
self.check_patterns(false, slice::from_ref(&arg.pat));
for param in &body.params {
self.check_irrefutable(&param.pat, "function argument");
self.check_patterns(false, slice::from_ref(&param.pat));
}
}
}

View File

@ -94,9 +94,9 @@ impl<'k> StatCollector<'k> {
}
impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
fn visit_arg(&mut self, arg: &'v hir::Arg) {
self.record("Arg", Id::Node(arg.hir_id), arg);
hir_visit::walk_arg(self, arg)
fn visit_param(&mut self, param: &'v hir::Param) {
self.record("Param", Id::Node(param.hir_id), param);
hir_visit::walk_param(self, param)
}
fn nested_visit_map<'this>(&'this mut self) -> hir_visit::NestedVisitorMap<'this, 'v> {

View File

@ -230,7 +230,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
}
}
fn process_formals(&mut self, formals: &'l [ast::Arg], qualname: &str) {
fn process_formals(&mut self, formals: &'l [ast::Param], qualname: &str) {
for arg in formals {
self.visit_pat(&arg.pat);
let mut collector = PathCollector::new();

View File

@ -32,7 +32,7 @@ use syntax::source_map::Spanned;
use syntax::parse::lexer::comments::strip_doc_comment_decoration;
use syntax::print::pprust;
use syntax::visit::{self, Visitor};
use syntax::print::pprust::{arg_to_string, ty_to_string};
use syntax::print::pprust::{param_to_string, ty_to_string};
use syntax_pos::*;
use dump_visitor::DumpVisitor;
@ -934,7 +934,7 @@ fn make_signature(decl: &ast::FnDecl, generics: &ast::Generics) -> String {
sig.push('(');
sig.push_str(&decl.inputs
.iter()
.map(arg_to_string)
.map(param_to_string)
.collect::<Vec<_>>()
.join(", "));
sig.push(')');

View File

@ -224,13 +224,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// fn takes_ref(_: &Foo) {}
/// let ref opt = Some(Foo);
///
/// opt.map(|arg| takes_ref(arg));
/// opt.map(|param| takes_ref(param));
/// ```
/// Suggest using `opt.as_ref().map(|arg| takes_ref(arg));` instead.
/// Suggest using `opt.as_ref().map(|param| takes_ref(param));` instead.
///
/// It only checks for `Option` and `Result` and won't work with
/// ```
/// opt.map(|arg| { takes_ref(arg) });
/// opt.map(|param| { takes_ref(param) });
/// ```
fn can_use_as_ref(
&self,
@ -247,13 +247,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
let local_parent = self.tcx.hir().get_parent_node(local_id);
let arg_hir_id = match self.tcx.hir().find(local_parent) {
Some(Node::Arg(hir::Arg { hir_id, .. })) => hir_id,
let param_hir_id = match self.tcx.hir().find(local_parent) {
Some(Node::Param(hir::Param { hir_id, .. })) => hir_id,
_ => return None
};
let arg_parent = self.tcx.hir().get_parent_node(*arg_hir_id);
let (expr_hir_id, closure_fn_decl) = match self.tcx.hir().find(arg_parent) {
let param_parent = self.tcx.hir().get_parent_node(*param_hir_id);
let (expr_hir_id, closure_fn_decl) = match self.tcx.hir().find(param_parent) {
Some(Node::Expr(
hir::Expr { hir_id, node: hir::ExprKind::Closure(_, decl, ..), .. }
)) => (hir_id, decl),

View File

@ -1102,19 +1102,19 @@ fn check_fn<'a, 'tcx>(
GatherLocalsVisitor { fcx: &fcx, parent_id: outer_hir_id, }.visit_body(body);
// Add formal parameters.
for (arg_ty, arg) in fn_sig.inputs().iter().zip(&body.arguments) {
for (param_ty, param) in fn_sig.inputs().iter().zip(&body.params) {
// Check the pattern.
fcx.check_pat_top(&arg.pat, arg_ty, None);
fcx.check_pat_top(&param.pat, param_ty, None);
// Check that argument is Sized.
// The check for a non-trivial pattern is a hack to avoid duplicate warnings
// for simple cases like `fn foo(x: Trait)`,
// where we would error once on the parameter as a whole, and once on the binding `x`.
if arg.pat.simple_ident().is_none() && !fcx.tcx.features().unsized_locals {
fcx.require_type_is_sized(arg_ty, decl.output.span(), traits::SizedArgumentType);
if param.pat.simple_ident().is_none() && !fcx.tcx.features().unsized_locals {
fcx.require_type_is_sized(param_ty, decl.output.span(), traits::SizedArgumentType);
}
fcx.write_ty(arg.hir_id, arg_ty);
fcx.write_ty(param.hir_id, param_ty);
}
inherited.tables.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig);
@ -3952,8 +3952,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
..
})) => {
let body = hir.body(*body_id);
sugg_call = body.arguments.iter()
.map(|arg| match &arg.pat.node {
sugg_call = body.params.iter()
.map(|param| match &param.pat.node {
hir::PatKind::Binding(_, _, ident, None)
if ident.name != kw::SelfLower => ident.to_string(),
_ => "_".to_string(),
@ -3970,8 +3970,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_label(*closure_span, "closure defined here");
msg = "call this closure";
let body = hir.body(*body_id);
sugg_call = body.arguments.iter()
.map(|arg| match &arg.pat.node {
sugg_call = body.params.iter()
.map(|param| match &param.pat.node {
hir::PatKind::Binding(_, _, ident, None)
if ident.name != kw::SelfLower => ident.to_string(),
_ => "_".to_string(),

View File

@ -468,7 +468,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let binding_parent = tcx.hir().get(binding_parent_id);
debug!("inner {:?} pat {:?} parent {:?}", inner, pat, binding_parent);
match binding_parent {
hir::Node::Arg(hir::Arg { span, .. }) => {
hir::Node::Param(hir::Param { span, .. }) => {
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(inner.span) {
err.span_suggestion(
*span,

View File

@ -347,12 +347,12 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
);
self.outlives_environment
.save_implied_bounds(body_id.hir_id);
self.link_fn_args(
self.link_fn_params(
region::Scope {
id: body.value.hir_id.local_id,
data: region::ScopeData::Node,
},
&body.arguments,
&body.params,
);
self.visit_body(body);
self.visit_region_obligations(body_id.hir_id);
@ -1078,16 +1078,16 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
/// Computes the guarantors for any ref bindings in a match and
/// then ensures that the lifetime of the resulting pointer is
/// linked to the lifetime of its guarantor (if any).
fn link_fn_args(&self, body_scope: region::Scope, args: &[hir::Arg]) {
debug!("regionck::link_fn_args(body_scope={:?})", body_scope);
for arg in args {
let arg_ty = self.node_ty(arg.hir_id);
fn link_fn_params(&self, body_scope: region::Scope, params: &[hir::Param]) {
debug!("regionck::link_fn_params(body_scope={:?})", body_scope);
for param in params {
let param_ty = self.node_ty(param.hir_id);
let re_scope = self.tcx.mk_region(ty::ReScope(body_scope));
let arg_cmt = self.with_mc(|mc| {
Rc::new(mc.cat_rvalue(arg.hir_id, arg.pat.span, re_scope, arg_ty))
let param_cmt = self.with_mc(|mc| {
Rc::new(mc.cat_rvalue(param.hir_id, param.pat.span, re_scope, param_ty))
});
debug!("arg_ty={:?} arg_cmt={:?} arg={:?}", arg_ty, arg_cmt, arg);
self.link_pattern(arg_cmt, &arg.pat);
debug!("param_ty={:?} param_cmt={:?} param={:?}", param_ty, param_cmt, param);
self.link_pattern(param_cmt, &param.pat);
}
}

View File

@ -39,8 +39,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let rustc_dump_user_substs = self.tcx.has_attr(item_def_id, sym::rustc_dump_user_substs);
let mut wbcx = WritebackCx::new(self, body, rustc_dump_user_substs);
for arg in &body.arguments {
wbcx.visit_node_id(arg.pat.span, arg.hir_id);
for param in &body.params {
wbcx.visit_node_id(param.pat.span, param.hir_id);
}
// Type only exists for constants and statics, not functions.
match self.tcx.hir().body_owner_kind(item_id) {
@ -245,8 +245,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
match e.node {
hir::ExprKind::Closure(_, _, body, _, _) => {
let body = self.fcx.tcx.hir().body(body);
for arg in &body.arguments {
self.visit_node_id(e.span, arg.hir_id);
for param in &body.params {
self.visit_node_id(e.span, param.hir_id);
}
self.visit_body(body);

View File

@ -2095,7 +2095,7 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty], hir::BodyId) {
Arguments {
values: self.0.iter().enumerate().map(|(i, ty)| {
Argument {
name: name_from_pat(&body.arguments[i].pat),
name: name_from_pat(&body.params[i].pat),
type_: ty.clean(cx),
}
}).collect()
@ -3779,7 +3779,7 @@ pub struct BareFunctionDecl {
impl Clean<BareFunctionDecl> for hir::BareFnTy {
fn clean(&self, cx: &DocContext<'_>) -> BareFunctionDecl {
let (generic_params, decl) = enter_impl_trait(cx, || {
(self.generic_params.clean(cx), (&*self.decl, &self.arg_names[..]).clean(cx))
(self.generic_params.clean(cx), (&*self.decl, &self.param_names[..]).clean(cx))
});
BareFunctionDecl {
unsafety: self.unsafety,

View File

@ -1789,11 +1789,11 @@ pub struct InlineAsm {
pub dialect: AsmDialect,
}
/// An argument in a function header.
/// A parameter in a function header.
///
/// E.g., `bar: usize` as in `fn foo(bar: usize)`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Arg {
pub struct Param {
pub attrs: ThinVec<Attribute>,
pub ty: P<Ty>,
pub pat: P<Pat>,
@ -1816,7 +1816,7 @@ pub enum SelfKind {
pub type ExplicitSelf = Spanned<SelfKind>;
impl Arg {
impl Param {
pub fn to_self(&self) -> Option<ExplicitSelf> {
if let PatKind::Ident(BindingMode::ByValue(mutbl), ident, _) = self.pat.node {
if ident.name == kw::SelfLower {
@ -1843,14 +1843,14 @@ impl Arg {
}
}
pub fn from_self(attrs: ThinVec<Attribute>, eself: ExplicitSelf, eself_ident: Ident) -> Arg {
pub fn from_self(attrs: ThinVec<Attribute>, eself: ExplicitSelf, eself_ident: Ident) -> Param {
let span = eself.span.to(eself_ident.span);
let infer_ty = P(Ty {
id: DUMMY_NODE_ID,
node: TyKind::ImplicitSelf,
span,
});
let arg = |mutbl, ty| Arg {
let param = |mutbl, ty| Param {
attrs,
pat: P(Pat {
id: DUMMY_NODE_ID,
@ -1862,9 +1862,9 @@ impl Arg {
id: DUMMY_NODE_ID,
};
match eself.node {
SelfKind::Explicit(ty, mutbl) => arg(mutbl, ty),
SelfKind::Value(mutbl) => arg(mutbl, infer_ty),
SelfKind::Region(lt, mutbl) => arg(
SelfKind::Explicit(ty, mutbl) => param(mutbl, ty),
SelfKind::Value(mutbl) => param(mutbl, infer_ty),
SelfKind::Region(lt, mutbl) => param(
Mutability::Immutable,
P(Ty {
id: DUMMY_NODE_ID,
@ -1887,17 +1887,17 @@ impl Arg {
/// E.g., `fn foo(bar: baz)`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct FnDecl {
pub inputs: Vec<Arg>,
pub inputs: Vec<Param>,
pub output: FunctionRetTy,
pub c_variadic: bool,
}
impl FnDecl {
pub fn get_self(&self) -> Option<ExplicitSelf> {
self.inputs.get(0).and_then(Arg::to_self)
self.inputs.get(0).and_then(Param::to_self)
}
pub fn has_self(&self) -> bool {
self.inputs.get(0).map(Arg::is_self).unwrap_or(false)
self.inputs.get(0).map(Param::is_self).unwrap_or(false)
}
}

View File

@ -714,7 +714,7 @@ macro_rules! derive_has_attrs {
derive_has_attrs! {
Item, Expr, Local, ast::ForeignItem, ast::StructField, ast::ImplItem, ast::TraitItem, ast::Arm,
ast::Field, ast::FieldPat, ast::Variant, ast::Arg
ast::Field, ast::FieldPat, ast::Variant, ast::Param
}
pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) -> ast::Crate {

View File

@ -655,7 +655,7 @@ impl<'a> ExtCtxt<'a> {
body: P<ast::Expr>)
-> P<ast::Expr> {
let fn_decl = self.fn_decl(
ids.iter().map(|id| self.arg(span, *id, self.ty_infer(span))).collect(),
ids.iter().map(|id| self.param(span, *id, self.ty_infer(span))).collect(),
ast::FunctionRetTy::Default(span));
// FIXME -- We are using `span` as the span of the `|...|`
@ -693,9 +693,9 @@ impl<'a> ExtCtxt<'a> {
self.lambda1(span, self.expr_block(self.block(span, stmts)), ident)
}
pub fn arg(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::Arg {
pub fn param(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::Param {
let arg_pat = self.pat_ident(span, ident);
ast::Arg {
ast::Param {
attrs: ThinVec::default(),
id: ast::DUMMY_NODE_ID,
pat: arg_pat,
@ -705,7 +705,7 @@ impl<'a> ExtCtxt<'a> {
}
// FIXME: unused `self`
pub fn fn_decl(&self, inputs: Vec<ast::Arg>, output: ast::FunctionRetTy) -> P<ast::FnDecl> {
pub fn fn_decl(&self, inputs: Vec<ast::Param>, output: ast::FunctionRetTy) -> P<ast::FnDecl> {
P(ast::FnDecl {
inputs,
output,
@ -731,7 +731,7 @@ impl<'a> ExtCtxt<'a> {
pub fn item_fn_poly(&self,
span: Span,
name: Ident,
inputs: Vec<ast::Arg> ,
inputs: Vec<ast::Param> ,
output: P<ast::Ty>,
generics: Generics,
body: P<ast::Block>) -> P<ast::Item> {
@ -752,7 +752,7 @@ impl<'a> ExtCtxt<'a> {
pub fn item_fn(&self,
span: Span,
name: Ident,
inputs: Vec<ast::Arg> ,
inputs: Vec<ast::Param> ,
output: P<ast::Ty>,
body: P<ast::Block>
) -> P<ast::Item> {

View File

@ -225,8 +225,8 @@ pub trait MutVisitor: Sized {
noop_visit_attribute(at, self);
}
fn flat_map_arg(&mut self, arg: Arg) -> SmallVec<[Arg; 1]> {
noop_flat_map_arg(arg, self)
fn flat_map_param(&mut self, param: Param) -> SmallVec<[Param; 1]> {
noop_flat_map_param(param, self)
}
fn visit_generics(&mut self, generics: &mut Generics) {
@ -587,14 +587,14 @@ pub fn noop_visit_meta_item<T: MutVisitor>(mi: &mut MetaItem, vis: &mut T) {
vis.visit_span(span);
}
pub fn noop_flat_map_arg<T: MutVisitor>(mut arg: Arg, vis: &mut T) -> SmallVec<[Arg; 1]> {
let Arg { attrs, id, pat, span, ty } = &mut arg;
pub fn noop_flat_map_param<T: MutVisitor>(mut param: Param, vis: &mut T) -> SmallVec<[Param; 1]> {
let Param { attrs, id, pat, span, ty } = &mut param;
vis.visit_id(id);
visit_thin_attrs(attrs, vis);
vis.visit_pat(pat);
vis.visit_span(span);
vis.visit_ty(ty);
smallvec![arg]
smallvec![param]
}
pub fn noop_visit_tt<T: MutVisitor>(tt: &mut TokenTree, vis: &mut T) {
@ -720,7 +720,7 @@ pub fn noop_visit_asyncness<T: MutVisitor>(asyncness: &mut IsAsync, vis: &mut T)
pub fn noop_visit_fn_decl<T: MutVisitor>(decl: &mut P<FnDecl>, vis: &mut T) {
let FnDecl { inputs, output, c_variadic: _ } = decl.deref_mut();
inputs.flat_map_in_place(|arg| vis.flat_map_arg(arg));
inputs.flat_map_in_place(|param| vis.flat_map_param(param));
match output {
FunctionRetTy::Default(span) => vis.visit_span(span),
FunctionRetTy::Ty(ty) => vis.visit_ty(ty),

View File

@ -19,7 +19,7 @@ const DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG: &str = "an inner attribute is not \
permitted in this context";
impl<'a> Parser<'a> {
crate fn parse_arg_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
crate fn parse_param_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
let attrs = self.parse_outer_attributes()?;
self.sess.gated_spans.param_attrs.borrow_mut()
.extend(attrs.iter().map(|a| a.span));

View File

@ -1,5 +1,5 @@
use crate::ast::{
self, Arg, BinOpKind, BindingMode, BlockCheckMode, Expr, ExprKind, Ident, Item, ItemKind,
self, Param, BinOpKind, BindingMode, BlockCheckMode, Expr, ExprKind, Ident, Item, ItemKind,
Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind, VariantData,
};
use crate::feature_gate::{feature_err, UnstableFeatures};
@ -18,7 +18,7 @@ use log::{debug, trace};
use std::mem;
/// Creates a placeholder argument.
crate fn dummy_arg(ident: Ident) -> Arg {
crate fn dummy_arg(ident: Ident) -> Param {
let pat = P(Pat {
id: ast::DUMMY_NODE_ID,
node: PatKind::Ident(BindingMode::ByValue(Mutability::Immutable), ident, None),
@ -29,7 +29,7 @@ crate fn dummy_arg(ident: Ident) -> Arg {
span: ident.span,
id: ast::DUMMY_NODE_ID
};
Arg { attrs: ThinVec::default(), id: ast::DUMMY_NODE_ID, pat, span: ident.span, ty: P(ty) }
Param { attrs: ThinVec::default(), id: ast::DUMMY_NODE_ID, pat, span: ident.span, ty: P(ty) }
}
pub enum Error {
@ -1183,7 +1183,7 @@ impl<'a> Parser<'a> {
Err(err)
}
crate fn eat_incorrect_doc_comment_for_arg_type(&mut self) {
crate fn eat_incorrect_doc_comment_for_param_type(&mut self) {
if let token::DocComment(_) = self.token.kind {
self.struct_span_err(
self.token.span,
@ -1211,7 +1211,7 @@ impl<'a> Parser<'a> {
}
}
crate fn argument_without_type(
crate fn parameter_without_type(
&mut self,
err: &mut DiagnosticBuilder<'_>,
pat: P<ast::Pat>,
@ -1286,13 +1286,13 @@ impl<'a> Parser<'a> {
Ok((pat, ty))
}
crate fn recover_bad_self_arg(
crate fn recover_bad_self_param(
&mut self,
mut arg: ast::Arg,
mut param: ast::Param,
is_trait_item: bool,
) -> PResult<'a, ast::Arg> {
let sp = arg.pat.span;
arg.ty.node = TyKind::Err;
) -> PResult<'a, ast::Param> {
let sp = param.pat.span;
param.ty.node = TyKind::Err;
let mut err = self.struct_span_err(sp, "unexpected `self` parameter in function");
if is_trait_item {
err.span_label(sp, "must be the first associated function parameter");
@ -1301,7 +1301,7 @@ impl<'a> Parser<'a> {
err.note("`self` is only valid as the first parameter of an associated function");
}
err.emit();
Ok(arg)
Ok(param)
}
crate fn consume_block(&mut self, delim: token::DelimToken) {
@ -1344,15 +1344,15 @@ impl<'a> Parser<'a> {
err
}
/// Replace duplicated recovered arguments with `_` pattern to avoid unecessary errors.
/// Replace duplicated recovered parameters with `_` pattern to avoid unecessary errors.
///
/// This is necessary because at this point we don't know whether we parsed a function with
/// anonymous arguments or a function with names but no types. In order to minimize
/// unecessary errors, we assume the arguments are in the shape of `fn foo(a, b, c)` where
/// the arguments are *names* (so we don't emit errors about not being able to find `b` in
/// anonymous parameters or a function with names but no types. In order to minimize
/// unecessary errors, we assume the parameters are in the shape of `fn foo(a, b, c)` where
/// the parameters are *names* (so we don't emit errors about not being able to find `b` in
/// the local scope), but if we find the same name multiple times, like in `fn foo(i8, i8)`,
/// we deduplicate them to not complain about duplicated argument names.
crate fn deduplicate_recovered_arg_names(&self, fn_inputs: &mut Vec<Arg>) {
/// we deduplicate them to not complain about duplicated parameter names.
crate fn deduplicate_recovered_params_names(&self, fn_inputs: &mut Vec<Param>) {
let mut seen_inputs = FxHashSet::default();
for input in fn_inputs.iter_mut() {
let opt_ident = if let (PatKind::Ident(_, ident, _), TyKind::Err) = (

View File

@ -10,7 +10,7 @@ pub use path::PathStyle;
mod stmt;
mod generics;
use crate::ast::{self, AttrStyle, Attribute, Arg, BindingMode, StrStyle, SelfKind};
use crate::ast::{self, AttrStyle, Attribute, Param, BindingMode, StrStyle, SelfKind};
use crate::ast::{FnDecl, Ident, IsAsync, MacDelimiter, Mutability, TyKind};
use crate::ast::{Visibility, VisibilityKind, Unsafety, CrateSugar};
use crate::source_map::{self, respan};
@ -971,27 +971,27 @@ impl<'a> Parser<'a> {
/// Skips unexpected attributes and doc comments in this position and emits an appropriate
/// error.
/// This version of parse arg doesn't necessarily require identifier names.
fn parse_arg_general(
/// This version of parse param doesn't necessarily require identifier names.
fn parse_param_general(
&mut self,
is_trait_item: bool,
allow_c_variadic: bool,
is_name_required: impl Fn(&token::Token) -> bool,
) -> PResult<'a, Arg> {
) -> PResult<'a, Param> {
let lo = self.token.span;
let attrs = self.parse_arg_attributes()?;
if let Some(mut arg) = self.parse_self_arg()? {
arg.attrs = attrs.into();
return self.recover_bad_self_arg(arg, is_trait_item);
let attrs = self.parse_param_attributes()?;
if let Some(mut param) = self.parse_self_param()? {
param.attrs = attrs.into();
return self.recover_bad_self_param(param, is_trait_item);
}
let is_name_required = is_name_required(&self.token);
let (pat, ty) = if is_name_required || self.is_named_argument() {
debug!("parse_arg_general parse_pat (is_name_required:{})", is_name_required);
debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required);
let pat = self.parse_fn_param_pat()?;
if let Err(mut err) = self.expect(&token::Colon) {
if let Some(ident) = self.argument_without_type(
if let Some(ident) = self.parameter_without_type(
&mut err,
pat,
is_name_required,
@ -1004,12 +1004,12 @@ impl<'a> Parser<'a> {
}
}
self.eat_incorrect_doc_comment_for_arg_type();
self.eat_incorrect_doc_comment_for_param_type();
(pat, self.parse_ty_common(true, true, allow_c_variadic)?)
} else {
debug!("parse_arg_general ident_to_pat");
debug!("parse_param_general ident_to_pat");
let parser_snapshot_before_ty = self.clone();
self.eat_incorrect_doc_comment_for_arg_type();
self.eat_incorrect_doc_comment_for_param_type();
let mut ty = self.parse_ty_common(true, true, allow_c_variadic);
if ty.is_ok() && self.token != token::Comma &&
self.token != token::CloseDelim(token::Paren) {
@ -1040,7 +1040,7 @@ impl<'a> Parser<'a> {
let span = lo.to(self.token.span);
Ok(Arg { attrs: attrs.into(), id: ast::DUMMY_NODE_ID, pat, span, ty })
Ok(Param { attrs: attrs.into(), id: ast::DUMMY_NODE_ID, pat, span, ty })
}
/// Parses mutability (`mut` or nothing).
@ -1186,26 +1186,26 @@ impl<'a> Parser<'a> {
}
fn parse_fn_args(&mut self, named_args: bool, allow_c_variadic: bool)
-> PResult<'a, (Vec<Arg> , bool)> {
fn parse_fn_params(&mut self, named_params: bool, allow_c_variadic: bool)
-> PResult<'a, (Vec<Param> , bool)> {
let sp = self.token.span;
let mut c_variadic = false;
let (args, _): (Vec<Option<Arg>>, _) = self.parse_paren_comma_seq(|p| {
let (params, _): (Vec<Option<Param>>, _) = self.parse_paren_comma_seq(|p| {
let do_not_enforce_named_arguments_for_c_variadic =
|token: &token::Token| -> bool {
if token == &token::DotDotDot {
false
} else {
named_args
named_params
}
};
match p.parse_arg_general(
match p.parse_param_general(
false,
allow_c_variadic,
do_not_enforce_named_arguments_for_c_variadic
) {
Ok(arg) => {
if let TyKind::CVarArgs = arg.ty.node {
Ok(param) => {
if let TyKind::CVarArgs = param.ty.node {
c_variadic = true;
if p.token != token::CloseDelim(token::Paren) {
let span = p.token.span;
@ -1213,10 +1213,10 @@ impl<'a> Parser<'a> {
"`...` must be the last argument of a C-variadic function");
Ok(None)
} else {
Ok(Some(arg))
Ok(Some(param))
}
} else {
Ok(Some(arg))
Ok(Some(param))
}
},
Err(mut e) => {
@ -1231,20 +1231,20 @@ impl<'a> Parser<'a> {
}
})?;
let args: Vec<_> = args.into_iter().filter_map(|x| x).collect();
let params: Vec<_> = params.into_iter().filter_map(|x| x).collect();
if c_variadic && args.len() <= 1 {
if c_variadic && params.len() <= 1 {
self.span_err(sp,
"C-variadic function must be declared with at least one named argument");
}
Ok((args, c_variadic))
Ok((params, c_variadic))
}
/// Returns the parsed optional self argument and whether a self shortcut was used.
/// Returns the parsed optional self parameter and whether a self shortcut was used.
///
/// See `parse_self_arg_with_attrs` to collect attributes.
fn parse_self_arg(&mut self) -> PResult<'a, Option<Arg>> {
/// See `parse_self_param_with_attrs` to collect attributes.
fn parse_self_param(&mut self) -> PResult<'a, Option<Param>> {
let expect_ident = |this: &mut Self| match this.token.kind {
// Preserve hygienic context.
token::Ident(name, _) =>
@ -1349,49 +1349,51 @@ impl<'a> Parser<'a> {
};
let eself = source_map::respan(eself_lo.to(eself_hi), eself);
Ok(Some(Arg::from_self(ThinVec::default(), eself, eself_ident)))
Ok(Some(Param::from_self(ThinVec::default(), eself, eself_ident)))
}
/// Returns the parsed optional self argument with attributes and whether a self
/// Returns the parsed optional self parameter with attributes and whether a self
/// shortcut was used.
fn parse_self_arg_with_attrs(&mut self) -> PResult<'a, Option<Arg>> {
let attrs = self.parse_arg_attributes()?;
let arg_opt = self.parse_self_arg()?;
Ok(arg_opt.map(|mut arg| {
arg.attrs = attrs.into();
arg
fn parse_self_parameter_with_attrs(&mut self) -> PResult<'a, Option<Param>> {
let attrs = self.parse_param_attributes()?;
let param_opt = self.parse_self_param()?;
Ok(param_opt.map(|mut param| {
param.attrs = attrs.into();
param
}))
}
/// Parses the parameter list and result type of a function that may have a `self` parameter.
fn parse_fn_decl_with_self<F>(&mut self, parse_arg_fn: F) -> PResult<'a, P<FnDecl>>
where F: FnMut(&mut Parser<'a>) -> PResult<'a, Arg>,
fn parse_fn_decl_with_self<F>(&mut self, parse_param_fn: F) -> PResult<'a, P<FnDecl>>
where F: FnMut(&mut Parser<'a>) -> PResult<'a, Param>,
{
self.expect(&token::OpenDelim(token::Paren))?;
// Parse optional self argument.
let self_arg = self.parse_self_arg_with_attrs()?;
let self_param = self.parse_self_parameter_with_attrs()?;
// Parse the rest of the function parameter list.
let sep = SeqSep::trailing_allowed(token::Comma);
let (mut fn_inputs, recovered) = if let Some(self_arg) = self_arg {
let (mut fn_inputs, recovered) = if let Some(self_param) = self_param {
if self.check(&token::CloseDelim(token::Paren)) {
(vec![self_arg], false)
(vec![self_param], false)
} else if self.eat(&token::Comma) {
let mut fn_inputs = vec![self_arg];
let mut fn_inputs = vec![self_param];
let (mut input, _, recovered) = self.parse_seq_to_before_end(
&token::CloseDelim(token::Paren), sep, parse_arg_fn)?;
&token::CloseDelim(token::Paren), sep, parse_param_fn)?;
fn_inputs.append(&mut input);
(fn_inputs, recovered)
} else {
match self.expect_one_of(&[], &[]) {
Err(err) => return Err(err),
Ok(recovered) => (vec![self_arg], recovered),
Ok(recovered) => (vec![self_param], recovered),
}
}
} else {
let (input, _, recovered) =
self.parse_seq_to_before_end(&token::CloseDelim(token::Paren), sep, parse_arg_fn)?;
self.parse_seq_to_before_end(&token::CloseDelim(token::Paren),
sep,
parse_param_fn)?;
(input, recovered)
};
@ -1399,8 +1401,8 @@ impl<'a> Parser<'a> {
// Parse closing paren and return type.
self.expect(&token::CloseDelim(token::Paren))?;
}
// Replace duplicated recovered arguments with `_` pattern to avoid unecessary errors.
self.deduplicate_recovered_arg_names(&mut fn_inputs);
// Replace duplicated recovered params with `_` pattern to avoid unecessary errors.
self.deduplicate_recovered_params_names(&mut fn_inputs);
Ok(P(FnDecl {
inputs: fn_inputs,

View File

@ -7,7 +7,7 @@ use crate::maybe_recover_from_interpolated_ty_qpath;
use crate::ptr::P;
use crate::ast::{self, Attribute, AttrStyle, Ident, CaptureBy, BlockCheckMode};
use crate::ast::{Expr, ExprKind, RangeLimits, Label, Movability, IsAsync, Arm};
use crate::ast::{Ty, TyKind, FunctionRetTy, Arg, FnDecl};
use crate::ast::{Ty, TyKind, FunctionRetTy, Param, FnDecl};
use crate::ast::{BinOpKind, BinOp, UnOp};
use crate::ast::{Mac, AnonConst, Field};
@ -1157,7 +1157,7 @@ impl<'a> Parser<'a> {
&[&token::BinOp(token::Or), &token::OrOr],
SeqSep::trailing_allowed(token::Comma),
TokenExpectType::NoExpect,
|p| p.parse_fn_block_arg()
|p| p.parse_fn_block_param()
)?.0;
self.expect_or()?;
args
@ -1172,10 +1172,10 @@ impl<'a> Parser<'a> {
}))
}
/// Parses an argument in a lambda header (e.g., `|arg, arg|`).
fn parse_fn_block_arg(&mut self) -> PResult<'a, Arg> {
/// Parses a parameter in a lambda header (e.g., `|arg, arg|`).
fn parse_fn_block_param(&mut self) -> PResult<'a, Param> {
let lo = self.token.span;
let attrs = self.parse_arg_attributes()?;
let attrs = self.parse_param_attributes()?;
let pat = self.parse_pat(PARAM_EXPECTED)?;
let t = if self.eat(&token::Colon) {
self.parse_ty()?
@ -1187,7 +1187,7 @@ impl<'a> Parser<'a> {
})
};
let span = lo.to(self.token.span);
Ok(Arg {
Ok(Param {
attrs: attrs.into(),
ty: t,
pat,

View File

@ -422,7 +422,7 @@ impl<'a> Parser<'a> {
} else if self.look_ahead(1, |t| *t == token::OpenDelim(token::Paren)) {
let ident = self.parse_ident().unwrap();
self.bump(); // `(`
let kw_name = if let Ok(Some(_)) = self.parse_self_arg_with_attrs()
let kw_name = if let Ok(Some(_)) = self.parse_self_parameter_with_attrs()
.map_err(|mut e| e.cancel())
{
"method"
@ -475,7 +475,7 @@ impl<'a> Parser<'a> {
self.eat_to_tokens(&[&token::Gt]);
self.bump(); // `>`
let (kw, kw_name, ambiguous) = if self.eat(&token::OpenDelim(token::Paren)) {
if let Ok(Some(_)) = self.parse_self_arg_with_attrs()
if let Ok(Some(_)) = self.parse_self_parameter_with_attrs()
.map_err(|mut e| e.cancel())
{
("fn", "method", false)
@ -861,7 +861,7 @@ impl<'a> Parser<'a> {
let ident = self.parse_ident()?;
let mut generics = self.parse_generics()?;
let decl = self.parse_fn_decl_with_self(|p| {
p.parse_arg_general(true, false, |_| true)
p.parse_param_general(true, false, |_| true)
})?;
generics.where_clause = self.parse_where_clause()?;
*at_end = true;
@ -1040,7 +1040,7 @@ impl<'a> Parser<'a> {
// We don't allow argument names to be left off in edition 2018.
let is_name_required = p.token.span.rust_2018();
p.parse_arg_general(true, false, |_| is_name_required)
p.parse_param_general(true, false, |_| is_name_required)
})?;
generics.where_clause = self.parse_where_clause()?;
@ -1291,7 +1291,7 @@ impl<'a> Parser<'a> {
/// Parses the argument list and result type of a function declaration.
fn parse_fn_decl(&mut self, allow_c_variadic: bool) -> PResult<'a, P<FnDecl>> {
let (args, c_variadic) = self.parse_fn_args(true, allow_c_variadic)?;
let (args, c_variadic) = self.parse_fn_params(true, allow_c_variadic)?;
let ret_ty = self.parse_ret_ty(true)?;
Ok(P(FnDecl {

View File

@ -292,7 +292,7 @@ impl<'a> Parser<'a> {
};
self.expect_keyword(kw::Fn)?;
let (inputs, c_variadic) = self.parse_fn_args(false, true)?;
let (inputs, c_variadic) = self.parse_fn_params(false, true)?;
let ret_ty = self.parse_ret_ty(false)?;
let decl = P(FnDecl {
inputs,

View File

@ -418,8 +418,8 @@ pub fn attribute_to_string(attr: &ast::Attribute) -> String {
to_string(|s| s.print_attribute(attr))
}
pub fn arg_to_string(arg: &ast::Arg) -> String {
to_string(|s| s.print_arg(arg, false))
pub fn param_to_string(arg: &ast::Param) -> String {
to_string(|s| s.print_param(arg, false))
}
fn foreign_item_to_string(arg: &ast::ForeignItem) -> String {
@ -2101,7 +2101,7 @@ impl<'a> State<'a> {
self.print_asyncness(asyncness);
self.print_capture_clause(capture_clause);
self.print_fn_block_args(decl);
self.print_fn_block_params(decl);
self.s.space();
self.print_expr(body);
self.end(); // need to close a box
@ -2536,21 +2536,21 @@ impl<'a> State<'a> {
self.print_ident(name);
}
self.print_generic_params(&generics.params);
self.print_fn_args_and_ret(decl);
self.print_fn_params_and_ret(decl);
self.print_where_clause(&generics.where_clause)
}
crate fn print_fn_args_and_ret(&mut self, decl: &ast::FnDecl) {
crate fn print_fn_params_and_ret(&mut self, decl: &ast::FnDecl) {
self.popen();
self.commasep(Inconsistent, &decl.inputs, |s, arg| s.print_arg(arg, false));
self.commasep(Inconsistent, &decl.inputs, |s, param| s.print_param(param, false));
self.pclose();
self.print_fn_output(decl)
}
crate fn print_fn_block_args(&mut self, decl: &ast::FnDecl) {
crate fn print_fn_block_params(&mut self, decl: &ast::FnDecl) {
self.s.word("|");
self.commasep(Inconsistent, &decl.inputs, |s, arg| s.print_arg(arg, true));
self.commasep(Inconsistent, &decl.inputs, |s, param| s.print_param(param, true));
self.s.word("|");
if let ast::FunctionRetTy::Default(..) = decl.output {
@ -2759,7 +2759,7 @@ impl<'a> State<'a> {
self.print_type(&mt.ty)
}
crate fn print_arg(&mut self, input: &ast::Arg, is_closure: bool) {
crate fn print_param(&mut self, input: &ast::Param, is_closure: bool) {
self.ibox(INDENT_UNIT);
self.print_outer_attributes_inline(&input.attrs);

View File

@ -66,7 +66,7 @@ pub trait Visitor<'ast>: Sized {
fn visit_local(&mut self, l: &'ast Local) { walk_local(self, l) }
fn visit_block(&mut self, b: &'ast Block) { walk_block(self, b) }
fn visit_stmt(&mut self, s: &'ast Stmt) { walk_stmt(self, s) }
fn visit_arg(&mut self, arg: &'ast Arg) { walk_arg(self, arg) }
fn visit_param(&mut self, param: &'ast Param) { walk_param(self, param) }
fn visit_arm(&mut self, a: &'ast Arm) { walk_arm(self, a) }
fn visit_pat(&mut self, p: &'ast Pat) { walk_pat(self, p) }
fn visit_anon_const(&mut self, c: &'ast AnonConst) { walk_anon_const(self, c) }
@ -555,8 +555,8 @@ pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FunctionR
}
pub fn walk_fn_decl<'a, V: Visitor<'a>>(visitor: &mut V, function_declaration: &'a FnDecl) {
for arg in &function_declaration.inputs {
visitor.visit_arg(arg);
for param in &function_declaration.inputs {
visitor.visit_param(param);
}
visitor.visit_fn_ret_ty(&function_declaration.output);
}
@ -824,10 +824,10 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
visitor.visit_expr_post(expression)
}
pub fn walk_arg<'a, V: Visitor<'a>>(visitor: &mut V, arg: &'a Arg) {
walk_list!(visitor, visit_attribute, arg.attrs.iter());
visitor.visit_pat(&arg.pat);
visitor.visit_ty(&arg.ty);
pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) {
walk_list!(visitor, visit_attribute, param.attrs.iter());
visitor.visit_pat(&param.pat);
visitor.visit_ty(&param.ty);
}
pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) {

View File

@ -929,10 +929,10 @@ impl<'a> MethodDef<'a> {
let args = {
let self_args = explicit_self.map(|explicit_self| {
let ident = Ident::with_dummy_span(kw::SelfLower).with_span_pos(trait_.span);
ast::Arg::from_self(ThinVec::default(), explicit_self, ident)
ast::Param::from_self(ThinVec::default(), explicit_self, ident)
});
let nonself_args = arg_types.into_iter()
.map(|(name, ty)| cx.arg(trait_.span, name, ty));
.map(|(name, ty)| cx.param(trait_.span, name, ty));
self_args.into_iter().chain(nonself_args).collect()
};

View File

@ -1,5 +1,5 @@
use syntax::ast::{ItemKind, Mutability, Stmt, Ty, TyKind, Unsafety};
use syntax::ast::{self, Arg, Attribute, Expr, FnHeader, Generics, Ident};
use syntax::ast::{self, Param, Attribute, Expr, FnHeader, Generics, Ident};
use syntax::attr::check_builtin_macro_attribute;
use syntax::ext::allocator::{AllocatorKind, AllocatorMethod, AllocatorTy, ALLOCATOR_METHODS};
use syntax::ext::base::{Annotatable, ExtCtxt};
@ -114,7 +114,7 @@ impl AllocFnFactory<'_, '_> {
fn arg_ty(
&self,
ty: &AllocatorTy,
args: &mut Vec<Arg>,
args: &mut Vec<Param>,
ident: &mut dyn FnMut() -> Ident,
) -> P<Expr> {
match *ty {
@ -123,8 +123,8 @@ impl AllocFnFactory<'_, '_> {
let ty_usize = self.cx.ty_path(usize);
let size = ident();
let align = ident();
args.push(self.cx.arg(self.span, size, ty_usize.clone()));
args.push(self.cx.arg(self.span, align, ty_usize));
args.push(self.cx.param(self.span, size, ty_usize.clone()));
args.push(self.cx.param(self.span, align, ty_usize));
let layout_new = self.cx.std_path(&[
Symbol::intern("alloc"),
@ -140,14 +140,14 @@ impl AllocFnFactory<'_, '_> {
AllocatorTy::Ptr => {
let ident = ident();
args.push(self.cx.arg(self.span, ident, self.ptr_u8()));
args.push(self.cx.param(self.span, ident, self.ptr_u8()));
let arg = self.cx.expr_ident(self.span, ident);
self.cx.expr_cast(self.span, arg, self.ptr_u8())
}
AllocatorTy::Usize => {
let ident = ident();
args.push(self.cx.arg(self.span, ident, self.usize()));
args.push(self.cx.param(self.span, ident, self.usize()));
self.cx.expr_ident(self.span, ident)
}

View File

@ -4,5 +4,5 @@
fn main() {
let _ = async |x: u8| {};
//~^ ERROR `async` non-`move` closures with arguments are not currently supported
//~^ ERROR `async` non-`move` closures with parameters are not currently supported
}

View File

@ -1,5 +1,5 @@
error[E0708]: `async` non-`move` closures with arguments are not currently supported
--> $DIR/no-args-non-move-async-closure.rs:6:13
error[E0708]: `async` non-`move` closures with parameters are not currently supported
--> $DIR/no-params-non-move-async-closure.rs:6:13
|
LL | let _ = async |x: u8| {};
| ^^^^^^^^^^^^^

View File

@ -1,8 +0,0 @@
error[E0628]: generators cannot have explicit arguments
--> $DIR/no-arguments-on-generators.rs:4:15
|
LL | let gen = |start| {
| ^^^^^^^
error: aborting due to previous error

View File

@ -1,7 +1,7 @@
#![feature(generators)]
fn main() {
let gen = |start| { //~ ERROR generators cannot have explicit arguments
let gen = |start| { //~ ERROR generators cannot have explicit parameters
yield;
};
}

View File

@ -0,0 +1,8 @@
error[E0628]: generators cannot have explicit parameters
--> $DIR/no-parameters-on-generators.rs:4:15
|
LL | let gen = |start| {
| ^^^^^^^
error: aborting due to previous error