Skip to content

Commit

Permalink
Rollup merge of rust-lang#69738 - mark-i-m:assoc-fn-2, r=Centril
Browse files Browse the repository at this point in the history
More Method -> AssocFn renaming

r? @Centril @eddyb

cc rust-lang#60163

Blocked on rust-lang#69674
  • Loading branch information
JohnTitor authored Mar 14, 2020
2 parents abbb9f4 + b9aef25 commit 7cae549
Show file tree
Hide file tree
Showing 38 changed files with 104 additions and 109 deletions.
8 changes: 4 additions & 4 deletions src/librustc/hir/map/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl MaybeFnLike for hir::Item<'_> {
impl MaybeFnLike for hir::ImplItem<'_> {
fn is_fn_like(&self) -> bool {
match self.kind {
hir::ImplItemKind::Method(..) => true,
hir::ImplItemKind::Fn(..) => true,
_ => false,
}
}
Expand All @@ -60,7 +60,7 @@ impl MaybeFnLike for hir::ImplItem<'_> {
impl MaybeFnLike for hir::TraitItem<'_> {
fn is_fn_like(&self) -> bool {
match self.kind {
hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => true,
hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => true,
_ => false,
}
}
Expand Down Expand Up @@ -239,13 +239,13 @@ impl<'a> FnLikeNode<'a> {
_ => bug!("item FnLikeNode that is not fn-like"),
},
Node::TraitItem(ti) => match ti.kind {
hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => {
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs)
}
_ => bug!("trait method FnLikeNode that is not fn-like"),
},
Node::ImplItem(ii) => match ii.kind {
hir::ImplItemKind::Method(ref sig, body) => {
hir::ImplItemKind::Fn(ref sig, body) => {
method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
}
_ => bug!("impl method FnLikeNode that is not fn-like"),
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<'hir> Entry<'hir> {
},

Node::ImplItem(ref item) => match item.kind {
ImplItemKind::Method(ref sig, _) => Some(&sig.decl),
ImplItemKind::Fn(ref sig, _) => Some(&sig.decl),
_ => None,
},

Expand All @@ -82,7 +82,7 @@ impl<'hir> Entry<'hir> {
},

Node::ImplItem(item) => match &item.kind {
ImplItemKind::Method(sig, _) => Some(sig),
ImplItemKind::Fn(sig, _) => Some(sig),
_ => None,
},

Expand All @@ -101,12 +101,12 @@ impl<'hir> Entry<'hir> {

Node::TraitItem(item) => match item.kind {
TraitItemKind::Const(_, Some(body))
| TraitItemKind::Fn(_, TraitMethod::Provided(body)) => Some(body),
| TraitItemKind::Fn(_, TraitFn::Provided(body)) => Some(body),
_ => None,
},

Node::ImplItem(item) => match item.kind {
ImplItemKind::Const(_, body) | ImplItemKind::Method(_, body) => Some(body),
ImplItemKind::Const(_, body) | ImplItemKind::Fn(_, body) => Some(body),
_ => None,
},

Expand Down Expand Up @@ -331,7 +331,7 @@ impl<'hir> Map<'hir> {
},
Node::ImplItem(item) => match item.kind {
ImplItemKind::Const(..) => DefKind::AssocConst,
ImplItemKind::Method(..) => DefKind::AssocFn,
ImplItemKind::Fn(..) => DefKind::AssocFn,
ImplItemKind::TyAlias(..) => DefKind::AssocTy,
ImplItemKind::OpaqueTy(..) => DefKind::AssocOpaqueTy,
},
Expand Down Expand Up @@ -473,7 +473,7 @@ impl<'hir> Map<'hir> {
Node::Ctor(..)
| Node::Item(&Item { kind: ItemKind::Fn(..), .. })
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(..), .. })
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Method(..), .. }) => BodyOwnerKind::Fn,
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(..), .. }) => BodyOwnerKind::Fn,
Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => BodyOwnerKind::Static(m),
Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => BodyOwnerKind::Closure,
node => bug!("{:#?} is not a body node", node),
Expand Down Expand Up @@ -804,7 +804,7 @@ impl<'hir> Map<'hir> {
_ => false,
},
Node::ImplItem(ii) => match ii.kind {
ImplItemKind::Method(..) => true,
ImplItemKind::Fn(..) => true,
_ => false,
},
Node::Block(_) => true,
Expand Down Expand Up @@ -1300,7 +1300,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
ImplItemKind::Const(..) => {
format!("assoc const {} in {}{}", ii.ident, path_str(), id_str)
}
ImplItemKind::Method(..) => format!("method {} in {}{}", ii.ident, path_str(), id_str),
ImplItemKind::Fn(..) => format!("method {} in {}{}", ii.ident, path_str(), id_str),
ImplItemKind::TyAlias(_) => {
format!("assoc type {} in {}{}", ii.ident, path_str(), id_str)
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_ast_lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let names = self.lower_fn_params_to_names(&sig.decl);
let (generics, sig) =
self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
(generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::Required(names)))
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)))
}
AssocItemKind::Fn(_, ref sig, ref generics, Some(ref body)) => {
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
let (generics, sig) =
self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
(generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::Provided(body_id)))
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)))
}
AssocItemKind::TyAlias(_, ref generics, ref bounds, ref default) => {
let ty = default.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed()));
Expand Down Expand Up @@ -838,7 +838,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
asyncness.opt_return_id(),
);

(generics, hir::ImplItemKind::Method(sig, body_id))
(generics, hir::ImplItemKind::Fn(sig, body_id))
}
AssocItemKind::TyAlias(_, generics, _, ty) => {
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn reachable_non_generics_provider(
// Only consider nodes that actually have exported symbols.
Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. })
| Node::Item(&hir::Item { kind: hir::ItemKind::Fn(..), .. })
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Method(..), .. }) => {
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) => {
let def_id = tcx.hir().local_def_id(hir_id);
let generics = tcx.generics_of(def_id);
if !generics.requires_monomorphization(tcx) &&
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,7 @@ pub struct TraitItem<'hir> {

/// Represents a trait method's body (or just argument names).
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub enum TraitMethod<'hir> {
pub enum TraitFn<'hir> {
/// No default body in the trait, just a signature.
Required(&'hir [Ident]),

Expand All @@ -1864,7 +1864,7 @@ pub enum TraitItemKind<'hir> {
/// An associated constant with an optional value (otherwise `impl`s must contain a value).
Const(&'hir Ty<'hir>, Option<BodyId>),
/// An associated function with an optional body.
Fn(FnSig<'hir>, TraitMethod<'hir>),
Fn(FnSig<'hir>, TraitFn<'hir>),
/// An associated type with (possibly empty) bounds and optional concrete
/// type.
Type(GenericBounds<'hir>, Option<&'hir Ty<'hir>>),
Expand Down Expand Up @@ -1897,8 +1897,8 @@ pub enum ImplItemKind<'hir> {
/// An associated constant of the given type, set to the constant result
/// of the expression.
Const(&'hir Ty<'hir>, BodyId),
/// A method implementation with the given signature and body.
Method(FnSig<'hir>, BodyId),
/// An associated function implementation with the given signature and body.
Fn(FnSig<'hir>, BodyId),
/// An associated type.
TyAlias(&'hir Ty<'hir>),
/// An associated `type = impl Trait`.
Expand All @@ -1909,7 +1909,7 @@ impl ImplItemKind<'_> {
pub fn namespace(&self) -> Namespace {
match self {
ImplItemKind::OpaqueTy(..) | ImplItemKind::TyAlias(..) => Namespace::TypeNS,
ImplItemKind::Const(..) | ImplItemKind::Method(..) => Namespace::ValueNS,
ImplItemKind::Const(..) | ImplItemKind::Fn(..) => Namespace::ValueNS,
}
}
}
Expand Down Expand Up @@ -2700,7 +2700,7 @@ impl Node<'_> {
pub fn fn_decl(&self) -> Option<&FnDecl<'_>> {
match self {
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
| Node::ImplItem(ImplItem { kind: ImplItemKind::Method(fn_sig, _), .. })
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
| Node::Item(Item { kind: ItemKind::Fn(fn_sig, _, _), .. }) => Some(fn_sig.decl),
Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => {
Some(fn_decl)
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,14 +911,14 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
visitor.visit_ty(ty);
walk_list!(visitor, visit_nested_body, default);
}
TraitItemKind::Fn(ref sig, TraitMethod::Required(param_names)) => {
TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => {
visitor.visit_id(trait_item.hir_id);
visitor.visit_fn_decl(&sig.decl);
for &param_name in param_names {
visitor.visit_ident(param_name);
}
}
TraitItemKind::Fn(ref sig, TraitMethod::Provided(body_id)) => {
TraitItemKind::Fn(ref sig, TraitFn::Provided(body_id)) => {
visitor.visit_fn(
FnKind::Method(trait_item.ident, sig, None, &trait_item.attrs),
&sig.decl,
Expand Down Expand Up @@ -968,7 +968,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
visitor.visit_ty(ty);
visitor.visit_nested_body(body);
}
ImplItemKind::Method(ref sig, body_id) => {
ImplItemKind::Fn(ref sig, body_id) => {
visitor.visit_fn(
FnKind::Method(impl_item.ident, sig, Some(&impl_item.vis), &impl_item.attrs),
&sig.decl,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,13 +886,13 @@ impl<'a> State<'a> {
Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Inherited };
self.print_associated_const(ti.ident, &ty, default, &vis);
}
hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Required(ref arg_names)) => {
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(ref arg_names)) => {
let vis =
Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Inherited };
self.print_method_sig(ti.ident, sig, &ti.generics, &vis, arg_names, None);
self.s.word(";");
}
hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => {
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
let vis =
Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Inherited };
self.head("");
Expand Down Expand Up @@ -925,7 +925,7 @@ impl<'a> State<'a> {
hir::ImplItemKind::Const(ref ty, expr) => {
self.print_associated_const(ii.ident, &ty, Some(expr), &ii.vis);
}
hir::ImplItemKind::Method(ref sig, body) => {
hir::ImplItemKind::Fn(ref sig, body) => {
self.head("");
self.print_method_sig(ii.ident, sig, &ii.generics, &ii.vis, &[], Some(body));
self.nbsp();
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_hir/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ impl Target {
pub fn from_trait_item(trait_item: &TraitItem<'_>) -> Target {
match trait_item.kind {
TraitItemKind::Const(..) => Target::AssocConst,
TraitItemKind::Fn(_, hir::TraitMethod::Required(_)) => {
TraitItemKind::Fn(_, hir::TraitFn::Required(_)) => {
Target::Method(MethodKind::Trait { body: false })
}
TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => {
TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => {
Target::Method(MethodKind::Trait { body: true })
}
TraitItemKind::Type(..) => Target::AssocTy,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl DirtyCleanVisitor<'tcx> {
TraitItemKind::Type(..) => ("NodeTraitType", LABELS_CONST_IN_TRAIT),
},
HirNode::ImplItem(item) => match item.kind {
ImplItemKind::Method(..) => ("Node::ImplItem", LABELS_FN_IN_IMPL),
ImplItemKind::Fn(..) => ("Node::ImplItem", LABELS_FN_IN_IMPL),
ImplItemKind::Const(..) => ("NodeImplConst", LABELS_CONST_IN_IMPL),
ImplItemKind::TyAlias(..) => ("NodeImplType", LABELS_CONST_IN_IMPL),
ImplItemKind::OpaqueTy(..) => ("NodeImplType", LABELS_CONST_IN_IMPL),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ fn trait_item_scope_tag(item: &hir::TraitItem<'_>) -> &'static str {

fn impl_item_scope_tag(item: &hir::ImplItem<'_>) -> &'static str {
match item.kind {
hir::ImplItemKind::Method(..) => "method body",
hir::ImplItemKind::Fn(..) => "method body",
hir::ImplItemKind::Const(..)
| hir::ImplItemKind::OpaqueTy(..)
| hir::ImplItemKind::TyAlias(..) => "associated item",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
..
})
| Node::ImplItem(&hir::ImplItem {
kind: hir::ImplItemKind::Method(ref m, ..),
kind: hir::ImplItemKind::Fn(ref m, ..),
..
}) => &m.decl,
_ => return None,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_infer/traits/error_reporting/on_unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
})
}
hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(body_id)),
kind: hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(body_id)),
..
}) => self.describe_generator(*body_id).or_else(|| Some("a trait method")),
hir::Node::ImplItem(hir::ImplItem {
kind: hir::ImplItemKind::Method(sig, body_id),
kind: hir::ImplItemKind::Fn(sig, body_id),
..
}) => self.describe_generator(*body_id).or_else(|| {
Some(if let hir::FnHeader { asyncness: hir::IsAsync::Async, .. } = sig.header {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_infer/traits/error_reporting/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
})
| hir::Node::ImplItem(hir::ImplItem {
generics,
kind: hir::ImplItemKind::Method(..),
kind: hir::ImplItemKind::Fn(..),
..
})
| hir::Node::Item(hir::Item {
Expand Down Expand Up @@ -798,7 +798,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
Node::Item(&hir::Item { span, kind: hir::ItemKind::Fn(ref sig, ..), .. })
| Node::ImplItem(&hir::ImplItem {
span,
kind: hir::ImplItemKind::Method(ref sig, _),
kind: hir::ImplItemKind::Fn(ref sig, _),
..
})
| Node::TraitItem(&hir::TraitItem {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {

let desc = match impl_item.kind {
hir::ImplItemKind::Const(..) => "an associated constant",
hir::ImplItemKind::Method(..) => "a method",
hir::ImplItemKind::Fn(..) => "a method",
hir::ImplItemKind::TyAlias(_) => "an associated type",
hir::ImplItemKind::OpaqueTy(_) => "an associated `impl Trait` type",
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
}

fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::TraitItem<'_>) {
if let hir::TraitItemKind::Fn(_, hir::TraitMethod::Required(pnames)) = item.kind {
if let hir::TraitItemKind::Fn(_, hir::TraitFn::Required(pnames)) = item.kind {
self.check_snake_case(cx, "trait method", &item.ident);
for param_name in pnames {
self.check_snake_case(cx, "variable", param_name);
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_metadata/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ impl EntryKind {
EntryKind::Struct(_, _) => DefKind::Struct,
EntryKind::Union(_, _) => DefKind::Union,
EntryKind::Fn(_) | EntryKind::ForeignFn(_) => DefKind::Fn,
EntryKind::Method(_) => DefKind::AssocFn,
EntryKind::AssocFn(_) => DefKind::AssocFn,
EntryKind::Type => DefKind::TyAlias,
EntryKind::TypeParam => DefKind::TyParam,
EntryKind::ConstParam => DefKind::ConstParam,
Expand Down Expand Up @@ -1067,7 +1067,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {

let (kind, container, has_self) = match self.kind(id) {
EntryKind::AssocConst(container, _, _) => (ty::AssocKind::Const, container, false),
EntryKind::Method(data) => {
EntryKind::AssocFn(data) => {
let data = data.decode(self);
(ty::AssocKind::Method, data.container, data.has_self)
}
Expand Down Expand Up @@ -1249,7 +1249,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
fn get_fn_param_names(&self, id: DefIndex) -> Vec<ast::Name> {
let param_names = match self.kind(id) {
EntryKind::Fn(data) | EntryKind::ForeignFn(data) => data.decode(self).param_names,
EntryKind::Method(data) => data.decode(self).fn_data.param_names,
EntryKind::AssocFn(data) => data.decode(self).fn_data.param_names,
_ => Lazy::empty(),
};
param_names.decode(self).collect()
Expand Down Expand Up @@ -1286,7 +1286,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
// don't serialize constness for tuple variant and tuple struct constructors.
fn is_const_fn_raw(&self, id: DefIndex) -> bool {
let constness = match self.kind(id) {
EntryKind::Method(data) => data.decode(self).fn_data.constness,
EntryKind::AssocFn(data) => data.decode(self).fn_data.constness,
EntryKind::Fn(data) => data.decode(self).constness,
// Some intrinsics can be const fn. While we could recompute this (at least until we
// stop having hardcoded whitelists and move to stability attributes), it seems cleaner
Expand All @@ -1301,7 +1301,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
fn asyncness(&self, id: DefIndex) -> hir::IsAsync {
match self.kind(id) {
EntryKind::Fn(data) => data.decode(self).asyncness,
EntryKind::Method(data) => data.decode(self).fn_data.asyncness,
EntryKind::AssocFn(data) => data.decode(self).fn_data.asyncness,
EntryKind::ForeignFn(data) => data.decode(self).asyncness,
_ => bug!("asyncness: expected function kind"),
}
Expand Down
Loading

0 comments on commit 7cae549

Please sign in to comment.