Skip to content

Commit 9bc7386

Browse files
authored
Rollup merge of #69674 - mark-i-m:assoc-fn, r=matthewjasper
Rename DefKind::Method and TraitItemKind::Method r? @eddyb, @Centril, or @matthewjasper cc #69498 #60163
2 parents 156a05a + 3aeb9f0 commit 9bc7386

File tree

52 files changed

+104
-106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+104
-106
lines changed

src/librustc/hir/map/blocks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl MaybeFnLike for hir::ImplItem<'_> {
6060
impl MaybeFnLike for hir::TraitItem<'_> {
6161
fn is_fn_like(&self) -> bool {
6262
match self.kind {
63-
hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => true,
63+
hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => true,
6464
_ => false,
6565
}
6666
}
@@ -239,7 +239,7 @@ impl<'a> FnLikeNode<'a> {
239239
_ => bug!("item FnLikeNode that is not fn-like"),
240240
},
241241
Node::TraitItem(ti) => match ti.kind {
242-
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => {
242+
hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => {
243243
method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs)
244244
}
245245
_ => bug!("trait method FnLikeNode that is not fn-like"),

src/librustc/hir/map/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'hir> Entry<'hir> {
5151
},
5252

5353
Node::TraitItem(ref item) => match item.kind {
54-
TraitItemKind::Method(ref sig, _) => Some(&sig.decl),
54+
TraitItemKind::Fn(ref sig, _) => Some(&sig.decl),
5555
_ => None,
5656
},
5757

@@ -77,7 +77,7 @@ impl<'hir> Entry<'hir> {
7777
},
7878

7979
Node::TraitItem(item) => match &item.kind {
80-
TraitItemKind::Method(sig, _) => Some(sig),
80+
TraitItemKind::Fn(sig, _) => Some(sig),
8181
_ => None,
8282
},
8383

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

102102
Node::TraitItem(item) => match item.kind {
103103
TraitItemKind::Const(_, Some(body))
104-
| TraitItemKind::Method(_, TraitMethod::Provided(body)) => Some(body),
104+
| TraitItemKind::Fn(_, TraitMethod::Provided(body)) => Some(body),
105105
_ => None,
106106
},
107107

@@ -326,12 +326,12 @@ impl<'hir> Map<'hir> {
326326
},
327327
Node::TraitItem(item) => match item.kind {
328328
TraitItemKind::Const(..) => DefKind::AssocConst,
329-
TraitItemKind::Method(..) => DefKind::Method,
329+
TraitItemKind::Fn(..) => DefKind::AssocFn,
330330
TraitItemKind::Type(..) => DefKind::AssocTy,
331331
},
332332
Node::ImplItem(item) => match item.kind {
333333
ImplItemKind::Const(..) => DefKind::AssocConst,
334-
ImplItemKind::Method(..) => DefKind::Method,
334+
ImplItemKind::Method(..) => DefKind::AssocFn,
335335
ImplItemKind::TyAlias(..) => DefKind::AssocTy,
336336
ImplItemKind::OpaqueTy(..) => DefKind::AssocOpaqueTy,
337337
},
@@ -472,7 +472,7 @@ impl<'hir> Map<'hir> {
472472
| Node::AnonConst(_) => BodyOwnerKind::Const,
473473
Node::Ctor(..)
474474
| Node::Item(&Item { kind: ItemKind::Fn(..), .. })
475-
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Method(..), .. })
475+
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(..), .. })
476476
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Method(..), .. }) => BodyOwnerKind::Fn,
477477
Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => BodyOwnerKind::Static(m),
478478
Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => BodyOwnerKind::Closure,
@@ -800,7 +800,7 @@ impl<'hir> Map<'hir> {
800800
_ => false,
801801
},
802802
Node::TraitItem(ti) => match ti.kind {
803-
TraitItemKind::Method(..) => true,
803+
TraitItemKind::Fn(..) => true,
804804
_ => false,
805805
},
806806
Node::ImplItem(ii) => match ii.kind {
@@ -1311,7 +1311,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
13111311
Some(Node::TraitItem(ti)) => {
13121312
let kind = match ti.kind {
13131313
TraitItemKind::Const(..) => "assoc constant",
1314-
TraitItemKind::Method(..) => "trait method",
1314+
TraitItemKind::Fn(..) => "trait method",
13151315
TraitItemKind::Type(..) => "assoc type",
13161316
};
13171317

src/librustc/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub enum EvalResult {
250250
fn skip_stability_check_due_to_privacy(tcx: TyCtxt<'_>, mut def_id: DefId) -> bool {
251251
// Check if `def_id` is a trait method.
252252
match tcx.def_kind(def_id) {
253-
Some(DefKind::Method) | Some(DefKind::AssocTy) | Some(DefKind::AssocConst) => {
253+
Some(DefKind::AssocFn) | Some(DefKind::AssocTy) | Some(DefKind::AssocConst) => {
254254
if let ty::TraitContainer(trait_def_id) = tcx.associated_item(def_id).container {
255255
// Trait methods do not declare visibility (even
256256
// for visibility info in cstore). Use containing

src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ impl<'tcx> TypeckTables<'tcx> {
611611
}
612612

613613
match self.type_dependent_defs().get(expr.hir_id) {
614-
Some(Ok((DefKind::Method, _))) => true,
614+
Some(Ok((DefKind::AssocFn, _))) => true,
615615
_ => false,
616616
}
617617
}

src/librustc/ty/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl AssocItem {
230230
pub fn def_kind(&self) -> DefKind {
231231
match self.kind {
232232
AssocKind::Const => DefKind::AssocConst,
233-
AssocKind::Method => DefKind::Method,
233+
AssocKind::Method => DefKind::AssocFn,
234234
AssocKind::Type => DefKind::AssocTy,
235235
AssocKind::OpaqueTy => DefKind::AssocOpaqueTy,
236236
}
@@ -2872,7 +2872,7 @@ impl<'tcx> TyCtxt<'tcx> {
28722872
}
28732873
} else {
28742874
match self.def_kind(def_id).expect("no def for `DefId`") {
2875-
DefKind::AssocConst | DefKind::Method | DefKind::AssocTy => true,
2875+
DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => true,
28762876
_ => false,
28772877
}
28782878
};
@@ -3051,7 +3051,7 @@ impl<'tcx> TyCtxt<'tcx> {
30513051
/// `DefId` of the impl that the method belongs to; otherwise, returns `None`.
30523052
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
30533053
let item = if def_id.krate != LOCAL_CRATE {
3054-
if let Some(DefKind::Method) = self.def_kind(def_id) {
3054+
if let Some(DefKind::AssocFn) = self.def_kind(def_id) {
30553055
Some(self.associated_item(def_id))
30563056
} else {
30573057
None

src/librustc_ast_lowering/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
761761
let names = self.lower_fn_params_to_names(&sig.decl);
762762
let (generics, sig) =
763763
self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
764-
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
764+
(generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::Required(names)))
765765
}
766766
AssocItemKind::Fn(_, ref sig, ref generics, Some(ref body)) => {
767767
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
768768
let (generics, sig) =
769769
self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
770-
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Provided(body_id)))
770+
(generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::Provided(body_id)))
771771
}
772772
AssocItemKind::TyAlias(_, ref generics, ref bounds, ref default) => {
773773
let ty = default.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed()));

src/librustc_ast_lowering/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
7575
ParenthesizedGenericArgs::Ok
7676
}
7777
// `a::b::Trait(Args)::TraitItem`
78-
Res::Def(DefKind::Method, _)
78+
Res::Def(DefKind::AssocFn, _)
7979
| Res::Def(DefKind::AssocConst, _)
8080
| Res::Def(DefKind::AssocTy, _)
8181
if i + 2 == proj_start =>

src/librustc_hir/def.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub enum DefKind {
7272
Static,
7373
/// Refers to the struct or enum variant's constructor.
7474
Ctor(CtorOf, CtorKind),
75-
Method,
75+
AssocFn,
7676
AssocConst,
7777

7878
// Macro namespace
@@ -107,7 +107,8 @@ impl DefKind {
107107
DefKind::Union => "union",
108108
DefKind::Trait => "trait",
109109
DefKind::ForeignTy => "foreign type",
110-
DefKind::Method => "method",
110+
// FIXME: Update the description to "assoc fn"
111+
DefKind::AssocFn => "method",
111112
DefKind::Const => "constant",
112113
DefKind::AssocConst => "associated constant",
113114
DefKind::TyParam => "type parameter",
@@ -150,7 +151,7 @@ impl DefKind {
150151
| DefKind::ConstParam
151152
| DefKind::Static
152153
| DefKind::Ctor(..)
153-
| DefKind::Method
154+
| DefKind::AssocFn
154155
| DefKind::AssocConst => ns == Namespace::ValueNS,
155156

156157
DefKind::Macro(..) => ns == Namespace::MacroNS,

src/librustc_hir/hir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,8 +1863,8 @@ pub enum TraitMethod<'hir> {
18631863
pub enum TraitItemKind<'hir> {
18641864
/// An associated constant with an optional value (otherwise `impl`s must contain a value).
18651865
Const(&'hir Ty<'hir>, Option<BodyId>),
1866-
/// A method with an optional body.
1867-
Method(FnSig<'hir>, TraitMethod<'hir>),
1866+
/// An associated function with an optional body.
1867+
Fn(FnSig<'hir>, TraitMethod<'hir>),
18681868
/// An associated type with (possibly empty) bounds and optional concrete
18691869
/// type.
18701870
Type(GenericBounds<'hir>, Option<&'hir Ty<'hir>>),
@@ -2699,7 +2699,7 @@ impl Node<'_> {
26992699

27002700
pub fn fn_decl(&self) -> Option<&FnDecl<'_>> {
27012701
match self {
2702-
Node::TraitItem(TraitItem { kind: TraitItemKind::Method(fn_sig, _), .. })
2702+
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
27032703
| Node::ImplItem(ImplItem { kind: ImplItemKind::Method(fn_sig, _), .. })
27042704
| Node::Item(Item { kind: ItemKind::Fn(fn_sig, _, _), .. }) => Some(fn_sig.decl),
27052705
Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => {

src/librustc_hir/intravisit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,14 +911,14 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
911911
visitor.visit_ty(ty);
912912
walk_list!(visitor, visit_nested_body, default);
913913
}
914-
TraitItemKind::Method(ref sig, TraitMethod::Required(param_names)) => {
914+
TraitItemKind::Fn(ref sig, TraitMethod::Required(param_names)) => {
915915
visitor.visit_id(trait_item.hir_id);
916916
visitor.visit_fn_decl(&sig.decl);
917917
for &param_name in param_names {
918918
visitor.visit_ident(param_name);
919919
}
920920
}
921-
TraitItemKind::Method(ref sig, TraitMethod::Provided(body_id)) => {
921+
TraitItemKind::Fn(ref sig, TraitMethod::Provided(body_id)) => {
922922
visitor.visit_fn(
923923
FnKind::Method(trait_item.ident, sig, None, &trait_item.attrs),
924924
&sig.decl,

0 commit comments

Comments
 (0)