Skip to content

Commit

Permalink
Auto merge of #70643 - Rustin-Liu:rustin-patch-rename, r=eddyb
Browse files Browse the repository at this point in the history
Rename AssocKind::Method to AssocKind::Fn

Part of #60163.

#60163 (comment)
  • Loading branch information
bors committed Apr 14, 2020
2 parents 47f4969 + b07e7fe commit 513a647
Show file tree
Hide file tree
Showing 44 changed files with 119 additions and 126 deletions.
4 changes: 2 additions & 2 deletions src/librustc_ast_lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
(hir::AssocItemKind::Type, default.is_some())
}
AssocItemKind::Fn(_, sig, _, default) => {
(hir::AssocItemKind::Method { has_self: sig.decl.has_self() }, default.is_some())
(hir::AssocItemKind::Fn { has_self: sig.decl.has_self() }, default.is_some())
}
AssocItemKind::MacCall(..) => unimplemented!(),
};
Expand Down Expand Up @@ -894,7 +894,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}
AssocItemKind::Fn(_, sig, ..) => {
hir::AssocItemKind::Method { has_self: sig.decl.has_self() }
hir::AssocItemKind::Fn { has_self: sig.decl.has_self() }
}
AssocItemKind::MacCall(..) => unimplemented!(),
},
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2515,7 +2515,7 @@ pub struct ImplItemRef<'hir> {
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub enum AssocItemKind {
Const,
Method { has_self: bool },
Fn { has_self: bool },
Type,
OpaqueTy,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
// enable E0621 for it.
pub(super) fn is_self_anon(&self, is_first: bool, scope_def_id: DefId) -> bool {
is_first
&& self.tcx().opt_associated_item(scope_def_id).map(|i| i.method_has_self_argument)
&& self.tcx().opt_associated_item(scope_def_id).map(|i| i.fn_has_self_parameter)
== Some(true)
}
}
4 changes: 2 additions & 2 deletions src/librustc_metadata/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
EntryKind::AssocConst(container, _, _) => (ty::AssocKind::Const, container, false),
EntryKind::AssocFn(data) => {
let data = data.decode(self);
(ty::AssocKind::Method, data.container, data.has_self)
(ty::AssocKind::Fn, data.container, data.has_self)
}
EntryKind::AssocType(container) => (ty::AssocKind::Type, container, false),
EntryKind::AssocOpaqueTy(container) => (ty::AssocKind::OpaqueTy, container, false),
Expand All @@ -1167,7 +1167,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
defaultness: container.defaultness(),
def_id: self.local_def_id(id),
container: container.with_def_id(parent),
method_has_self_argument: has_self,
fn_has_self_parameter: has_self,
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ impl EncodeContext<'tcx> {
rendered_const,
)
}
ty::AssocKind::Method => {
ty::AssocKind::Fn => {
let fn_data = if let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind {
let param_names = match *m {
hir::TraitFn::Required(ref names) => {
Expand All @@ -860,7 +860,7 @@ impl EncodeContext<'tcx> {
EntryKind::AssocFn(self.lazy(AssocFnData {
fn_data,
container,
has_self: trait_item.method_has_self_argument,
has_self: trait_item.fn_has_self_parameter,
}))
}
ty::AssocKind::Type => EntryKind::AssocType(container),
Expand All @@ -874,7 +874,7 @@ impl EncodeContext<'tcx> {
self.encode_const_stability(def_id);
self.encode_deprecation(def_id);
match trait_item.kind {
ty::AssocKind::Const | ty::AssocKind::Method => {
ty::AssocKind::Const | ty::AssocKind::Fn => {
self.encode_item_type(def_id);
}
ty::AssocKind::Type => {
Expand All @@ -884,7 +884,7 @@ impl EncodeContext<'tcx> {
}
ty::AssocKind::OpaqueTy => unreachable!(),
}
if trait_item.kind == ty::AssocKind::Method {
if trait_item.kind == ty::AssocKind::Fn {
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
self.encode_variances_of(def_id);
}
Expand Down Expand Up @@ -931,7 +931,7 @@ impl EncodeContext<'tcx> {
bug!()
}
}
ty::AssocKind::Method => {
ty::AssocKind::Fn => {
let fn_data = if let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind {
FnData {
asyncness: sig.header.asyncness,
Expand All @@ -944,7 +944,7 @@ impl EncodeContext<'tcx> {
EntryKind::AssocFn(self.lazy(AssocFnData {
fn_data,
container,
has_self: impl_item.method_has_self_argument,
has_self: impl_item.fn_has_self_parameter,
}))
}
ty::AssocKind::OpaqueTy => EntryKind::AssocOpaqueTy(container),
Expand All @@ -958,7 +958,7 @@ impl EncodeContext<'tcx> {
self.encode_const_stability(def_id);
self.encode_deprecation(def_id);
self.encode_item_type(def_id);
if impl_item.kind == ty::AssocKind::Method {
if impl_item.kind == ty::AssocKind::Fn {
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
self.encode_variances_of(def_id);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/traits/specialization_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ impl<'tcx> Node {
.find(move |impl_item| {
match (trait_item_kind, impl_item.kind) {
| (Const, Const)
| (Method, Method)
| (Fn, Fn)
| (Type, Type)
| (Type, OpaqueTy) // assoc. types can be made opaque in impls
=> tcx.hygienic_eq(impl_item.ident, trait_item_name, trait_def_id),

| (Const, _)
| (Method, _)
| (Fn, _)
| (Type, _)
| (OpaqueTy, _)
=> false,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'tcx> OverloadedDeref<'tcx> {
let method_def_id = tcx
.associated_items(trait_def_id.unwrap())
.in_definition_order()
.find(|m| m.kind == ty::AssocKind::Method)
.find(|m| m.kind == ty::AssocKind::Fn)
.unwrap()
.def_id;
(method_def_id, tcx.mk_substs_trait(source, &[]))
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl<'tcx> Instance<'tcx> {
let call_once = tcx
.associated_items(fn_once)
.in_definition_order()
.find(|it| it.kind == ty::AssocKind::Method)
.find(|it| it.kind == ty::AssocKind::Fn)
.unwrap()
.def_id;
let def = ty::InstanceDef::ClosureOnceShim { call_once };
Expand Down
34 changes: 12 additions & 22 deletions src/librustc_middle/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-tidy-filelength

pub use self::fold::{TypeFoldable, TypeVisitor};
pub use self::AssocItemContainer::*;
pub use self::BorrowKind::*;
Expand Down Expand Up @@ -192,58 +190,50 @@ pub struct AssocItem {
pub container: AssocItemContainer,

/// Whether this is a method with an explicit self
/// as its first argument, allowing method calls.
pub method_has_self_argument: bool,
/// as its first parameter, allowing method calls.
pub fn_has_self_parameter: bool,
}

#[derive(Copy, Clone, PartialEq, Debug, HashStable)]
pub enum AssocKind {
Const,
Method,
Fn,
OpaqueTy,
Type,
}

impl AssocKind {
pub fn suggestion_descr(&self) -> &'static str {
match self {
ty::AssocKind::Method => "method call",
ty::AssocKind::Type | ty::AssocKind::OpaqueTy => "associated type",
ty::AssocKind::Const => "associated constant",
}
}

pub fn namespace(&self) -> Namespace {
match *self {
ty::AssocKind::OpaqueTy | ty::AssocKind::Type => Namespace::TypeNS,
ty::AssocKind::Const | ty::AssocKind::Method => Namespace::ValueNS,
ty::AssocKind::Const | ty::AssocKind::Fn => Namespace::ValueNS,
}
}
}

impl AssocItem {
pub fn def_kind(&self) -> DefKind {
match self.kind {
pub fn as_def_kind(&self) -> DefKind {
match self {
AssocKind::Const => DefKind::AssocConst,
AssocKind::Method => DefKind::AssocFn,
AssocKind::Fn => DefKind::AssocFn,
AssocKind::Type => DefKind::AssocTy,
AssocKind::OpaqueTy => DefKind::AssocOpaqueTy,
}
}
}

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

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

pub fn trait_relevant_for_never(self, did: DefId) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
let call_mut = tcx
.associated_items(fn_mut)
.in_definition_order()
.find(|it| it.kind == ty::AssocKind::Method)
.find(|it| it.kind == ty::AssocKind::Fn)
.unwrap()
.def_id;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/hair/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> {
.tcx
.associated_items(trait_def_id)
.filter_by_name_unhygienic(method_name)
.find(|item| item.kind == ty::AssocKind::Method)
.find(|item| item.kind == ty::AssocKind::Fn)
.expect("trait method not found");

let method_ty = self.tcx.type_of(item.def_id);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
found_pub_static = true;
intravisit::walk_impl_item(self, impl_item);
}
AssocItemKind::Method { has_self: false } => {
AssocItemKind::Fn { has_self: false } => {
found_pub_static = true;
intravisit::walk_impl_item(self, impl_item);
}
Expand Down Expand Up @@ -1927,7 +1927,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
let mut check = self.check(hir_id, vis);

let (check_ty, is_assoc_ty) = match assoc_item_kind {
AssocItemKind::Const | AssocItemKind::Method { .. } => (true, false),
AssocItemKind::Const | AssocItemKind::Fn { .. } => (true, false),
AssocItemKind::Type => (defaultness.has_value(), true),
// `ty()` for opaque types is the underlying type,
// it's not a part of interface, so we skip it.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
Res::Def(DefKind::AssocFn, def_id) => {
if cstore
.associated_item_cloned_untracked(def_id, self.r.session)
.method_has_self_argument
.fn_has_self_parameter
{
self.r.has_self.insert(def_id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
};

let has_self = match assoc_item_kind {
Some(hir::AssocItemKind::Method { has_self }) => has_self,
Some(hir::AssocItemKind::Fn { has_self }) => has_self,
_ => false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
err.note(&format!(
"{}s cannot be accessed directly on a `trait`, they can only be \
accessed through a specific `impl`",
assoc_item.kind.suggestion_descr(),
assoc_item.kind.as_def_kind().descr(def_id)
));
err.span_suggestion(
span,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trait_selection/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ fn vtable_methods<'tcx>(
let trait_methods = tcx
.associated_items(trait_ref.def_id())
.in_definition_order()
.filter(|item| item.kind == ty::AssocKind::Method);
.filter(|item| item.kind == ty::AssocKind::Fn);

// Now list each method's DefId and InternalSubsts (for within its trait).
// If the method can never be called from this object, produce None.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trait_selection/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn object_safety_violations_for_trait(
let mut violations: Vec<_> = tcx
.associated_items(trait_def_id)
.in_definition_order()
.filter(|item| item.kind == ty::AssocKind::Method)
.filter(|item| item.kind == ty::AssocKind::Fn)
.filter_map(|item| {
object_safety_violation_for_method(tcx, trait_def_id, &item)
.map(|(code, span)| ObjectSafetyViolation::Method(item.ident.name, code, span))
Expand Down Expand Up @@ -362,7 +362,7 @@ fn virtual_call_violation_for_method<'tcx>(
method: &ty::AssocItem,
) -> Option<MethodViolationCode> {
// The method's first parameter must be named `self`
if !method.method_has_self_argument {
if !method.fn_has_self_parameter {
// We'll attempt to provide a structured suggestion for `Self: Sized`.
let sugg =
tcx.hir().get_if_local(method.def_id).as_ref().and_then(|node| node.generics()).map(
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trait_selection/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ pub fn count_own_vtable_entries(tcx: TyCtxt<'tcx>, trait_ref: ty::PolyTraitRef<'
// Count number of methods and add them to the total offset.
// Skip over associated types and constants.
for trait_item in tcx.associated_items(trait_ref.def_id()).in_definition_order() {
if trait_item.kind == ty::AssocKind::Method {
if trait_item.kind == ty::AssocKind::Fn {
entries += 1;
}
}
Expand All @@ -315,10 +315,10 @@ pub fn get_vtable_index_of_object_method<N>(
for trait_item in tcx.associated_items(object.upcast_trait_ref.def_id()).in_definition_order() {
if trait_item.def_id == method_def_id {
// The item with the ID we were given really ought to be a method.
assert_eq!(trait_item.kind, ty::AssocKind::Method);
assert_eq!(trait_item.kind, ty::AssocKind::Fn);
return entries;
}
if trait_item.kind == ty::AssocKind::Method {
if trait_item.kind == ty::AssocKind::Fn {
entries += 1;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_ty/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn associated_item_from_trait_item_ref(
let def_id = tcx.hir().local_def_id(trait_item_ref.id.hir_id);
let (kind, has_self) = match trait_item_ref.kind {
hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
hir::AssocItemKind::Method { has_self } => (ty::AssocKind::Method, has_self),
hir::AssocItemKind::Fn { has_self } => (ty::AssocKind::Fn, has_self),
hir::AssocItemKind::Type => (ty::AssocKind::Type, false),
hir::AssocItemKind::OpaqueTy => bug!("only impls can have opaque types"),
};
Expand All @@ -98,7 +98,7 @@ fn associated_item_from_trait_item_ref(
defaultness: trait_item_ref.defaultness,
def_id,
container: ty::TraitContainer(parent_def_id),
method_has_self_argument: has_self,
fn_has_self_parameter: has_self,
}
}

Expand All @@ -110,7 +110,7 @@ fn associated_item_from_impl_item_ref(
let def_id = tcx.hir().local_def_id(impl_item_ref.id.hir_id);
let (kind, has_self) = match impl_item_ref.kind {
hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
hir::AssocItemKind::Method { has_self } => (ty::AssocKind::Method, has_self),
hir::AssocItemKind::Fn { has_self } => (ty::AssocKind::Fn, has_self),
hir::AssocItemKind::Type => (ty::AssocKind::Type, false),
hir::AssocItemKind::OpaqueTy => (ty::AssocKind::OpaqueTy, false),
};
Expand All @@ -123,7 +123,7 @@ fn associated_item_from_impl_item_ref(
defaultness: impl_item_ref.defaultness,
def_id,
container: ty::ImplContainer(parent_def_id),
method_has_self_argument: has_self,
fn_has_self_parameter: has_self,
}
}

Expand Down
Loading

0 comments on commit 513a647

Please sign in to comment.