AssocImplKind::{Method -> Fn}.

This commit is contained in:
Mazdak Farrokhzad 2019-12-08 00:13:59 +01:00
parent abf2e7aa95
commit e52f902a8a
16 changed files with 31 additions and 35 deletions

View File

@ -481,7 +481,7 @@ impl<'a> LoweringContext<'a> {
self.lctx.allocate_hir_id_counter(item.id);
match item.kind {
AssocItemKind::Method(_, None) => {
AssocItemKind::Fn(_, None) => {
// Ignore patterns in trait methods without bodies
self.with_hir_id_owner(None, |this| {
visit::walk_trait_item(this, item)

View File

@ -826,7 +826,7 @@ impl LoweringContext<'_> {
.map(|x| self.lower_const_body(i.span, Some(x))),
),
),
AssocItemKind::Method(ref sig, None) => {
AssocItemKind::Fn(ref sig, None) => {
let names = self.lower_fn_params_to_names(&sig.decl);
let (generics, sig) = self.lower_method_sig(
&i.generics,
@ -837,7 +837,7 @@ impl LoweringContext<'_> {
);
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
}
AssocItemKind::Method(ref sig, Some(ref body)) => {
AssocItemKind::Fn(ref sig, Some(ref body)) => {
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
let (generics, sig) = self.lower_method_sig(
&i.generics,
@ -880,7 +880,7 @@ impl LoweringContext<'_> {
AssocItemKind::TyAlias(_, ref default) => {
(hir::AssocItemKind::Type, default.is_some())
}
AssocItemKind::Method(ref sig, ref default) => (
AssocItemKind::Fn(ref sig, ref default) => (
hir::AssocItemKind::Method {
has_self: sig.decl.has_self(),
},
@ -913,7 +913,7 @@ impl LoweringContext<'_> {
self.lower_const_body(i.span, expr.as_deref()),
),
),
AssocItemKind::Method(ref sig, ref body) => {
AssocItemKind::Fn(ref sig, ref body) => {
self.current_item = Some(i.span);
let body_id = self.lower_maybe_async_body(
i.span,
@ -984,7 +984,7 @@ impl LoweringContext<'_> {
None => hir::AssocItemKind::Type,
Some(_) => hir::AssocItemKind::OpaqueTy,
},
AssocItemKind::Method(sig, _) => hir::AssocItemKind::Method {
AssocItemKind::Fn(sig, _) => hir::AssocItemKind::Method {
has_self: sig.decl.has_self(),
},
AssocItemKind::Macro(..) => unimplemented!(),

View File

@ -779,7 +779,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> {
fn flat_map_trait_item(&mut self, i: ast::AssocItem) -> SmallVec<[ast::AssocItem; 1]> {
let is_const = match i.kind {
ast::AssocItemKind::Const(..) => true,
ast::AssocItemKind::Method(ref sig, _) => Self::is_sig_const(sig),
ast::AssocItemKind::Fn(ref sig, _) => Self::is_sig_const(sig),
_ => false,
};
self.run(is_const, |s| noop_flat_map_assoc_item(i, s))

View File

@ -269,7 +269,7 @@ impl EarlyLintPass for UnsafeCode {
}
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, item: &ast::AssocItem) {
if let ast::AssocItemKind::Method(ref sig, None) = item.kind {
if let ast::AssocItemKind::Fn(ref sig, None) = item.kind {
if sig.header.unsafety == ast::Unsafety::Unsafe {
self.report_unsafe(cx, item.span, "declaration of an `unsafe` method")
}
@ -617,7 +617,7 @@ declare_lint_pass!(
impl EarlyLintPass for AnonymousParameters {
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, it: &ast::AssocItem) {
match it.kind {
ast::AssocItemKind::Method(ref sig, _) => {
ast::AssocItemKind::Fn(ref sig, _) => {
for arg in sig.decl.inputs.iter() {
match arg.pat.kind {
ast::PatKind::Ident(_, ident, None) => {

View File

@ -1790,7 +1790,7 @@ impl<'a> Parser<'a> {
})?;
let sig = FnSig { header, decl };
let body = self.parse_assoc_fn_body(at_end, attrs)?;
Ok((ident, AssocItemKind::Method(sig, body), generics))
Ok((ident, AssocItemKind::Fn(sig, body), generics))
}
/// Parse the "body" of a method in an associated item definition.

View File

@ -544,7 +544,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
for impl_item in impl_items {
self.invalid_visibility(&impl_item.vis, None);
if let AssocItemKind::Method(ref sig, _) = impl_item.kind {
if let AssocItemKind::Fn(ref sig, _) = impl_item.kind {
self.check_trait_fn_not_const(sig.header.constness);
self.check_trait_fn_not_async(impl_item.span, sig.header.asyncness.node);
}
@ -795,7 +795,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
AssocItemKind::Const(_, body) => {
self.check_impl_item_provided(ii.span, body, "constant", " = <expr>;");
}
AssocItemKind::Method(sig, body) => {
AssocItemKind::Fn(sig, body) => {
self.check_impl_item_provided(ii.span, body, "function", " { <body> }");
self.check_fn_decl(&sig.decl);
}
@ -812,7 +812,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
self.invalid_visibility(&ti.vis, None);
self.check_defaultness(ti.span, ti.defaultness);
if let AssocItemKind::Method(sig, block) = &ti.kind {
if let AssocItemKind::Fn(sig, block) = &ti.kind {
self.check_fn_decl(&sig.decl);
self.check_trait_fn_not_async(ti.span, sig.header.asyncness.node);
self.check_trait_fn_not_const(sig.header.constness);
@ -838,7 +838,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
fn visit_assoc_item(&mut self, item: &'a AssocItem) {
if let AssocItemKind::Method(sig, _) = &item.kind {
if let AssocItemKind::Fn(sig, _) = &item.kind {
self.check_c_varadic_type(&sig.decl);
}
visit::walk_assoc_item(self, item);

View File

@ -1176,7 +1176,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
let item_def_id = self.r.definitions.local_def_id(item.id);
let (res, ns) = match item.kind {
AssocItemKind::Const(..) => (Res::Def(DefKind::AssocConst, item_def_id), ValueNS),
AssocItemKind::Method(ref sig, _) => {
AssocItemKind::Fn(ref sig, _) => {
if sig.decl.has_self() {
self.r.has_self.insert(item_def_id);
}

View File

@ -214,11 +214,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
fn visit_trait_item(&mut self, ti: &'a AssocItem) {
let def_data = match ti.kind {
AssocItemKind::Method(..) | AssocItemKind::Const(..) =>
DefPathData::ValueNs(ti.ident.name),
AssocItemKind::TyAlias(..) => {
DefPathData::TypeNs(ti.ident.name)
},
AssocItemKind::Fn(..) | AssocItemKind::Const(..) => DefPathData::ValueNs(ti.ident.name),
AssocItemKind::TyAlias(..) => DefPathData::TypeNs(ti.ident.name),
AssocItemKind::Macro(..) => return self.visit_macro_invoc(ti.id),
};
@ -228,7 +225,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
fn visit_impl_item(&mut self, ii: &'a AssocItem) {
let def_data = match ii.kind {
AssocItemKind::Method(FnSig {
AssocItemKind::Fn(FnSig {
ref header,
ref decl,
}, ref body) if header.asyncness.node.is_async() => {
@ -242,7 +239,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
body.as_deref(),
)
}
AssocItemKind::Method(..) |
AssocItemKind::Fn(..) |
AssocItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name),
AssocItemKind::TyAlias(..) => DefPathData::TypeNs(ii.ident.name),
AssocItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),

View File

@ -818,7 +818,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
});
}
}
AssocItemKind::Method(_, _) => {
AssocItemKind::Fn(_, _) => {
visit::walk_assoc_item(this, trait_item)
}
AssocItemKind::TyAlias(..) => {
@ -1109,7 +1109,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
visit::walk_assoc_item(this, impl_item)
});
}
AssocItemKind::Method(..) => {
AssocItemKind::Fn(..) => {
// If this is a trait impl, ensure the method
// exists in trait
this.check_trait_item(impl_item.ident,

View File

@ -1044,7 +1044,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
&trait_item.attrs,
);
}
ast::AssocItemKind::Method(ref sig, ref body) => {
ast::AssocItemKind::Fn(ref sig, ref body) => {
self.process_method(
sig,
body.as_ref().map(|x| &**x),
@ -1115,7 +1115,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
&impl_item.attrs,
);
}
ast::AssocItemKind::Method(ref sig, ref body) => {
ast::AssocItemKind::Fn(ref sig, ref body) => {
self.process_method(
sig,
body.as_deref(),

View File

@ -1634,8 +1634,7 @@ pub enum AssocItemKind {
Const(P<Ty>, Option<P<Expr>>),
/// An associated function.
/// FIXME(Centril): Rename to `Fn`.
Method(FnSig, Option<P<Block>>),
Fn(FnSig, Option<P<Block>>),
/// An associated type.
TyAlias(GenericBounds, Option<P<Ty>>),

View File

@ -573,7 +573,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_trait_item(&mut self, ti: &'a ast::AssocItem) {
match ti.kind {
ast::AssocItemKind::Method(ref sig, ref block) => {
ast::AssocItemKind::Fn(ref sig, ref block) => {
if block.is_none() {
self.check_extern(sig.header.ext);
}
@ -600,7 +600,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
match ii.kind {
ast::AssocItemKind::Method(ref sig, _) => {
ast::AssocItemKind::Fn(ref sig, _) => {
if sig.decl.c_variadic() {
gate_feature_post!(
&self, c_variadic, ii.span,

View File

@ -955,7 +955,7 @@ pub fn noop_flat_map_assoc_item<T: MutVisitor>(mut item: AssocItem, visitor: &mu
visitor.visit_ty(ty);
visit_opt(expr, |expr| visitor.visit_expr(expr));
}
AssocItemKind::Method(sig, body) => {
AssocItemKind::Fn(sig, body) => {
visit_fn_sig(sig, visitor);
visit_opt(body, |body| visitor.visit_block(body));
}

View File

@ -1528,7 +1528,7 @@ impl<'a> State<'a> {
ast::AssocItemKind::Const(ty, expr) => {
self.print_associated_const(item.ident, ty, expr.as_deref(), &item.vis);
}
ast::AssocItemKind::Method(sig, body) => {
ast::AssocItemKind::Fn(sig, body) => {
if body.is_some() {
self.head("");
}

View File

@ -600,11 +600,11 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem)
visitor.visit_ty(ty);
walk_list!(visitor, visit_expr, expr);
}
AssocItemKind::Method(ref sig, None) => {
AssocItemKind::Fn(ref sig, None) => {
visitor.visit_fn_header(&sig.header);
walk_fn_decl(visitor, &sig.decl);
}
AssocItemKind::Method(ref sig, Some(ref body)) => {
AssocItemKind::Fn(ref sig, Some(ref body)) => {
visitor.visit_fn(FnKind::Method(item.ident, sig, &item.vis, body),
&sig.decl, item.span, item.id);
}

View File

@ -958,7 +958,7 @@ impl<'a> MethodDef<'a> {
vis: respan(trait_lo_sp, ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final,
ident: method_ident,
kind: ast::AssocItemKind::Method(sig, Some(body_block)),
kind: ast::AssocItemKind::Fn(sig, Some(body_block)),
tokens: None,
}
}