Skip to content

Commit

Permalink
DefKind::Method -> DefKind::AssocFn
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-i-m committed Mar 3, 2020
1 parent b135c73 commit 98c7ed6
Show file tree
Hide file tree
Showing 23 changed files with 38 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -326,12 +326,12 @@ impl<'hir> Map<'hir> {
},
Node::TraitItem(item) => match item.kind {
TraitItemKind::Const(..) => DefKind::AssocConst,
TraitItemKind::Method(..) => DefKind::Method,
TraitItemKind::Method(..) => DefKind::AssocFn,
TraitItemKind::Type(..) => DefKind::AssocTy,
},
Node::ImplItem(item) => match item.kind {
ImplItemKind::Const(..) => DefKind::AssocConst,
ImplItemKind::Method(..) => DefKind::Method,
ImplItemKind::Method(..) => DefKind::AssocFn,
ImplItemKind::TyAlias(..) => DefKind::AssocTy,
ImplItemKind::OpaqueTy(..) => DefKind::AssocOpaqueTy,
},
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/stability.rs
Expand Up @@ -250,7 +250,7 @@ pub enum EvalResult {
fn skip_stability_check_due_to_privacy(tcx: TyCtxt<'_>, mut def_id: DefId) -> bool {
// Check if `def_id` is a trait method.
match tcx.def_kind(def_id) {
Some(DefKind::Method) | Some(DefKind::AssocTy) | Some(DefKind::AssocConst) => {
Some(DefKind::AssocFn) | Some(DefKind::AssocTy) | Some(DefKind::AssocConst) => {
if let ty::TraitContainer(trait_def_id) = tcx.associated_item(def_id).container {
// Trait methods do not declare visibility (even
// for visibility info in cstore). Use containing
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/context.rs
Expand Up @@ -611,7 +611,7 @@ impl<'tcx> TypeckTables<'tcx> {
}

match self.type_dependent_defs().get(expr.hir_id) {
Some(Ok((DefKind::Method, _))) => true,
Some(Ok((DefKind::AssocFn, _))) => true,
_ => false,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/mod.rs
Expand Up @@ -230,7 +230,7 @@ impl AssocItem {
pub fn def_kind(&self) -> DefKind {
match self.kind {
AssocKind::Const => DefKind::AssocConst,
AssocKind::Method => DefKind::Method,
AssocKind::Method => DefKind::AssocFn,
AssocKind::Type => DefKind::AssocTy,
AssocKind::OpaqueTy => DefKind::AssocOpaqueTy,
}
Expand Down Expand Up @@ -2872,7 +2872,7 @@ impl<'tcx> TyCtxt<'tcx> {
}
} else {
match self.def_kind(def_id).expect("no def for `DefId`") {
DefKind::AssocConst | DefKind::Method | DefKind::AssocTy => true,
DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => true,
_ => false,
}
};
Expand Down Expand Up @@ -3051,7 +3051,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// `DefId` of the impl that the method belongs to; otherwise, returns `None`.
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
let item = if def_id.krate != LOCAL_CRATE {
if let Some(DefKind::Method) = self.def_kind(def_id) {
if let Some(DefKind::AssocFn) = self.def_kind(def_id) {
Some(self.associated_item(def_id))
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_lowering/path.rs
Expand Up @@ -75,7 +75,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ParenthesizedGenericArgs::Ok
}
// `a::b::Trait(Args)::TraitItem`
Res::Def(DefKind::Method, _)
Res::Def(DefKind::AssocFn, _)
| Res::Def(DefKind::AssocConst, _)
| Res::Def(DefKind::AssocTy, _)
if i + 2 == proj_start =>
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_hir/def.rs
Expand Up @@ -72,7 +72,7 @@ pub enum DefKind {
Static,
/// Refers to the struct or enum variant's constructor.
Ctor(CtorOf, CtorKind),
Method,
AssocFn,
AssocConst,

// Macro namespace
Expand Down Expand Up @@ -107,7 +107,8 @@ impl DefKind {
DefKind::Union => "union",
DefKind::Trait => "trait",
DefKind::ForeignTy => "foreign type",
DefKind::Method => "method",
// FIXME: Update the description to "assoc fn"
DefKind::AssocFn => "method",
DefKind::Const => "constant",
DefKind::AssocConst => "associated constant",
DefKind::TyParam => "type parameter",
Expand Down Expand Up @@ -150,7 +151,7 @@ impl DefKind {
| DefKind::ConstParam
| DefKind::Static
| DefKind::Ctor(..)
| DefKind::Method
| DefKind::AssocFn
| DefKind::AssocConst => ns == Namespace::ValueNS,

DefKind::Macro(..) => ns == Namespace::MacroNS,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/error_reporting/need_type_info.rs
Expand Up @@ -468,7 +468,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
&segment.args,
) {
let borrow = tables.borrow();
if let Some((DefKind::Method, did)) = borrow.type_dependent_def(e.hir_id) {
if let Some((DefKind::AssocFn, did)) = borrow.type_dependent_def(e.hir_id) {
let generics = self.tcx.generics_of(did);
if !generics.params.is_empty() {
err.span_suggestion(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/unused.rs
Expand Up @@ -54,7 +54,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
match callee.kind {
hir::ExprKind::Path(ref qpath) => {
match cx.tables.qpath_res(qpath, callee.hir_id) {
Res::Def(DefKind::Fn, def_id) | Res::Def(DefKind::Method, def_id) => {
Res::Def(DefKind::Fn, def_id) | Res::Def(DefKind::AssocFn, def_id) => {
Some(def_id)
}
// `Res::Local` if it was a closure, for which we
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/rmeta/decoder.rs
Expand Up @@ -504,7 +504,7 @@ impl EntryKind {
EntryKind::Struct(_, _) => DefKind::Struct,
EntryKind::Union(_, _) => DefKind::Union,
EntryKind::Fn(_) | EntryKind::ForeignFn(_) => DefKind::Fn,
EntryKind::Method(_) => DefKind::Method,
EntryKind::Method(_) => DefKind::AssocFn,
EntryKind::Type => DefKind::TyAlias,
EntryKind::TypeParam => DefKind::TyParam,
EntryKind::ConstParam => DefKind::ConstParam,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/util/pretty.rs
Expand Up @@ -545,7 +545,7 @@ fn write_mir_sig(
trace!("write_mir_sig: {:?}", src.instance);
let kind = tcx.def_kind(src.def_id());
let is_function = match kind {
Some(DefKind::Fn) | Some(DefKind::Method) | Some(DefKind::Ctor(..)) => true,
Some(DefKind::Fn) | Some(DefKind::AssocFn) | Some(DefKind::Ctor(..)) => true,
_ => tcx.is_closure(src.def_id()),
};
match (kind, src.promoted) {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir_build/hair/cx/expr.rs
Expand Up @@ -600,7 +600,7 @@ fn user_substs_applied_to_res<'tcx>(
// a tuple-struct or tuple-variant. This has the type of a
// `Fn` but with the user-given substitutions.
Res::Def(DefKind::Fn, _)
| Res::Def(DefKind::Method, _)
| Res::Def(DefKind::AssocFn, _)
| Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
| Res::Def(DefKind::Const, _)
| Res::Def(DefKind::AssocConst, _) => {
Expand Down Expand Up @@ -703,7 +703,7 @@ fn convert_path_expr<'a, 'tcx>(
match res {
// A regular function, constructor function or a constant.
Res::Def(DefKind::Fn, _)
| Res::Def(DefKind::Method, _)
| Res::Def(DefKind::AssocFn, _)
| Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
| Res::SelfCtor(..) => {
let user_ty = user_substs_applied_to_res(cx, expr.hir_id, res);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_privacy/lib.rs
Expand Up @@ -620,7 +620,7 @@ impl EmbargoVisitor<'tcx> {
| DefKind::ForeignTy
| DefKind::Fn
| DefKind::OpaqueTy
| DefKind::Method
| DefKind::AssocFn
| DefKind::Trait
| DefKind::TyParam
| DefKind::Variant => (),
Expand Down Expand Up @@ -1298,7 +1298,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
_ => None,
};
let def = def.filter(|(kind, _)| match kind {
DefKind::Method
DefKind::AssocFn
| DefKind::AssocConst
| DefKind::AssocTy
| DefKind::AssocOpaqueTy
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -887,7 +887,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
| Res::PrimTy(..)
| Res::ToolMod => self.r.define(parent, ident, TypeNS, (res, vis, span, expansion)),
Res::Def(DefKind::Fn, _)
| Res::Def(DefKind::Method, _)
| Res::Def(DefKind::AssocFn, _)
| Res::Def(DefKind::Static, _)
| Res::Def(DefKind::Const, _)
| Res::Def(DefKind::AssocConst, _)
Expand All @@ -911,7 +911,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
let field_names = cstore.struct_field_names_untracked(def_id, self.r.session);
self.insert_field_names(def_id, field_names);
}
Res::Def(DefKind::Method, def_id) => {
Res::Def(DefKind::AssocFn, def_id) => {
if cstore.associated_item_cloned_untracked(def_id).method_has_self_argument {
self.r.has_self.insert(def_id);
}
Expand Down Expand Up @@ -1257,7 +1257,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
if sig.decl.has_self() {
self.r.has_self.insert(item_def_id);
}
(Res::Def(DefKind::Method, item_def_id), ValueNS)
(Res::Def(DefKind::AssocFn, item_def_id), ValueNS)
}
AssocItemKind::TyAlias(..) => (Res::Def(DefKind::AssocTy, item_def_id), TypeNS),
AssocItemKind::Macro(_) => bug!(), // handled above
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/late.rs
Expand Up @@ -266,7 +266,7 @@ impl<'a> PathSource<'a> {
| Res::Def(DefKind::Static, _)
| Res::Local(..)
| Res::Def(DefKind::Fn, _)
| Res::Def(DefKind::Method, _)
| Res::Def(DefKind::AssocFn, _)
| Res::Def(DefKind::AssocConst, _)
| Res::SelfCtor(..)
| Res::Def(DefKind::ConstParam, _) => true,
Expand All @@ -293,7 +293,7 @@ impl<'a> PathSource<'a> {
_ => false,
},
PathSource::TraitItem(ns) => match res {
Res::Def(DefKind::AssocConst, _) | Res::Def(DefKind::Method, _)
Res::Def(DefKind::AssocConst, _) | Res::Def(DefKind::AssocFn, _)
if ns == ValueNS =>
{
true
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/late/diagnostics.rs
Expand Up @@ -124,7 +124,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
.unwrap_or(false)
}
Res::Def(DefKind::Ctor(..), _)
| Res::Def(DefKind::Method, _)
| Res::Def(DefKind::AssocFn, _)
| Res::Def(DefKind::Const, _)
| Res::Def(DefKind::AssocConst, _)
| Res::SelfCtor(_)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/lib.rs
Expand Up @@ -742,7 +742,7 @@ impl<'a> NameBinding<'a> {
fn is_importable(&self) -> bool {
match self.res() {
Res::Def(DefKind::AssocConst, _)
| Res::Def(DefKind::Method, _)
| Res::Def(DefKind::AssocFn, _)
| Res::Def(DefKind::AssocTy, _) => false,
_ => true,
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/lib.rs
Expand Up @@ -716,7 +716,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
| Res::Def(HirDefKind::Ctor(..), _) => {
Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_def_id(res.def_id()) })
}
Res::Def(HirDefKind::Method, decl_id) => {
Res::Def(HirDefKind::AssocFn, decl_id) => {
let def_id = if decl_id.is_local() {
let ti = self.tcx.associated_item(decl_id);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/astconv.rs
Expand Up @@ -2588,7 +2588,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}

// Case 4. Reference to a method or associated const.
DefKind::Method | DefKind::AssocConst => {
DefKind::AssocFn | DefKind::AssocConst => {
if segments.len() >= 2 {
let generics = tcx.generics_of(def_id);
path_segs.push(PathSeg(generics.parent.unwrap(), last - 1));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/generator_interior.rs
Expand Up @@ -237,7 +237,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
// ZST in a temporary, so skip its type, just in case it
// can significantly complicate the generator type.
Res::Def(DefKind::Fn, _)
| Res::Def(DefKind::Method, _)
| Res::Def(DefKind::AssocFn, _)
| Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) => {
// NOTE(eddyb) this assumes a path expression has
// no nested expressions to keep track of.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -2976,7 +2976,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

pub fn write_method_call(&self, hir_id: hir::HirId, method: MethodCallee<'tcx>) {
debug!("write_method_call(hir_id={:?}, method={:?})", hir_id, method);
self.write_resolution(hir_id, Ok((DefKind::Method, method.def_id)));
self.write_resolution(hir_id, Ok((DefKind::AssocFn, method.def_id)));
self.write_substs(hir_id, method.substs);

// When the method is confirmed, the `method.substs` includes
Expand Down Expand Up @@ -5364,7 +5364,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
is_alias_variant_ctor = true;
}
}
Res::Def(DefKind::Method, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
Res::Def(DefKind::AssocFn, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
let container = tcx.associated_item(def_id).container;
debug!("instantiate_value_path: def_id={:?} container={:?}", def_id, container);
match container {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/pat.rs
Expand Up @@ -682,7 +682,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.set_tainted_by_errors();
return tcx.types.err;
}
Res::Def(DefKind::Method, _)
Res::Def(DefKind::AssocFn, _)
| Res::Def(DefKind::Ctor(_, CtorKind::Fictive), _)
| Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) => {
report_unexpected_variant_res(tcx, res, pat.span, qpath);
Expand Down Expand Up @@ -729,7 +729,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
let mut err = struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg);
match (res, &pat.kind) {
(Res::Def(DefKind::Fn, _), _) | (Res::Def(DefKind::Method, _), _) => {
(Res::Def(DefKind::Fn, _), _) | (Res::Def(DefKind::AssocFn, _), _) => {
err.span_label(pat.span, "`fn` calls are not allowed in patterns");
err.help(
"for more information, visit \
Expand Down Expand Up @@ -766,7 +766,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
on_error();
return tcx.types.err;
}
Res::Def(DefKind::AssocConst, _) | Res::Def(DefKind::Method, _) => {
Res::Def(DefKind::AssocConst, _) | Res::Def(DefKind::AssocFn, _) => {
report_unexpected_res(res);
return tcx.types.err;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/mem_categorization.rs
Expand Up @@ -425,7 +425,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
| Res::Def(DefKind::ConstParam, _)
| Res::Def(DefKind::AssocConst, _)
| Res::Def(DefKind::Fn, _)
| Res::Def(DefKind::Method, _)
| Res::Def(DefKind::AssocFn, _)
| Res::SelfCtor(..) => Ok(self.cat_rvalue(hir_id, span, expr_ty)),

Res::Def(DefKind::Static, _) => Ok(Place {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Expand Up @@ -149,7 +149,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
// In case this is a trait item, skip the
// early return and try looking for the trait.
let value = match res {
Res::Def(DefKind::Method, _) | Res::Def(DefKind::AssocConst, _) => true,
Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::AssocConst, _) => true,
Res::Def(DefKind::AssocTy, _) => false,
Res::Def(DefKind::Variant, _) => {
return handle_variant(cx, res, extra_fragment);
Expand Down Expand Up @@ -813,7 +813,7 @@ fn ambiguity_error(

for (res, ns) in candidates {
let (action, mut suggestion) = match res {
Res::Def(DefKind::Method, _) | Res::Def(DefKind::Fn, _) => {
Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::Fn, _) => {
("add parentheses", format!("{}()", path_str))
}
Res::Def(DefKind::Macro(..), _) => {
Expand Down

0 comments on commit 98c7ed6

Please sign in to comment.