Move two methods from AssocKind
to AssocItem
.
Because all the other similar methods are on `AssocItem`.
This commit is contained in:
parent
b26f3d4347
commit
89e93a51c8
9 changed files with 26 additions and 29 deletions
|
@ -64,7 +64,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
|
||||||
|
|
||||||
fn compare_hygienically(&self, item1: ty::AssocItem, item2: ty::AssocItem) -> bool {
|
fn compare_hygienically(&self, item1: ty::AssocItem, item2: ty::AssocItem) -> bool {
|
||||||
// Symbols and namespace match, compare hygienically.
|
// Symbols and namespace match, compare hygienically.
|
||||||
item1.kind.namespace() == item2.kind.namespace()
|
item1.namespace() == item2.namespace()
|
||||||
&& item1.ident(self.tcx).normalize_to_macros_2_0()
|
&& item1.ident(self.tcx).normalize_to_macros_2_0()
|
||||||
== item2.ident(self.tcx).normalize_to_macros_2_0()
|
== item2.ident(self.tcx).normalize_to_macros_2_0()
|
||||||
}
|
}
|
||||||
|
|
|
@ -501,7 +501,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
let names: Vec<_> = tcx
|
let names: Vec<_> = tcx
|
||||||
.associated_items(trait_def_id)
|
.associated_items(trait_def_id)
|
||||||
.in_definition_order()
|
.in_definition_order()
|
||||||
.filter(|assoc| assoc.kind.namespace() == Namespace::ValueNS)
|
.filter(|assoc| assoc.namespace() == Namespace::ValueNS)
|
||||||
.map(|cand| cand.name)
|
.map(|cand| cand.name)
|
||||||
.collect();
|
.collect();
|
||||||
if let Some(typo) = find_best_match_for_name(&names, segment.ident.name, None) {
|
if let Some(typo) = find_best_match_for_name(&names, segment.ident.name, None) {
|
||||||
|
|
|
@ -1731,7 +1731,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
tcx.associated_items(*trait_def_id)
|
tcx.associated_items(*trait_def_id)
|
||||||
.in_definition_order()
|
.in_definition_order()
|
||||||
.any(|i| {
|
.any(|i| {
|
||||||
i.kind.namespace() == Namespace::TypeNS
|
i.namespace() == Namespace::TypeNS
|
||||||
&& i.ident(tcx).normalize_to_macros_2_0() == assoc_ident
|
&& i.ident(tcx).normalize_to_macros_2_0() == assoc_ident
|
||||||
&& i.is_type()
|
&& i.is_type()
|
||||||
})
|
})
|
||||||
|
|
|
@ -529,7 +529,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let def_kind = pick.item.kind.as_def_kind();
|
let def_kind = pick.item.as_def_kind();
|
||||||
tcx.check_stability(pick.item.def_id, Some(expr_id), span, Some(method_name.span));
|
tcx.check_stability(pick.item.def_id, Some(expr_id), span, Some(method_name.span));
|
||||||
Ok((def_kind, pick.item.def_id))
|
Ok((def_kind, pick.item.def_id))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1583,7 +1583,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
) {
|
) {
|
||||||
self.private_candidate.set(Some((pick.item.kind.as_def_kind(), pick.item.def_id)));
|
self.private_candidate.set(Some((pick.item.as_def_kind(), pick.item.def_id)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
@ -1694,7 +1694,7 @@ impl<'tcx> Pick<'tcx> {
|
||||||
if self.unstable_candidates.is_empty() {
|
if self.unstable_candidates.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let def_kind = self.item.kind.as_def_kind();
|
let def_kind = self.item.as_def_kind();
|
||||||
tcx.node_span_lint(lint::builtin::UNSTABLE_NAME_COLLISIONS, scope_expr_id, span, |lint| {
|
tcx.node_span_lint(lint::builtin::UNSTABLE_NAME_COLLISIONS, scope_expr_id, span, |lint| {
|
||||||
lint.primary_message(format!(
|
lint.primary_message(format!(
|
||||||
"{} {} with this name may be added to the standard library in the future",
|
"{} {} with this name may be added to the standard library in the future",
|
||||||
|
|
|
@ -1819,7 +1819,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
) {
|
) {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let def_kind = similar_candidate.kind.as_def_kind();
|
let def_kind = similar_candidate.as_def_kind();
|
||||||
let an = self.tcx.def_kind_descr_article(def_kind, similar_candidate.def_id);
|
let an = self.tcx.def_kind_descr_article(def_kind, similar_candidate.def_id);
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"there is {an} {} `{}` with a similar name",
|
"there is {an} {} `{}` with a similar name",
|
||||||
|
@ -4288,7 +4288,7 @@ fn print_disambiguation_help<'tcx>(
|
||||||
&& let SelfSource::MethodCall(receiver) = source
|
&& let SelfSource::MethodCall(receiver) = source
|
||||||
&& let Some(args) = args
|
&& let Some(args) = args
|
||||||
{
|
{
|
||||||
let def_kind_descr = tcx.def_kind_descr(item.kind.as_def_kind(), item.def_id);
|
let def_kind_descr = tcx.def_kind_descr(item.as_def_kind(), item.def_id);
|
||||||
let item_name = item.ident(tcx);
|
let item_name = item.ident(tcx);
|
||||||
let first_input =
|
let first_input =
|
||||||
tcx.fn_sig(item.def_id).instantiate_identity().skip_binder().inputs().get(0);
|
tcx.fn_sig(item.def_id).instantiate_identity().skip_binder().inputs().get(0);
|
||||||
|
|
|
@ -96,6 +96,20 @@ impl AssocItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn namespace(&self) -> Namespace {
|
||||||
|
match self.kind {
|
||||||
|
ty::AssocKind::Type { .. } => Namespace::TypeNS,
|
||||||
|
ty::AssocKind::Const | ty::AssocKind::Fn { .. } => Namespace::ValueNS,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_def_kind(&self) -> DefKind {
|
||||||
|
match self.kind {
|
||||||
|
AssocKind::Const => DefKind::AssocConst,
|
||||||
|
AssocKind::Fn { .. } => DefKind::AssocFn,
|
||||||
|
AssocKind::Type { .. } => DefKind::AssocTy,
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn is_type(&self) -> bool {
|
pub fn is_type(&self) -> bool {
|
||||||
matches!(self.kind, ty::AssocKind::Type { .. })
|
matches!(self.kind, ty::AssocKind::Type { .. })
|
||||||
}
|
}
|
||||||
|
@ -153,23 +167,6 @@ pub enum AssocKind {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AssocKind {
|
|
||||||
pub fn namespace(&self) -> Namespace {
|
|
||||||
match *self {
|
|
||||||
ty::AssocKind::Type { .. } => Namespace::TypeNS,
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for AssocKind {
|
impl std::fmt::Display for AssocKind {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
@ -250,7 +247,7 @@ impl AssocItems {
|
||||||
parent_def_id: DefId,
|
parent_def_id: DefId,
|
||||||
) -> Option<&ty::AssocItem> {
|
) -> Option<&ty::AssocItem> {
|
||||||
self.filter_by_name_unhygienic(ident.name)
|
self.filter_by_name_unhygienic(ident.name)
|
||||||
.filter(|item| item.kind.namespace() == ns)
|
.filter(|item| item.namespace() == ns)
|
||||||
.find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
|
.find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2116,7 +2116,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||||
err.note(format!(
|
err.note(format!(
|
||||||
"{}s cannot be accessed directly on a `trait`, they can only be \
|
"{}s cannot be accessed directly on a `trait`, they can only be \
|
||||||
accessed through a specific `impl`",
|
accessed through a specific `impl`",
|
||||||
self.tcx.def_kind_descr(assoc_item.kind.as_def_kind(), item_def_id)
|
self.tcx.def_kind_descr(assoc_item.as_def_kind(), item_def_id)
|
||||||
));
|
));
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
|
|
|
@ -60,7 +60,7 @@ fn filter_assoc_items_by_name_and_namespace(
|
||||||
ns: Namespace,
|
ns: Namespace,
|
||||||
) -> impl Iterator<Item = &ty::AssocItem> {
|
) -> impl Iterator<Item = &ty::AssocItem> {
|
||||||
tcx.associated_items(assoc_items_of).filter_by_name_unhygienic(ident.name).filter(move |item| {
|
tcx.associated_items(assoc_items_of).filter_by_name_unhygienic(ident.name).filter(move |item| {
|
||||||
item.kind.namespace() == ns && tcx.hygienic_eq(ident, item.ident(tcx), assoc_items_of)
|
item.namespace() == ns && tcx.hygienic_eq(ident, item.ident(tcx), assoc_items_of)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,7 +743,7 @@ impl<'tcx> LinkCollector<'_, 'tcx> {
|
||||||
ns,
|
ns,
|
||||||
)
|
)
|
||||||
.map(|item| {
|
.map(|item| {
|
||||||
let res = Res::Def(item.kind.as_def_kind(), item.def_id);
|
let res = Res::Def(item.as_def_kind(), item.def_id);
|
||||||
(res, item.def_id)
|
(res, item.def_id)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue