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
56 changed files with 391 additions and 388 deletions

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) {