From e52f902a8ab3a1abbb200607db4766d95b27bc8e Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 8 Dec 2019 00:13:59 +0100 Subject: [PATCH] `AssocImplKind::{Method -> Fn}`. --- src/librustc/hir/lowering.rs | 2 +- src/librustc/hir/lowering/item.rs | 10 +++++----- src/librustc_interface/util.rs | 2 +- src/librustc_lint/builtin.rs | 4 ++-- src/librustc_parse/parser/item.rs | 2 +- src/librustc_passes/ast_validation.rs | 8 ++++---- src/librustc_resolve/build_reduced_graph.rs | 2 +- src/librustc_resolve/def_collector.rs | 11 ++++------- src/librustc_resolve/late.rs | 4 ++-- src/librustc_save_analysis/dump_visitor.rs | 4 ++-- src/libsyntax/ast.rs | 3 +-- src/libsyntax/feature_gate/check.rs | 4 ++-- src/libsyntax/mut_visit.rs | 2 +- src/libsyntax/print/pprust.rs | 2 +- src/libsyntax/visit.rs | 4 ++-- src/libsyntax_ext/deriving/generic/mod.rs | 2 +- 16 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 78df14adc5d..50733512fae 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -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) diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index f25714f741b..f0543b9057d 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -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!(), diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index da8eae6028e..e84ac82942c 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -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)) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 8916fc08838..1fc89961889 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -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) => { diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index a7c98886622..0840a1551db 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -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. diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 609885cb254..e90231f984b 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -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", " = ;"); } - AssocItemKind::Method(sig, body) => { + AssocItemKind::Fn(sig, body) => { self.check_impl_item_provided(ii.span, body, "function", " { }"); 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); diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index dc301375440..e94e0dc695c 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -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); } diff --git a/src/librustc_resolve/def_collector.rs b/src/librustc_resolve/def_collector.rs index 6e26553d82f..9bae339f80e 100644 --- a/src/librustc_resolve/def_collector.rs +++ b/src/librustc_resolve/def_collector.rs @@ -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), diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index ad29fd9e1db..ec9c2a5b75d 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -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, diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 3b36c1c70f9..df6ad51d104 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -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(), diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 1b729ebaf43..f7f84333857 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1634,8 +1634,7 @@ pub enum AssocItemKind { Const(P, Option>), /// An associated function. - /// FIXME(Centril): Rename to `Fn`. - Method(FnSig, Option>), + Fn(FnSig, Option>), /// An associated type. TyAlias(GenericBounds, Option>), diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index fcce9d4e95f..871ec2c008e 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -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, diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 18d42f9dd66..2a6cff5971c 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -955,7 +955,7 @@ pub fn noop_flat_map_assoc_item(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)); } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 9e4615f60c0..87f6ae85b69 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -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(""); } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index e2c0ee61467..51e7fa1eb38 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -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); } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 1c1fcc4f301..b7707bfb8e5 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -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, } }