Skip to content

Commit b07e7fe

Browse files
committed
Rename AssocKind::Method to AssocKind::Fn
Rename fn_has_self_argument to fn_has_self_parameter Rename AssocItemKind::Method to AssocItemKind::Fn Refine has_no_input_arg Refine has_no_input_arg Revert has_no_input_arg Refine suggestion_descr Move as_def_kind into AssocKind Signed-off-by: Rustin-Liu <rustin.liu@gmail.com> Fix tidy check issue Signed-off-by: Rustin-Liu <rustin.liu@gmail.com>
1 parent 8e18e26 commit b07e7fe

Some content is hidden

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

44 files changed

+119
-126
lines changed

src/librustc_ast_lowering/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
796796
(hir::AssocItemKind::Type, default.is_some())
797797
}
798798
AssocItemKind::Fn(_, sig, _, default) => {
799-
(hir::AssocItemKind::Method { has_self: sig.decl.has_self() }, default.is_some())
799+
(hir::AssocItemKind::Fn { has_self: sig.decl.has_self() }, default.is_some())
800800
}
801801
AssocItemKind::MacCall(..) => unimplemented!(),
802802
};
@@ -894,7 +894,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
894894
}
895895
}
896896
AssocItemKind::Fn(_, sig, ..) => {
897-
hir::AssocItemKind::Method { has_self: sig.decl.has_self() }
897+
hir::AssocItemKind::Fn { has_self: sig.decl.has_self() }
898898
}
899899
AssocItemKind::MacCall(..) => unimplemented!(),
900900
},

src/librustc_hir/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2515,7 +2515,7 @@ pub struct ImplItemRef<'hir> {
25152515
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
25162516
pub enum AssocItemKind {
25172517
Const,
2518-
Method { has_self: bool },
2518+
Fn { has_self: bool },
25192519
Type,
25202520
OpaqueTy,
25212521
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
118118
// enable E0621 for it.
119119
pub(super) fn is_self_anon(&self, is_first: bool, scope_def_id: DefId) -> bool {
120120
is_first
121-
&& self.tcx().opt_associated_item(scope_def_id).map(|i| i.method_has_self_argument)
121+
&& self.tcx().opt_associated_item(scope_def_id).map(|i| i.fn_has_self_parameter)
122122
== Some(true)
123123
}
124124
}

src/librustc_metadata/rmeta/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11531153
EntryKind::AssocConst(container, _, _) => (ty::AssocKind::Const, container, false),
11541154
EntryKind::AssocFn(data) => {
11551155
let data = data.decode(self);
1156-
(ty::AssocKind::Method, data.container, data.has_self)
1156+
(ty::AssocKind::Fn, data.container, data.has_self)
11571157
}
11581158
EntryKind::AssocType(container) => (ty::AssocKind::Type, container, false),
11591159
EntryKind::AssocOpaqueTy(container) => (ty::AssocKind::OpaqueTy, container, false),
@@ -1167,7 +1167,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11671167
defaultness: container.defaultness(),
11681168
def_id: self.local_def_id(id),
11691169
container: container.with_def_id(parent),
1170-
method_has_self_argument: has_self,
1170+
fn_has_self_parameter: has_self,
11711171
}
11721172
}
11731173

src/librustc_metadata/rmeta/encoder.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ impl EncodeContext<'tcx> {
839839
rendered_const,
840840
)
841841
}
842-
ty::AssocKind::Method => {
842+
ty::AssocKind::Fn => {
843843
let fn_data = if let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind {
844844
let param_names = match *m {
845845
hir::TraitFn::Required(ref names) => {
@@ -860,7 +860,7 @@ impl EncodeContext<'tcx> {
860860
EntryKind::AssocFn(self.lazy(AssocFnData {
861861
fn_data,
862862
container,
863-
has_self: trait_item.method_has_self_argument,
863+
has_self: trait_item.fn_has_self_parameter,
864864
}))
865865
}
866866
ty::AssocKind::Type => EntryKind::AssocType(container),
@@ -874,7 +874,7 @@ impl EncodeContext<'tcx> {
874874
self.encode_const_stability(def_id);
875875
self.encode_deprecation(def_id);
876876
match trait_item.kind {
877-
ty::AssocKind::Const | ty::AssocKind::Method => {
877+
ty::AssocKind::Const | ty::AssocKind::Fn => {
878878
self.encode_item_type(def_id);
879879
}
880880
ty::AssocKind::Type => {
@@ -884,7 +884,7 @@ impl EncodeContext<'tcx> {
884884
}
885885
ty::AssocKind::OpaqueTy => unreachable!(),
886886
}
887-
if trait_item.kind == ty::AssocKind::Method {
887+
if trait_item.kind == ty::AssocKind::Fn {
888888
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
889889
self.encode_variances_of(def_id);
890890
}
@@ -931,7 +931,7 @@ impl EncodeContext<'tcx> {
931931
bug!()
932932
}
933933
}
934-
ty::AssocKind::Method => {
934+
ty::AssocKind::Fn => {
935935
let fn_data = if let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind {
936936
FnData {
937937
asyncness: sig.header.asyncness,
@@ -944,7 +944,7 @@ impl EncodeContext<'tcx> {
944944
EntryKind::AssocFn(self.lazy(AssocFnData {
945945
fn_data,
946946
container,
947-
has_self: impl_item.method_has_self_argument,
947+
has_self: impl_item.fn_has_self_parameter,
948948
}))
949949
}
950950
ty::AssocKind::OpaqueTy => EntryKind::AssocOpaqueTy(container),
@@ -958,7 +958,7 @@ impl EncodeContext<'tcx> {
958958
self.encode_const_stability(def_id);
959959
self.encode_deprecation(def_id);
960960
self.encode_item_type(def_id);
961-
if impl_item.kind == ty::AssocKind::Method {
961+
if impl_item.kind == ty::AssocKind::Fn {
962962
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
963963
self.encode_variances_of(def_id);
964964
}

src/librustc_middle/traits/specialization_graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ impl<'tcx> Node {
107107
.find(move |impl_item| {
108108
match (trait_item_kind, impl_item.kind) {
109109
| (Const, Const)
110-
| (Method, Method)
110+
| (Fn, Fn)
111111
| (Type, Type)
112112
| (Type, OpaqueTy) // assoc. types can be made opaque in impls
113113
=> tcx.hygienic_eq(impl_item.ident, trait_item_name, trait_def_id),
114114

115115
| (Const, _)
116-
| (Method, _)
116+
| (Fn, _)
117117
| (Type, _)
118118
| (OpaqueTy, _)
119119
=> false,

src/librustc_middle/ty/adjustment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'tcx> OverloadedDeref<'tcx> {
123123
let method_def_id = tcx
124124
.associated_items(trait_def_id.unwrap())
125125
.in_definition_order()
126-
.find(|m| m.kind == ty::AssocKind::Method)
126+
.find(|m| m.kind == ty::AssocKind::Fn)
127127
.unwrap()
128128
.def_id;
129129
(method_def_id, tcx.mk_substs_trait(source, &[]))

src/librustc_middle/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl<'tcx> Instance<'tcx> {
366366
let call_once = tcx
367367
.associated_items(fn_once)
368368
.in_definition_order()
369-
.find(|it| it.kind == ty::AssocKind::Method)
369+
.find(|it| it.kind == ty::AssocKind::Fn)
370370
.unwrap()
371371
.def_id;
372372
let def = ty::InstanceDef::ClosureOnceShim { call_once };

src/librustc_middle/ty/mod.rs

+12-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-tidy-filelength
2-
31
pub use self::fold::{TypeFoldable, TypeVisitor};
42
pub use self::AssocItemContainer::*;
53
pub use self::BorrowKind::*;
@@ -192,58 +190,50 @@ pub struct AssocItem {
192190
pub container: AssocItemContainer,
193191

194192
/// Whether this is a method with an explicit self
195-
/// as its first argument, allowing method calls.
196-
pub method_has_self_argument: bool,
193+
/// as its first parameter, allowing method calls.
194+
pub fn_has_self_parameter: bool,
197195
}
198196

199197
#[derive(Copy, Clone, PartialEq, Debug, HashStable)]
200198
pub enum AssocKind {
201199
Const,
202-
Method,
200+
Fn,
203201
OpaqueTy,
204202
Type,
205203
}
206204

207205
impl AssocKind {
208-
pub fn suggestion_descr(&self) -> &'static str {
209-
match self {
210-
ty::AssocKind::Method => "method call",
211-
ty::AssocKind::Type | ty::AssocKind::OpaqueTy => "associated type",
212-
ty::AssocKind::Const => "associated constant",
213-
}
214-
}
215-
216206
pub fn namespace(&self) -> Namespace {
217207
match *self {
218208
ty::AssocKind::OpaqueTy | ty::AssocKind::Type => Namespace::TypeNS,
219-
ty::AssocKind::Const | ty::AssocKind::Method => Namespace::ValueNS,
209+
ty::AssocKind::Const | ty::AssocKind::Fn => Namespace::ValueNS,
220210
}
221211
}
222-
}
223212

224-
impl AssocItem {
225-
pub fn def_kind(&self) -> DefKind {
226-
match self.kind {
213+
pub fn as_def_kind(&self) -> DefKind {
214+
match self {
227215
AssocKind::Const => DefKind::AssocConst,
228-
AssocKind::Method => DefKind::AssocFn,
216+
AssocKind::Fn => DefKind::AssocFn,
229217
AssocKind::Type => DefKind::AssocTy,
230218
AssocKind::OpaqueTy => DefKind::AssocOpaqueTy,
231219
}
232220
}
221+
}
233222

223+
impl AssocItem {
234224
/// Tests whether the associated item admits a non-trivial implementation
235225
/// for !
236226
pub fn relevant_for_never(&self) -> bool {
237227
match self.kind {
238228
AssocKind::OpaqueTy | AssocKind::Const | AssocKind::Type => true,
239229
// FIXME(canndrew): Be more thorough here, check if any argument is uninhabited.
240-
AssocKind::Method => !self.method_has_self_argument,
230+
AssocKind::Fn => !self.fn_has_self_parameter,
241231
}
242232
}
243233

244234
pub fn signature(&self, tcx: TyCtxt<'_>) -> String {
245235
match self.kind {
246-
ty::AssocKind::Method => {
236+
ty::AssocKind::Fn => {
247237
// We skip the binder here because the binder would deanonymize all
248238
// late-bound regions, and we don't want method signatures to show up
249239
// `as for<'r> fn(&'r MyType)`. Pretty-printing handles late-bound
@@ -2664,7 +2654,7 @@ impl<'tcx> TyCtxt<'tcx> {
26642654
pub fn provided_trait_methods(self, id: DefId) -> impl 'tcx + Iterator<Item = &'tcx AssocItem> {
26652655
self.associated_items(id)
26662656
.in_definition_order()
2667-
.filter(|item| item.kind == AssocKind::Method && item.defaultness.has_value())
2657+
.filter(|item| item.kind == AssocKind::Fn && item.defaultness.has_value())
26682658
}
26692659

26702660
pub fn trait_relevant_for_never(self, did: DefId) -> bool {

src/librustc_mir/shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
7474
let call_mut = tcx
7575
.associated_items(fn_mut)
7676
.in_definition_order()
77-
.find(|it| it.kind == ty::AssocKind::Method)
77+
.find(|it| it.kind == ty::AssocKind::Fn)
7878
.unwrap()
7979
.def_id;
8080

src/librustc_mir_build/hair/cx/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> {
176176
.tcx
177177
.associated_items(trait_def_id)
178178
.filter_by_name_unhygienic(method_name)
179-
.find(|item| item.kind == ty::AssocKind::Method)
179+
.find(|item| item.kind == ty::AssocKind::Fn)
180180
.expect("trait method not found");
181181

182182
let method_ty = self.tcx.type_of(item.def_id);

src/librustc_privacy/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
16481648
found_pub_static = true;
16491649
intravisit::walk_impl_item(self, impl_item);
16501650
}
1651-
AssocItemKind::Method { has_self: false } => {
1651+
AssocItemKind::Fn { has_self: false } => {
16521652
found_pub_static = true;
16531653
intravisit::walk_impl_item(self, impl_item);
16541654
}
@@ -1927,7 +1927,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
19271927
let mut check = self.check(hir_id, vis);
19281928

19291929
let (check_ty, is_assoc_ty) = match assoc_item_kind {
1930-
AssocItemKind::Const | AssocItemKind::Method { .. } => (true, false),
1930+
AssocItemKind::Const | AssocItemKind::Fn { .. } => (true, false),
19311931
AssocItemKind::Type => (defaultness.has_value(), true),
19321932
// `ty()` for opaque types is the underlying type,
19331933
// it's not a part of interface, so we skip it.

src/librustc_resolve/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
921921
Res::Def(DefKind::AssocFn, def_id) => {
922922
if cstore
923923
.associated_item_cloned_untracked(def_id, self.r.session)
924-
.method_has_self_argument
924+
.fn_has_self_parameter
925925
{
926926
self.r.has_self.insert(def_id);
927927
}

src/librustc_resolve/late/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
21172117
};
21182118

21192119
let has_self = match assoc_item_kind {
2120-
Some(hir::AssocItemKind::Method { has_self }) => has_self,
2120+
Some(hir::AssocItemKind::Fn { has_self }) => has_self,
21212121
_ => false,
21222122
};
21232123

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
10291029
err.note(&format!(
10301030
"{}s cannot be accessed directly on a `trait`, they can only be \
10311031
accessed through a specific `impl`",
1032-
assoc_item.kind.suggestion_descr(),
1032+
assoc_item.kind.as_def_kind().descr(def_id)
10331033
));
10341034
err.span_suggestion(
10351035
span,

src/librustc_trait_selection/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ fn vtable_methods<'tcx>(
475475
let trait_methods = tcx
476476
.associated_items(trait_ref.def_id())
477477
.in_definition_order()
478-
.filter(|item| item.kind == ty::AssocKind::Method);
478+
.filter(|item| item.kind == ty::AssocKind::Fn);
479479

480480
// Now list each method's DefId and InternalSubsts (for within its trait).
481481
// If the method can never be called from this object, produce None.

src/librustc_trait_selection/traits/object_safety.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn object_safety_violations_for_trait(
8686
let mut violations: Vec<_> = tcx
8787
.associated_items(trait_def_id)
8888
.in_definition_order()
89-
.filter(|item| item.kind == ty::AssocKind::Method)
89+
.filter(|item| item.kind == ty::AssocKind::Fn)
9090
.filter_map(|item| {
9191
object_safety_violation_for_method(tcx, trait_def_id, &item)
9292
.map(|(code, span)| ObjectSafetyViolation::Method(item.ident.name, code, span))
@@ -362,7 +362,7 @@ fn virtual_call_violation_for_method<'tcx>(
362362
method: &ty::AssocItem,
363363
) -> Option<MethodViolationCode> {
364364
// The method's first parameter must be named `self`
365-
if !method.method_has_self_argument {
365+
if !method.fn_has_self_parameter {
366366
// We'll attempt to provide a structured suggestion for `Self: Sized`.
367367
let sugg =
368368
tcx.hir().get_if_local(method.def_id).as_ref().and_then(|node| node.generics()).map(

src/librustc_trait_selection/traits/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub fn count_own_vtable_entries(tcx: TyCtxt<'tcx>, trait_ref: ty::PolyTraitRef<'
293293
// Count number of methods and add them to the total offset.
294294
// Skip over associated types and constants.
295295
for trait_item in tcx.associated_items(trait_ref.def_id()).in_definition_order() {
296-
if trait_item.kind == ty::AssocKind::Method {
296+
if trait_item.kind == ty::AssocKind::Fn {
297297
entries += 1;
298298
}
299299
}
@@ -315,10 +315,10 @@ pub fn get_vtable_index_of_object_method<N>(
315315
for trait_item in tcx.associated_items(object.upcast_trait_ref.def_id()).in_definition_order() {
316316
if trait_item.def_id == method_def_id {
317317
// The item with the ID we were given really ought to be a method.
318-
assert_eq!(trait_item.kind, ty::AssocKind::Method);
318+
assert_eq!(trait_item.kind, ty::AssocKind::Fn);
319319
return entries;
320320
}
321-
if trait_item.kind == ty::AssocKind::Method {
321+
if trait_item.kind == ty::AssocKind::Fn {
322322
entries += 1;
323323
}
324324
}

src/librustc_ty/ty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn associated_item_from_trait_item_ref(
8585
let def_id = tcx.hir().local_def_id(trait_item_ref.id.hir_id);
8686
let (kind, has_self) = match trait_item_ref.kind {
8787
hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
88-
hir::AssocItemKind::Method { has_self } => (ty::AssocKind::Method, has_self),
88+
hir::AssocItemKind::Fn { has_self } => (ty::AssocKind::Fn, has_self),
8989
hir::AssocItemKind::Type => (ty::AssocKind::Type, false),
9090
hir::AssocItemKind::OpaqueTy => bug!("only impls can have opaque types"),
9191
};
@@ -98,7 +98,7 @@ fn associated_item_from_trait_item_ref(
9898
defaultness: trait_item_ref.defaultness,
9999
def_id,
100100
container: ty::TraitContainer(parent_def_id),
101-
method_has_self_argument: has_self,
101+
fn_has_self_parameter: has_self,
102102
}
103103
}
104104

@@ -110,7 +110,7 @@ fn associated_item_from_impl_item_ref(
110110
let def_id = tcx.hir().local_def_id(impl_item_ref.id.hir_id);
111111
let (kind, has_self) = match impl_item_ref.kind {
112112
hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
113-
hir::AssocItemKind::Method { has_self } => (ty::AssocKind::Method, has_self),
113+
hir::AssocItemKind::Fn { has_self } => (ty::AssocKind::Fn, has_self),
114114
hir::AssocItemKind::Type => (ty::AssocKind::Type, false),
115115
hir::AssocItemKind::OpaqueTy => (ty::AssocKind::OpaqueTy, false),
116116
};
@@ -123,7 +123,7 @@ fn associated_item_from_impl_item_ref(
123123
defaultness: impl_item_ref.defaultness,
124124
def_id,
125125
container: ty::ImplContainer(parent_def_id),
126-
method_has_self_argument: has_self,
126+
fn_has_self_parameter: has_self,
127127
}
128128
}
129129

0 commit comments

Comments
 (0)