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>
This commit is contained in:
Rustin-Liu 2020-04-01 10:09:50 +08:00
parent 8e18e26f12
commit b07e7fe047
44 changed files with 123 additions and 130 deletions

View file

@ -796,7 +796,7 @@ fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemRef {
(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!(),
};
@ -894,7 +894,7 @@ fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef<'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!(),
},

View file

@ -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,
}

View file

@ -118,7 +118,7 @@ pub(super) fn is_return_type_anon(
// 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)
}
}

View file

@ -1153,7 +1153,7 @@ fn get_associated_item(&self, id: DefIndex, sess: &Session) -> ty::AssocItem {
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),
@ -1167,7 +1167,7 @@ fn get_associated_item(&self, id: DefIndex, sess: &Session) -> ty::AssocItem {
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,
}
}

View file

@ -839,7 +839,7 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) {
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) => {
@ -860,7 +860,7 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) {
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),
@ -874,7 +874,7 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) {
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 => {
@ -884,7 +884,7 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) {
}
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);
}
@ -931,7 +931,7 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) {
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,
@ -944,7 +944,7 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) {
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),
@ -958,7 +958,7 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) {
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);
}

View file

@ -107,13 +107,13 @@ pub fn item(
.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,

View file

@ -123,7 +123,7 @@ pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> (DefId, Substs
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, &[]))

View file

@ -366,7 +366,7 @@ pub fn fn_once_adapter_instance(
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 };

View file

@ -1,5 +1,3 @@
// ignore-tidy-filelength
pub use self::fold::{TypeFoldable, TypeVisitor};
pub use self::AssocItemContainer::*;
pub use self::BorrowKind::*;
@ -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,
}
}
pub fn as_def_kind(&self) -> DefKind {
match self {
AssocKind::Const => DefKind::AssocConst,
AssocKind::Fn => DefKind::AssocFn,
AssocKind::Type => DefKind::AssocTy,
AssocKind::OpaqueTy => DefKind::AssocOpaqueTy,
}
}
}
impl AssocItem {
pub fn def_kind(&self) -> DefKind {
match self.kind {
AssocKind::Const => DefKind::AssocConst,
AssocKind::Method => DefKind::AssocFn,
AssocKind::Type => DefKind::AssocTy,
AssocKind::OpaqueTy => DefKind::AssocOpaqueTy,
}
}
/// 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
@ -2664,7 +2654,7 @@ pub fn par_body_owners<F: Fn(LocalDefId) + sync::Sync + sync::Send>(self, f: F)
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 {

View file

@ -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;

View file

@ -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);

View file

@ -1648,7 +1648,7 @@ fn visit_item(&mut self, item: &'tcx hir::Item<'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);
}
@ -1927,7 +1927,7 @@ fn check_assoc_item(
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.

View file

@ -921,7 +921,7 @@ fn build_reduced_graph_for_external_crate_res(&mut self, child: Export<NodeId>)
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);
}

View file

@ -2117,7 +2117,7 @@ fn visit_fn_like_elision(
};
let has_self = match assoc_item_kind {
Some(hir::AssocItemKind::Method { has_self }) => has_self,
Some(hir::AssocItemKind::Fn { has_self }) => has_self,
_ => false,
};

View file

@ -1029,7 +1029,7 @@ fn suggest_fully_qualified_path(
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,

View file

@ -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.

View file

@ -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))
@ -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(

View file

@ -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;
}
}
@ -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;
}
}

View file

@ -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"),
};
@ -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,
}
}
@ -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),
};
@ -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,
}
}

View file

@ -516,7 +516,7 @@ fn compare_self_type<'tcx>(
})
};
match (trait_m.method_has_self_argument, impl_m.method_has_self_argument) {
match (trait_m.fn_has_self_parameter, impl_m.fn_has_self_parameter) {
(false, false) | (true, true) => {}
(false, true) => {
@ -1163,7 +1163,7 @@ fn compare_type_predicate_entailment(
fn assoc_item_kind_str(impl_item: &ty::AssocItem) -> &'static str {
match impl_item.kind {
ty::AssocKind::Const => "const",
ty::AssocKind::Method => "method",
ty::AssocKind::Fn => "method",
ty::AssocKind::Type | ty::AssocKind::OpaqueTy => "type",
}
}

View file

@ -250,9 +250,7 @@ pub fn get_conversion_methods(
// This function checks if the method isn't static and takes other arguments than `self`.
fn has_no_input_arg(&self, method: &AssocItem) -> bool {
match method.kind {
ty::AssocKind::Method => {
self.tcx.fn_sig(method.def_id).inputs().skip_binder().len() == 1
}
ty::AssocKind::Fn => self.tcx.fn_sig(method.def_id).inputs().skip_binder().len() == 1,
_ => false,
}
}

View file

@ -467,7 +467,7 @@ pub fn resolve_ufcs(
}
}
let def_kind = pick.item.def_kind();
let def_kind = pick.item.kind.as_def_kind();
debug!("resolve_ufcs: def_kind={:?}, def_id={:?}", def_kind, pick.item.def_id);
tcx.check_stability(pick.item.def_id, Some(expr_id), span);
Ok((def_kind, pick.item.def_id))

View file

@ -570,7 +570,8 @@ fn push_candidate(&mut self, candidate: Candidate<'tcx>, is_inherent: bool) {
self.extension_candidates.push(candidate);
}
} else if self.private_candidate.is_none() {
self.private_candidate = Some((candidate.item.def_kind(), candidate.item.def_id));
self.private_candidate =
Some((candidate.item.kind.as_def_kind(), candidate.item.def_id));
}
}
@ -896,7 +897,7 @@ pub fn matches_return_type(
expected: Ty<'tcx>,
) -> bool {
match method.kind {
ty::AssocKind::Method => {
ty::AssocKind::Fn => {
let fty = self.tcx.fn_sig(method.def_id);
self.probe(|_| {
let substs = self.fresh_substs_for_item(self.span, method.def_id);
@ -1553,10 +1554,10 @@ fn has_applicable_self(&self, item: &ty::AssocItem) -> bool {
// In Path mode (i.e., resolving a value like `T::next`), consider any
// associated value (i.e., methods, constants) but not types.
match self.mode {
Mode::MethodCall => item.method_has_self_argument,
Mode::MethodCall => item.fn_has_self_parameter,
Mode::Path => match item.kind {
ty::AssocKind::OpaqueTy | ty::AssocKind::Type => false,
ty::AssocKind::Method | ty::AssocKind::Const => true,
ty::AssocKind::Fn | ty::AssocKind::Const => true,
},
}
// FIXME -- check for types that deref to `Self`,
@ -1577,7 +1578,7 @@ fn xform_self_ty(
impl_ty: Ty<'tcx>,
substs: SubstsRef<'tcx>,
) -> (Ty<'tcx>, Option<Ty<'tcx>>) {
if item.kind == ty::AssocKind::Method && self.mode == Mode::MethodCall {
if item.kind == ty::AssocKind::Fn && self.mode == Mode::MethodCall {
let sig = self.xform_method_sig(item.def_id, substs);
(sig.inputs()[0], Some(sig.output()))
} else {

View file

@ -162,7 +162,7 @@ pub fn report_method_error<'b>(
ty::AssocKind::Const
| ty::AssocKind::Type
| ty::AssocKind::OpaqueTy => rcvr_ty,
ty::AssocKind::Method => self
ty::AssocKind::Fn => self
.tcx
.fn_sig(item.def_id)
.inputs()
@ -179,6 +179,7 @@ pub fn report_method_error<'b>(
path,
ty,
item.kind,
item.def_id,
sugg_span,
idx,
self.tcx.sess.source_map(),
@ -220,6 +221,7 @@ pub fn report_method_error<'b>(
path,
rcvr_ty,
item.kind,
item.def_id,
sugg_span,
idx,
self.tcx.sess.source_map(),
@ -764,7 +766,7 @@ trait bound{s}",
err.span_label(span, msg);
}
} else if let Some(lev_candidate) = lev_candidate {
let def_kind = lev_candidate.def_kind();
let def_kind = lev_candidate.kind.as_def_kind();
err.span_suggestion(
span,
&format!(
@ -957,7 +959,7 @@ fn suggest_traits_to_import<'b>(
&& self
.associated_item(info.def_id, item_name, Namespace::ValueNS)
.filter(|item| {
if let ty::AssocKind::Method = item.kind {
if let ty::AssocKind::Fn = item.kind {
let id = self.tcx.hir().as_local_hir_id(item.def_id);
if let Some(hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Fn(fn_sig, method),
@ -1387,12 +1389,13 @@ fn print_disambiguation_help(
trait_name: String,
rcvr_ty: Ty<'_>,
kind: ty::AssocKind,
def_id: DefId,
span: Span,
candidate: Option<usize>,
source_map: &source_map::SourceMap,
) {
let mut applicability = Applicability::MachineApplicable;
let sugg_args = if let (ty::AssocKind::Method, Some(args)) = (kind, args) {
let sugg_args = if let (ty::AssocKind::Fn, Some(args)) = (kind, args) {
format!(
"({}{})",
if rcvr_ty.is_region_ptr() {
@ -1416,7 +1419,7 @@ fn print_disambiguation_help(
span,
&format!(
"disambiguate the {} for {}",
kind.suggestion_descr(),
kind.as_def_kind().descr(def_id),
if let Some(candidate) = candidate {
format!("candidate #{}", candidate)
} else {

View file

@ -1903,7 +1903,7 @@ fn check_specialization_validity<'tcx>(
) {
let kind = match impl_item.kind {
hir::ImplItemKind::Const(..) => ty::AssocKind::Const,
hir::ImplItemKind::Fn(..) => ty::AssocKind::Method,
hir::ImplItemKind::Fn(..) => ty::AssocKind::Fn,
hir::ImplItemKind::OpaqueTy(..) => ty::AssocKind::OpaqueTy,
hir::ImplItemKind::TyAlias(_) => ty::AssocKind::Type,
};
@ -2049,7 +2049,7 @@ fn check_impl_items_against_trait<'tcx>(
}
hir::ImplItemKind::Fn(..) => {
let opt_trait_span = tcx.hir().span_if_local(ty_trait_item.def_id);
if ty_trait_item.kind == ty::AssocKind::Method {
if ty_trait_item.kind == ty::AssocKind::Fn {
compare_impl_method(
tcx,
&ty_impl_item,
@ -2295,7 +2295,7 @@ fn fn_sig_suggestion(
/// structured suggestion.
fn suggestion_signature(assoc: &ty::AssocItem, tcx: TyCtxt<'_>) -> String {
match assoc.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

View file

@ -294,7 +294,7 @@ fn check_associated_item(
let ty = fcx.normalize_associated_types_in(span, &ty);
fcx.register_wf_obligation(ty, span, code.clone());
}
ty::AssocKind::Method => {
ty::AssocKind::Fn => {
let sig = fcx.tcx.fn_sig(item.def_id);
let sig = fcx.normalize_associated_types_in(span, &sig);
let hir_sig = sig_if_method.expect("bad signature for method");
@ -985,7 +985,7 @@ fn check_method_receiver<'fcx, 'tcx>(
// Check that the method has a valid receiver type, given the type `Self`.
debug!("check_method_receiver({:?}, self_ty={:?})", method, self_ty);
if !method.method_has_self_argument {
if !method.fn_has_self_parameter {
return;
}

View file

@ -2583,7 +2583,7 @@ fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
.associated_items(trait_def_id)
.filter_by_name_unhygienic(impl_item.ident.name)
.find(move |trait_item| {
trait_item.kind == ty::AssocKind::Method
trait_item.kind == ty::AssocKind::Fn
&& tcx.hygienic_eq(impl_item.ident, trait_item.ident, trait_def_id)
})
{

View file

@ -147,7 +147,7 @@ fn enforce_impl_params_are_constrained(
let predicates = tcx.predicates_of(def_id).instantiate_identity(tcx);
cgp::parameters_for(&predicates, true)
}
ty::AssocKind::Method | ty::AssocKind::Const => Vec::new(),
ty::AssocKind::Fn | ty::AssocKind::Const => Vec::new(),
}
})
.collect();

View file

@ -1174,14 +1174,14 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
};
AssocConstItem(ty.clean(cx), default)
}
ty::AssocKind::Method => {
ty::AssocKind::Fn => {
let generics =
(cx.tcx.generics_of(self.def_id), cx.tcx.explicit_predicates_of(self.def_id))
.clean(cx);
let sig = cx.tcx.fn_sig(self.def_id);
let mut decl = (self.def_id, sig).clean(cx);
if self.method_has_self_argument {
if self.fn_has_self_parameter {
let self_ty = match self.container {
ty::ImplContainer(def_id) => cx.tcx.type_of(def_id),
ty::TraitContainer(_) => cx.tcx.types.self_param,

View file

@ -209,7 +209,7 @@ fn resolve(
.filter_by_name_unhygienic(item_name)
.next()
.and_then(|item| match item.kind {
ty::AssocKind::Method => Some("method"),
ty::AssocKind::Fn => Some("method"),
_ => None,
})
.map(|out| (prim, Some(format!("{}#{}.{}", path, out, item_name))))
@ -238,12 +238,12 @@ fn resolve(
.find(|item| item.ident.name == item_name);
if let Some(item) = item {
let out = match item.kind {
ty::AssocKind::Method if ns == ValueNS => "method",
ty::AssocKind::Fn if ns == ValueNS => "method",
ty::AssocKind::Const if ns == ValueNS => "associatedconstant",
_ => return self.variant_field(path_str, current_item, module_id),
};
if extra_fragment.is_some() {
Err(ErrorKind::AnchorFailure(if item.kind == ty::AssocKind::Method {
Err(ErrorKind::AnchorFailure(if item.kind == ty::AssocKind::Fn {
"methods cannot be followed by anchors"
} else {
"associated constants cannot be followed by anchors"
@ -298,14 +298,15 @@ fn resolve(
.map(|item| cx.tcx.associated_item(*item))
.find(|item| item.ident.name == item_name);
if let Some(item) = item {
let kind = match item.kind {
ty::AssocKind::Const if ns == ValueNS => "associatedconstant",
ty::AssocKind::Type if ns == TypeNS => "associatedtype",
ty::AssocKind::Method if ns == ValueNS => {
if item.defaultness.has_value() { "method" } else { "tymethod" }
}
_ => return self.variant_field(path_str, current_item, module_id),
};
let kind =
match item.kind {
ty::AssocKind::Const if ns == ValueNS => "associatedconstant",
ty::AssocKind::Type if ns == TypeNS => "associatedtype",
ty::AssocKind::Fn if ns == ValueNS => {
if item.defaultness.has_value() { "method" } else { "tymethod" }
}
_ => return self.variant_field(path_str, current_item, module_id),
};
if extra_fragment.is_some() {
Err(ErrorKind::AnchorFailure(if item.kind == ty::AssocKind::Const {

View file

@ -14,11 +14,11 @@ note: candidate #2 is defined in an impl of the trait `Trait2` for the type `Tes
|
LL | fn foo() {}
| ^^^^^^^^
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | Trait1::foo()
| ^^^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | Trait2::foo()
| ^^^^^^^^^^^

View file

@ -6,11 +6,11 @@ LL | assert_eq!('x'.ipu_flatten(), 0);
|
= note: candidate #1 is defined in an impl of the trait `inference_unstable_iterator::IpuIterator` for the type `char`
= note: candidate #2 is defined in an impl of the trait `inference_unstable_itertools::IpuItertools` for the type `char`
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | assert_eq!(inference_unstable_iterator::IpuIterator::ipu_flatten(&'x'), 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | assert_eq!(inference_unstable_itertools::IpuItertools::ipu_flatten(&'x'), 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -5,7 +5,7 @@ LL | x.foo();
| --^^^--
| | |
| | multiple `foo` found
| help: disambiguate the method call for candidate #2: `T::foo(&x)`
| help: disambiguate the associated function for candidate #2: `T::foo(&x)`
|
note: candidate #1 is defined in an impl for the type `(dyn T + 'a)`
--> $DIR/issue-18446.rs:9:5

View file

@ -14,11 +14,11 @@ note: candidate #2 is defined in an impl of the trait `Add` for the type `isize`
|
LL | fn to_int(&self) -> isize { *self }
| ^^^^^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | ToPrimitive::to_int(&self) + other.to_int()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | Add::to_int(&self) + other.to_int()
| ^^^^^^^^^^^^^^^^^^

View file

@ -14,11 +14,11 @@ note: candidate #2 is defined in an impl of the trait `await` for the type `r#fn
|
LL | fn r#struct(&self) {
| ^^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | async::r#struct(&r#fn {});
| ^^^^^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | await::r#struct(&r#fn {});
| ^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -10,11 +10,11 @@ note: candidate #1 is defined in an impl of the trait `Me2` for the type `usize`
LL | impl Me2 for usize { fn me(&self) -> usize { *self } }
| ^^^^^^^^^^^^^^^^^^^^^
= note: candidate #2 is defined in an impl of the trait `ambig_impl_2_lib::Me` for the type `usize`
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | fn main() { Me2::me(&1_usize); }
| ^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | fn main() { ambig_impl_2_lib::Me::me(&1_usize); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -14,11 +14,11 @@ note: candidate #2 is defined in the trait `B`
|
LL | trait B { fn foo(&self); }
| ^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | A::foo(t);
| ^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | B::foo(t);
| ^^^^^^^^^

View file

@ -14,11 +14,11 @@ note: candidate #2 is defined in an impl of the trait `B` for the type `AB`
|
LL | fn foo(self) {}
| ^^^^^^^^^^^^
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | A::foo(AB {});
| ^^^^^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | B::foo(AB {});
| ^^^^^^^^^^^^^

View file

@ -14,11 +14,11 @@ note: candidate #2 is defined in an impl of the trait `B` for the type `AB`
|
LL | fn foo() {}
| ^^^^^^^^
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | A::foo();
| ^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | B::foo();
| ^^^^^^

View file

@ -14,11 +14,11 @@ note: candidate #2 is defined in an impl of the trait `Bar` for the type `usize`
|
LL | trait Bar { fn method(&self) {} }
| ^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | Foo::method(&1_usize);
| ^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | Bar::method(&1_usize);
| ^^^^^^^^^^^^^^^^^^^^^

View file

@ -35,15 +35,15 @@ note: candidate #3 is defined in the trait `FinalFoo`
|
LL | fn foo(&self) -> u8;
| ^^^^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | let z = internal::X::foo(x);
| ^^^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | let z = nuisance_foo::NuisanceFoo::foo(x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #3
help: disambiguate the associated function for candidate #3
|
LL | let z = FinalFoo::foo(x);
| ^^^^^^^^^^^^^^^^

View file

@ -14,11 +14,11 @@ note: candidate #2 is defined in the trait `B`
|
LL | fn foo(&mut self) {}
| ^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | A::foo(&a)
| ^^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | B::foo(&a)
| ^^^^^^^^^^
@ -39,11 +39,11 @@ note: candidate #2 is defined in the trait `D`
|
LL | fn foo(&self) {}
| ^^^^^^^^^^^^^
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | C::foo(&a)
| ^^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | D::foo(&a)
| ^^^^^^^^^^
@ -64,11 +64,11 @@ note: candidate #2 is defined in the trait `F`
|
LL | fn foo(self) {}
| ^^^^^^^^^^^^
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | E::foo(a)
| ^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | F::foo(a)
| ^^^^^^^^^

View file

@ -25,15 +25,15 @@ LL | fn f9(_: usize) -> usize;
candidate #1: `CtxtFn`
candidate #2: `OtherTrait`
candidate #3: `UnusedTrait`
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | u.f8(42) + CtxtFn::f9(u, 342) + m.fff(42)
| ^^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | u.f8(42) + OtherTrait::f9(u, 342) + m.fff(42)
| ^^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #3
help: disambiguate the associated function for candidate #3
|
LL | u.f8(42) + UnusedTrait::f9(u, 342) + m.fff(42)
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -64,7 +64,7 @@ LL | t.is_str()
| --^^^^^^--
| | |
| | this is an associated function, not a method
| help: disambiguate the method call for the candidate: `ManyImplTrait::is_str(t)`
| help: disambiguate the associated function for the candidate: `ManyImplTrait::is_str(t)`
|
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in the trait `ManyImplTrait`

View file

@ -14,11 +14,11 @@ note: candidate #2 is defined in an impl of the trait `inner::B` for the type `u
|
LL | fn foo(&self) {}
| ^^^^^^^^^^^^^
help: disambiguate the method call for candidate #1
help: disambiguate the associated function for candidate #1
|
LL | inner::A::foo(&t);
| ^^^^^^^^^^^^^^^^^
help: disambiguate the method call for candidate #2
help: disambiguate the associated function for candidate #2
|
LL | inner::B::foo(&t);
| ^^^^^^^^^^^^^^^^^