Skip to content

Commit

Permalink
rename TraitItemKind::Method -> Fn
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-i-m committed Mar 3, 2020
1 parent 98c7ed6 commit 3aeb9f0
Show file tree
Hide file tree
Showing 31 changed files with 67 additions and 70 deletions.
4 changes: 2 additions & 2 deletions src/librustc/hir/map/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::Method(_, hir::TraitMethod::Provided(_)) => true,
hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => true,
_ => false,
}
}
Expand Down Expand Up @@ -239,7 +239,7 @@ impl<'a> FnLikeNode<'a> {
_ => bug!("item FnLikeNode that is not fn-like"),
},
Node::TraitItem(ti) => match ti.kind {
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => {
hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => {
method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs)
}
_ => bug!("trait method FnLikeNode that is not fn-like"),
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'hir> Entry<'hir> {
},

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

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

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

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

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

Expand Down Expand Up @@ -326,7 +326,7 @@ impl<'hir> Map<'hir> {
},
Node::TraitItem(item) => match item.kind {
TraitItemKind::Const(..) => DefKind::AssocConst,
TraitItemKind::Method(..) => DefKind::AssocFn,
TraitItemKind::Fn(..) => DefKind::AssocFn,
TraitItemKind::Type(..) => DefKind::AssocTy,
},
Node::ImplItem(item) => match item.kind {
Expand Down Expand Up @@ -473,7 +473,7 @@ impl<'hir> Map<'hir> {
| Node::AnonConst(_) => BodyOwnerKind::Const,
Node::Ctor(..)
| Node::Item(&Item { kind: ItemKind::Fn(..), .. })
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Method(..), .. })
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(..), .. })
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Method(..), .. }) => BodyOwnerKind::Fn,
Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => BodyOwnerKind::Static(m),
Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => BodyOwnerKind::Closure,
Expand Down Expand Up @@ -801,7 +801,7 @@ impl<'hir> Map<'hir> {
_ => false,
},
Node::TraitItem(ti) => match ti.kind {
TraitItemKind::Method(..) => true,
TraitItemKind::Fn(..) => true,
_ => false,
},
Node::ImplItem(ii) => match ii.kind {
Expand Down Expand Up @@ -1312,7 +1312,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
Some(Node::TraitItem(ti)) => {
let kind = match ti.kind {
TraitItemKind::Const(..) => "assoc constant",
TraitItemKind::Method(..) => "trait method",
TraitItemKind::Fn(..) => "trait method",
TraitItemKind::Type(..) => "assoc type",
};

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_ast_lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,13 +767,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::Method(sig, hir::TraitMethod::Required(names)))
(generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::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::Method(sig, hir::TraitMethod::Provided(body_id)))
(generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::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
6 changes: 3 additions & 3 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1863,8 +1863,8 @@ pub enum TraitMethod<'hir> {
pub enum TraitItemKind<'hir> {
/// An associated constant with an optional value (otherwise `impl`s must contain a value).
Const(&'hir Ty<'hir>, Option<BodyId>),
/// A method with an optional body.
Method(FnSig<'hir>, TraitMethod<'hir>),
/// An associated function with an optional body.
Fn(FnSig<'hir>, TraitMethod<'hir>),
/// An associated type with (possibly empty) bounds and optional concrete
/// type.
Type(GenericBounds<'hir>, Option<&'hir Ty<'hir>>),
Expand Down Expand Up @@ -2699,7 +2699,7 @@ impl Node<'_> {

pub fn fn_decl(&self) -> Option<&FnDecl<'_>> {
match self {
Node::TraitItem(TraitItem { kind: TraitItemKind::Method(fn_sig, _), .. })
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
| Node::ImplItem(ImplItem { kind: ImplItemKind::Method(fn_sig, _), .. })
| Node::Item(Item { kind: ItemKind::Fn(fn_sig, _, _), .. }) => Some(fn_sig.decl),
Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => {
Expand Down
4 changes: 2 additions & 2 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::Method(ref sig, TraitMethod::Required(param_names)) => {
TraitItemKind::Fn(ref sig, TraitMethod::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::Method(ref sig, TraitMethod::Provided(body_id)) => {
TraitItemKind::Fn(ref sig, TraitMethod::Provided(body_id)) => {
visitor.visit_fn(
FnKind::Method(trait_item.ident, sig, None, &trait_item.attrs),
&sig.decl,
Expand Down
4 changes: 2 additions & 2 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::Method(ref sig, hir::TraitMethod::Required(ref arg_names)) => {
hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::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::Method(ref sig, hir::TraitMethod::Provided(body)) => {
hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => {
let vis =
Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Inherited };
self.head("");
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::Method(_, hir::TraitMethod::Required(_)) => {
TraitItemKind::Fn(_, hir::TraitMethod::Required(_)) => {
Target::Method(MethodKind::Trait { body: false })
}
TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => {
TraitItemKind::Fn(_, hir::TraitMethod::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 @@ -328,7 +328,7 @@ impl DirtyCleanVisitor<'tcx> {
}
}
HirNode::TraitItem(item) => match item.kind {
TraitItemKind::Method(..) => ("Node::TraitItem", LABELS_FN_IN_TRAIT),
TraitItemKind::Fn(..) => ("Node::TraitItem", LABELS_FN_IN_TRAIT),
TraitItemKind::Const(..) => ("NodeTraitConst", LABELS_CONST_IN_TRAIT),
TraitItemKind::Type(..) => ("NodeTraitType", LABELS_CONST_IN_TRAIT),
},
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 @@ -269,7 +269,7 @@ fn item_scope_tag(item: &hir::Item<'_>) -> &'static str {

fn trait_item_scope_tag(item: &hir::TraitItem<'_>) -> &'static str {
match item.kind {
hir::TraitItemKind::Method(..) => "method body",
hir::TraitItemKind::Fn(..) => "method body",
hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => "associated item",
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let fndecl = match self.tcx().hir().get(hir_id) {
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. })
| Node::TraitItem(&hir::TraitItem {
kind: hir::TraitItemKind::Method(ref m, ..),
kind: hir::TraitItemKind::Fn(ref m, ..),
..
})
| Node::ImplItem(&hir::ImplItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
})
}
hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(body_id)),
kind: hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(body_id)),
..
}) => self.describe_generator(*body_id).or_else(|| Some("a trait method")),
hir::Node::ImplItem(hir::ImplItem {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_infer/traits/error_reporting/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
match node {
hir::Node::TraitItem(hir::TraitItem {
generics,
kind: hir::TraitItemKind::Method(..),
kind: hir::TraitItemKind::Fn(..),
..
}) if param_ty && self_ty == self.tcx.types.self_param => {
// Restricting `Self` for a single method.
Expand All @@ -73,7 +73,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. })
| hir::Node::TraitItem(hir::TraitItem {
generics,
kind: hir::TraitItemKind::Method(..),
kind: hir::TraitItemKind::Fn(..),
..
})
| hir::Node::ImplItem(hir::ImplItem {
Expand Down Expand Up @@ -807,7 +807,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
})
| Node::TraitItem(&hir::TraitItem {
span,
kind: hir::TraitItemKind::Method(ref sig, _),
kind: hir::TraitItemKind::Fn(ref sig, _),
..
}) => (
self.tcx.sess.source_map().def_span(span),
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 @@ -465,7 +465,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {

let desc = match trait_item.kind {
hir::TraitItemKind::Const(..) => "an associated constant",
hir::TraitItemKind::Method(..) => "a trait method",
hir::TraitItemKind::Fn(..) => "a trait method",
hir::TraitItemKind::Type(..) => "an associated 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::Method(_, hir::TraitMethod::Required(pnames)) = item.kind {
if let hir::TraitItemKind::Fn(_, hir::TraitMethod::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
2 changes: 1 addition & 1 deletion src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ impl EncodeContext<'tcx> {
)
}
ty::AssocKind::Method => {
let fn_data = if let hir::TraitItemKind::Method(m_sig, m) = &ast_item.kind {
let fn_data = if let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind {
let param_names = match *m {
hir::TraitMethod::Required(ref names) => {
self.encode_fn_param_names(names)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}))
| Some(hir::Node::TraitItem(hir::TraitItem {
ident,
kind: hir::TraitItemKind::Method(sig, _),
kind: hir::TraitItemKind::Fn(sig, _),
..
}))
| Some(hir::Node::ImplItem(hir::ImplItem {
Expand Down Expand Up @@ -520,7 +520,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
hir::Node::Item(hir::Item { ident, kind: hir::ItemKind::Fn(sig, ..), .. })
| hir::Node::TraitItem(hir::TraitItem {
ident,
kind: hir::TraitItemKind::Method(sig, _),
kind: hir::TraitItemKind::Fn(sig, _),
..
})
| hir::Node::ImplItem(hir::ImplItem {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyAndCache<'_> {
})
| Node::TraitItem(hir::TraitItem {
kind:
hir::TraitItemKind::Method(hir::FnSig { decl, .. }, hir::TraitMethod::Provided(body_id)),
hir::TraitItemKind::Fn(hir::FnSig { decl, .. }, hir::TraitMethod::Provided(body_id)),
..
}) => (*body_id, decl.output.span()),
Node::Item(hir::Item { kind: hir::ItemKind::Static(ty, _, body_id), .. })
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_passes/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
let trait_item = self.krate.trait_item(trait_item_ref.id);
match trait_item.kind {
hir::TraitItemKind::Const(_, Some(_))
| hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => {
| hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => {
if has_allow_dead_code_or_lang_attr(
self.tcx,
trait_item.hir_id,
Expand Down Expand Up @@ -682,11 +682,11 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
match trait_item.kind {
hir::TraitItemKind::Const(_, Some(body_id))
| hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(body_id)) => {
| hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(body_id)) => {
self.visit_nested_body(body_id)
}
hir::TraitItemKind::Const(_, None)
| hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_))
| hir::TraitItemKind::Fn(_, hir::TraitMethod::Required(_))
| hir::TraitItemKind::Type(..) => {}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_passes/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
},
Some(Node::TraitItem(trait_method)) => match trait_method.kind {
hir::TraitItemKind::Const(_, ref default) => default.is_some(),
hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => true,
hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_))
hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => true,
hir::TraitItemKind::Fn(_, hir::TraitMethod::Required(_))
| hir::TraitItemKind::Type(..) => false,
},
Some(Node::ImplItem(impl_item)) => {
Expand Down Expand Up @@ -278,11 +278,11 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
Node::TraitItem(trait_method) => {
match trait_method.kind {
hir::TraitItemKind::Const(_, None)
| hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_)) => {
| hir::TraitItemKind::Fn(_, hir::TraitMethod::Required(_)) => {
// Keep going, nothing to get exported
}
hir::TraitItemKind::Const(_, Some(body_id))
| hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(body_id)) => {
| hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(body_id)) => {
self.visit_nested_body(body_id);
}
hir::TraitItemKind::Type(..) => {}
Expand Down
9 changes: 3 additions & 6 deletions src/librustc_resolve/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
use self::hir::TraitItemKind::*;
self.missing_named_lifetime_spots.push((&trait_item.generics).into());
match trait_item.kind {
Method(ref sig, _) => {
Fn(ref sig, _) => {
let tcx = self.tcx;
self.visit_early_late(
Some(tcx.hir().get_parent_item(trait_item.hir_id)),
Expand Down Expand Up @@ -1816,8 +1816,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
match self.tcx.hir().get(fn_id) {
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(..), .. })
| Node::TraitItem(&hir::TraitItem {
kind: hir::TraitItemKind::Method(..),
..
kind: hir::TraitItemKind::Fn(..), ..
})
| Node::ImplItem(&hir::ImplItem {
kind: hir::ImplItemKind::Method(..), ..
Expand Down Expand Up @@ -2093,9 +2092,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
// `fn` definitions and methods.
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(.., body), .. }) => Some(body),

Node::TraitItem(&hir::TraitItem {
kind: hir::TraitItemKind::Method(_, ref m), ..
}) => {
Node::TraitItem(&hir::TraitItem { kind: hir::TraitItemKind::Fn(_, ref m), .. }) => {
if let hir::ItemKind::Trait(.., ref trait_items) =
self.tcx.hir().expect_item(self.tcx.hir().get_parent_item(parent)).kind
{
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_traits/lowering/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ crate fn environment(tcx: TyCtxt<'_>, def_id: DefId) -> Environment<'_> {

let node_kind = match node {
Node::TraitItem(item) => match item.kind {
TraitItemKind::Method(..) => NodeKind::Fn,
TraitItemKind::Fn(..) => NodeKind::Fn,
_ => NodeKind::Other,
},

Expand Down
Loading

0 comments on commit 3aeb9f0

Please sign in to comment.