Skip to content

Commit 0d7c82e

Browse files
authored
Rollup merge of rust-lang#69738 - mark-i-m:assoc-fn-2, r=eddyb
More Method -> AssocFn renaming r? @Centril @eddyb cc rust-lang#60163 Blocked on rust-lang#69674
2 parents 1685264 + 1b92e86 commit 0d7c82e

File tree

39 files changed

+107
-111
lines changed

39 files changed

+107
-111
lines changed

src/librustc/hir/map/blocks.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl MaybeFnLike for hir::Item<'_> {
5151
impl MaybeFnLike for hir::ImplItem<'_> {
5252
fn is_fn_like(&self) -> bool {
5353
match self.kind {
54-
hir::ImplItemKind::Method(..) => true,
54+
hir::ImplItemKind::Fn(..) => true,
5555
_ => false,
5656
}
5757
}
@@ -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::Fn(_, hir::TraitMethod::Provided(_)) => true,
63+
hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => true,
6464
_ => false,
6565
}
6666
}
@@ -239,13 +239,13 @@ impl<'a> FnLikeNode<'a> {
239239
_ => bug!("item FnLikeNode that is not fn-like"),
240240
},
241241
Node::TraitItem(ti) => match ti.kind {
242-
hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => {
242+
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::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"),
246246
},
247247
Node::ImplItem(ii) => match ii.kind {
248-
hir::ImplItemKind::Method(ref sig, body) => {
248+
hir::ImplItemKind::Fn(ref sig, body) => {
249249
method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
250250
}
251251
_ => bug!("impl method FnLikeNode that is not fn-like"),

src/librustc/hir/map/mod.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn fn_decl<'hir>(node: Node<'hir>) -> Option<&'hir FnDecl<'hir>> {
5656
},
5757

5858
Node::ImplItem(ref item) => match item.kind {
59-
ImplItemKind::Method(ref sig, _) => Some(&sig.decl),
59+
ImplItemKind::Fn(ref sig, _) => Some(&sig.decl),
6060
_ => None,
6161
},
6262

@@ -82,7 +82,7 @@ fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
8282
},
8383

8484
Node::ImplItem(item) => match &item.kind {
85-
ImplItemKind::Method(sig, _) => Some(sig),
85+
ImplItemKind::Fn(sig, _) => Some(sig),
8686
_ => None,
8787
},
8888

@@ -100,13 +100,14 @@ fn associated_body<'hir>(node: Node<'hir>) -> Option<BodyId> {
100100
},
101101

102102
Node::TraitItem(item) => match item.kind {
103-
TraitItemKind::Const(_, Some(body))
104-
| TraitItemKind::Fn(_, TraitMethod::Provided(body)) => Some(body),
103+
TraitItemKind::Const(_, Some(body)) | TraitItemKind::Fn(_, TraitFn::Provided(body)) => {
104+
Some(body)
105+
}
105106
_ => None,
106107
},
107108

108109
Node::ImplItem(item) => match item.kind {
109-
ImplItemKind::Const(_, body) | ImplItemKind::Method(_, body) => Some(body),
110+
ImplItemKind::Const(_, body) | ImplItemKind::Fn(_, body) => Some(body),
110111
_ => None,
111112
},
112113

@@ -299,7 +300,7 @@ impl<'hir> Map<'hir> {
299300
},
300301
Node::ImplItem(item) => match item.kind {
301302
ImplItemKind::Const(..) => DefKind::AssocConst,
302-
ImplItemKind::Method(..) => DefKind::AssocFn,
303+
ImplItemKind::Fn(..) => DefKind::AssocFn,
303304
ImplItemKind::TyAlias(..) => DefKind::AssocTy,
304305
ImplItemKind::OpaqueTy(..) => DefKind::AssocOpaqueTy,
305306
},
@@ -443,7 +444,7 @@ impl<'hir> Map<'hir> {
443444
Node::Ctor(..)
444445
| Node::Item(&Item { kind: ItemKind::Fn(..), .. })
445446
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(..), .. })
446-
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Method(..), .. }) => BodyOwnerKind::Fn,
447+
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(..), .. }) => BodyOwnerKind::Fn,
447448
Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => BodyOwnerKind::Static(m),
448449
Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => BodyOwnerKind::Closure,
449450
node => bug!("{:#?} is not a body node", node),
@@ -749,7 +750,7 @@ impl<'hir> Map<'hir> {
749750
_ => false,
750751
},
751752
Node::ImplItem(ii) => match ii.kind {
752-
ImplItemKind::Method(..) => true,
753+
ImplItemKind::Fn(..) => true,
753754
_ => false,
754755
},
755756
Node::Block(_) => true,
@@ -1110,7 +1111,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
11101111
ImplItemKind::Const(..) => {
11111112
format!("assoc const {} in {}{}", ii.ident, path_str(), id_str)
11121113
}
1113-
ImplItemKind::Method(..) => format!("method {} in {}{}", ii.ident, path_str(), id_str),
1114+
ImplItemKind::Fn(..) => format!("method {} in {}{}", ii.ident, path_str(), id_str),
11141115
ImplItemKind::TyAlias(_) => {
11151116
format!("assoc type {} in {}{}", ii.ident, path_str(), id_str)
11161117
}

src/librustc_ast_lowering/item.rs

+3-3
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::Fn(sig, hir::TraitMethod::Required(names)))
764+
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::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::Fn(sig, hir::TraitMethod::Provided(body_id)))
770+
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::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()));
@@ -838,7 +838,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
838838
asyncness.opt_return_id(),
839839
);
840840

841-
(generics, hir::ImplItemKind::Method(sig, body_id))
841+
(generics, hir::ImplItemKind::Fn(sig, body_id))
842842
}
843843
AssocItemKind::TyAlias(_, generics, _, ty) => {
844844
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());

src/librustc_codegen_ssa/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn reachable_non_generics_provider(
8888
// Only consider nodes that actually have exported symbols.
8989
Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. })
9090
| Node::Item(&hir::Item { kind: hir::ItemKind::Fn(..), .. })
91-
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Method(..), .. }) => {
91+
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) => {
9292
let def_id = tcx.hir().local_def_id(hir_id);
9393
let generics = tcx.generics_of(def_id);
9494
if !generics.requires_monomorphization(tcx) &&

src/librustc_hir/hir.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ pub struct TraitItem<'hir> {
18541854

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

@@ -1868,7 +1868,7 @@ pub enum TraitItemKind<'hir> {
18681868
/// An associated constant with an optional value (otherwise `impl`s must contain a value).
18691869
Const(&'hir Ty<'hir>, Option<BodyId>),
18701870
/// An associated function with an optional body.
1871-
Fn(FnSig<'hir>, TraitMethod<'hir>),
1871+
Fn(FnSig<'hir>, TraitFn<'hir>),
18721872
/// An associated type with (possibly empty) bounds and optional concrete
18731873
/// type.
18741874
Type(GenericBounds<'hir>, Option<&'hir Ty<'hir>>),
@@ -1901,8 +1901,8 @@ pub enum ImplItemKind<'hir> {
19011901
/// An associated constant of the given type, set to the constant result
19021902
/// of the expression.
19031903
Const(&'hir Ty<'hir>, BodyId),
1904-
/// A method implementation with the given signature and body.
1905-
Method(FnSig<'hir>, BodyId),
1904+
/// An associated function implementation with the given signature and body.
1905+
Fn(FnSig<'hir>, BodyId),
19061906
/// An associated type.
19071907
TyAlias(&'hir Ty<'hir>),
19081908
/// An associated `type = impl Trait`.
@@ -1913,7 +1913,7 @@ impl ImplItemKind<'_> {
19131913
pub fn namespace(&self) -> Namespace {
19141914
match self {
19151915
ImplItemKind::OpaqueTy(..) | ImplItemKind::TyAlias(..) => Namespace::TypeNS,
1916-
ImplItemKind::Const(..) | ImplItemKind::Method(..) => Namespace::ValueNS,
1916+
ImplItemKind::Const(..) | ImplItemKind::Fn(..) => Namespace::ValueNS,
19171917
}
19181918
}
19191919
}
@@ -2704,7 +2704,7 @@ impl Node<'_> {
27042704
pub fn fn_decl(&self) -> Option<&FnDecl<'_>> {
27052705
match self {
27062706
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
2707-
| Node::ImplItem(ImplItem { kind: ImplItemKind::Method(fn_sig, _), .. })
2707+
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
27082708
| Node::Item(Item { kind: ItemKind::Fn(fn_sig, _, _), .. }) => Some(fn_sig.decl),
27092709
Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => {
27102710
Some(fn_decl)

src/librustc_hir/intravisit.rs

+3-3
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::Fn(ref sig, TraitMethod::Required(param_names)) => {
914+
TraitItemKind::Fn(ref sig, TraitFn::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::Fn(ref sig, TraitMethod::Provided(body_id)) => {
921+
TraitItemKind::Fn(ref sig, TraitFn::Provided(body_id)) => {
922922
visitor.visit_fn(
923923
FnKind::Method(trait_item.ident, sig, None, &trait_item.attrs),
924924
&sig.decl,
@@ -968,7 +968,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
968968
visitor.visit_ty(ty);
969969
visitor.visit_nested_body(body);
970970
}
971-
ImplItemKind::Method(ref sig, body_id) => {
971+
ImplItemKind::Fn(ref sig, body_id) => {
972972
visitor.visit_fn(
973973
FnKind::Method(impl_item.ident, sig, Some(&impl_item.vis), &impl_item.attrs),
974974
&sig.decl,

src/librustc_hir/print.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -886,13 +886,13 @@ impl<'a> State<'a> {
886886
Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Inherited };
887887
self.print_associated_const(ti.ident, &ty, default, &vis);
888888
}
889-
hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Required(ref arg_names)) => {
889+
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(ref arg_names)) => {
890890
let vis =
891891
Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Inherited };
892892
self.print_method_sig(ti.ident, sig, &ti.generics, &vis, arg_names, None);
893893
self.s.word(";");
894894
}
895-
hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => {
895+
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
896896
let vis =
897897
Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Inherited };
898898
self.head("");
@@ -925,7 +925,7 @@ impl<'a> State<'a> {
925925
hir::ImplItemKind::Const(ref ty, expr) => {
926926
self.print_associated_const(ii.ident, &ty, Some(expr), &ii.vis);
927927
}
928-
hir::ImplItemKind::Method(ref sig, body) => {
928+
hir::ImplItemKind::Fn(ref sig, body) => {
929929
self.head("");
930930
self.print_method_sig(ii.ident, sig, &ii.generics, &ii.vis, &[], Some(body));
931931
self.nbsp();

src/librustc_hir/target.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ impl Target {
105105
pub fn from_trait_item(trait_item: &TraitItem<'_>) -> Target {
106106
match trait_item.kind {
107107
TraitItemKind::Const(..) => Target::AssocConst,
108-
TraitItemKind::Fn(_, hir::TraitMethod::Required(_)) => {
108+
TraitItemKind::Fn(_, hir::TraitFn::Required(_)) => {
109109
Target::Method(MethodKind::Trait { body: false })
110110
}
111-
TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => {
111+
TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => {
112112
Target::Method(MethodKind::Trait { body: true })
113113
}
114114
TraitItemKind::Type(..) => Target::AssocTy,

src/librustc_incremental/persist/dirty_clean.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl DirtyCleanVisitor<'tcx> {
333333
TraitItemKind::Type(..) => ("NodeTraitType", LABELS_CONST_IN_TRAIT),
334334
},
335335
HirNode::ImplItem(item) => match item.kind {
336-
ImplItemKind::Method(..) => ("Node::ImplItem", LABELS_FN_IN_IMPL),
336+
ImplItemKind::Fn(..) => ("Node::ImplItem", LABELS_FN_IN_IMPL),
337337
ImplItemKind::Const(..) => ("NodeImplConst", LABELS_CONST_IN_IMPL),
338338
ImplItemKind::TyAlias(..) => ("NodeImplType", LABELS_CONST_IN_IMPL),
339339
ImplItemKind::OpaqueTy(..) => ("NodeImplType", LABELS_CONST_IN_IMPL),

src/librustc_infer/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ fn trait_item_scope_tag(item: &hir::TraitItem<'_>) -> &'static str {
275275

276276
fn impl_item_scope_tag(item: &hir::ImplItem<'_>) -> &'static str {
277277
match item.kind {
278-
hir::ImplItemKind::Method(..) => "method body",
278+
hir::ImplItemKind::Fn(..) => "method body",
279279
hir::ImplItemKind::Const(..)
280280
| hir::ImplItemKind::OpaqueTy(..)
281281
| hir::ImplItemKind::TyAlias(..) => "associated item",

src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
3737
..
3838
})
3939
| Node::ImplItem(&hir::ImplItem {
40-
kind: hir::ImplItemKind::Method(ref m, ..),
40+
kind: hir::ImplItemKind::Fn(ref m, ..),
4141
..
4242
}) => &m.decl,
4343
_ => return None,

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
486486

487487
let desc = match impl_item.kind {
488488
hir::ImplItemKind::Const(..) => "an associated constant",
489-
hir::ImplItemKind::Method(..) => "a method",
489+
hir::ImplItemKind::Fn(..) => "a method",
490490
hir::ImplItemKind::TyAlias(_) => "an associated type",
491491
hir::ImplItemKind::OpaqueTy(_) => "an associated `impl Trait` type",
492492
};

src/librustc_lint/nonstandard_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
343343
}
344344

345345
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::TraitItem<'_>) {
346-
if let hir::TraitItemKind::Fn(_, hir::TraitMethod::Required(pnames)) = item.kind {
346+
if let hir::TraitItemKind::Fn(_, hir::TraitFn::Required(pnames)) = item.kind {
347347
self.check_snake_case(cx, "trait method", &item.ident);
348348
for param_name in pnames {
349349
self.check_snake_case(cx, "variable", param_name);

src/librustc_metadata/rmeta/decoder.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ impl EntryKind {
505505
EntryKind::Struct(_, _) => DefKind::Struct,
506506
EntryKind::Union(_, _) => DefKind::Union,
507507
EntryKind::Fn(_) | EntryKind::ForeignFn(_) => DefKind::Fn,
508-
EntryKind::Method(_) => DefKind::AssocFn,
508+
EntryKind::AssocFn(_) => DefKind::AssocFn,
509509
EntryKind::Type => DefKind::TyAlias,
510510
EntryKind::TypeParam => DefKind::TyParam,
511511
EntryKind::ConstParam => DefKind::ConstParam,
@@ -1067,7 +1067,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10671067

10681068
let (kind, container, has_self) = match self.kind(id) {
10691069
EntryKind::AssocConst(container, _, _) => (ty::AssocKind::Const, container, false),
1070-
EntryKind::Method(data) => {
1070+
EntryKind::AssocFn(data) => {
10711071
let data = data.decode(self);
10721072
(ty::AssocKind::Method, data.container, data.has_self)
10731073
}
@@ -1249,7 +1249,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12491249
fn get_fn_param_names(&self, id: DefIndex) -> Vec<ast::Name> {
12501250
let param_names = match self.kind(id) {
12511251
EntryKind::Fn(data) | EntryKind::ForeignFn(data) => data.decode(self).param_names,
1252-
EntryKind::Method(data) => data.decode(self).fn_data.param_names,
1252+
EntryKind::AssocFn(data) => data.decode(self).fn_data.param_names,
12531253
_ => Lazy::empty(),
12541254
};
12551255
param_names.decode(self).collect()
@@ -1286,7 +1286,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12861286
// don't serialize constness for tuple variant and tuple struct constructors.
12871287
fn is_const_fn_raw(&self, id: DefIndex) -> bool {
12881288
let constness = match self.kind(id) {
1289-
EntryKind::Method(data) => data.decode(self).fn_data.constness,
1289+
EntryKind::AssocFn(data) => data.decode(self).fn_data.constness,
12901290
EntryKind::Fn(data) => data.decode(self).constness,
12911291
// Some intrinsics can be const fn. While we could recompute this (at least until we
12921292
// stop having hardcoded whitelists and move to stability attributes), it seems cleaner
@@ -1301,7 +1301,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13011301
fn asyncness(&self, id: DefIndex) -> hir::IsAsync {
13021302
match self.kind(id) {
13031303
EntryKind::Fn(data) => data.decode(self).asyncness,
1304-
EntryKind::Method(data) => data.decode(self).fn_data.asyncness,
1304+
EntryKind::AssocFn(data) => data.decode(self).fn_data.asyncness,
13051305
EntryKind::ForeignFn(data) => data.decode(self).asyncness,
13061306
_ => bug!("asyncness: expected function kind"),
13071307
}

0 commit comments

Comments
 (0)