Skip to content

Commit b8ed2c1

Browse files
committed
Move two methods from AssocKind to AssocItem.
Because all the other similar methods are on `AssocItem`.
1 parent df945fa commit b8ed2c1

File tree

9 files changed

+26
-29
lines changed

9 files changed

+26
-29
lines changed

compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
6464

6565
fn compare_hygienically(&self, item1: ty::AssocItem, item2: ty::AssocItem) -> bool {
6666
// Symbols and namespace match, compare hygienically.
67-
item1.kind.namespace() == item2.kind.namespace()
67+
item1.namespace() == item2.namespace()
6868
&& item1.ident(self.tcx).normalize_to_macros_2_0()
6969
== item2.ident(self.tcx).normalize_to_macros_2_0()
7070
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
501501
let names: Vec<_> = tcx
502502
.associated_items(trait_def_id)
503503
.in_definition_order()
504-
.filter(|assoc| assoc.kind.namespace() == Namespace::ValueNS)
504+
.filter(|assoc| assoc.namespace() == Namespace::ValueNS)
505505
.map(|cand| cand.name)
506506
.collect();
507507
if let Some(typo) = find_best_match_for_name(&names, segment.ident.name, None) {

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
17311731
tcx.associated_items(*trait_def_id)
17321732
.in_definition_order()
17331733
.any(|i| {
1734-
i.kind.namespace() == Namespace::TypeNS
1734+
i.namespace() == Namespace::TypeNS
17351735
&& i.ident(tcx).normalize_to_macros_2_0() == assoc_ident
17361736
&& i.is_type()
17371737
})

compiler/rustc_hir_typeck/src/method/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
529529
}
530530
}
531531

532-
let def_kind = pick.item.kind.as_def_kind();
532+
let def_kind = pick.item.as_def_kind();
533533
tcx.check_stability(pick.item.def_id, Some(expr_id), span, Some(method_name.span));
534534
Ok((def_kind, pick.item.def_id))
535535
}

compiler/rustc_hir_typeck/src/method/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15831583
},
15841584
None,
15851585
) {
1586-
self.private_candidate.set(Some((pick.item.kind.as_def_kind(), pick.item.def_id)));
1586+
self.private_candidate.set(Some((pick.item.as_def_kind(), pick.item.def_id)));
15871587
}
15881588
}
15891589
None
@@ -1694,7 +1694,7 @@ impl<'tcx> Pick<'tcx> {
16941694
if self.unstable_candidates.is_empty() {
16951695
return;
16961696
}
1697-
let def_kind = self.item.kind.as_def_kind();
1697+
let def_kind = self.item.as_def_kind();
16981698
tcx.node_span_lint(lint::builtin::UNSTABLE_NAME_COLLISIONS, scope_expr_id, span, |lint| {
16991699
lint.primary_message(format!(
17001700
"{} {} with this name may be added to the standard library in the future",

compiler/rustc_hir_typeck/src/method/suggest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18191819
mode: Mode,
18201820
) {
18211821
let tcx = self.tcx;
1822-
let def_kind = similar_candidate.kind.as_def_kind();
1822+
let def_kind = similar_candidate.as_def_kind();
18231823
let an = self.tcx.def_kind_descr_article(def_kind, similar_candidate.def_id);
18241824
let msg = format!(
18251825
"there is {an} {} `{}` with a similar name",
@@ -4288,7 +4288,7 @@ fn print_disambiguation_help<'tcx>(
42884288
&& let SelfSource::MethodCall(receiver) = source
42894289
&& let Some(args) = args
42904290
{
4291-
let def_kind_descr = tcx.def_kind_descr(item.kind.as_def_kind(), item.def_id);
4291+
let def_kind_descr = tcx.def_kind_descr(item.as_def_kind(), item.def_id);
42924292
let item_name = item.ident(tcx);
42934293
let first_input =
42944294
tcx.fn_sig(item.def_id).instantiate_identity().skip_binder().inputs().get(0);

compiler/rustc_middle/src/ty/assoc.rs

+15-18
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ impl AssocItem {
9696
}
9797
}
9898

99+
pub fn namespace(&self) -> Namespace {
100+
match self.kind {
101+
ty::AssocKind::Type { .. } => Namespace::TypeNS,
102+
ty::AssocKind::Const | ty::AssocKind::Fn { .. } => Namespace::ValueNS,
103+
}
104+
}
105+
106+
pub fn as_def_kind(&self) -> DefKind {
107+
match self.kind {
108+
AssocKind::Const => DefKind::AssocConst,
109+
AssocKind::Fn { .. } => DefKind::AssocFn,
110+
AssocKind::Type { .. } => DefKind::AssocTy,
111+
}
112+
}
99113
pub fn is_type(&self) -> bool {
100114
matches!(self.kind, ty::AssocKind::Type { .. })
101115
}
@@ -153,23 +167,6 @@ pub enum AssocKind {
153167
},
154168
}
155169

156-
impl AssocKind {
157-
pub fn namespace(&self) -> Namespace {
158-
match *self {
159-
ty::AssocKind::Type { .. } => Namespace::TypeNS,
160-
ty::AssocKind::Const | ty::AssocKind::Fn { .. } => Namespace::ValueNS,
161-
}
162-
}
163-
164-
pub fn as_def_kind(&self) -> DefKind {
165-
match self {
166-
AssocKind::Const => DefKind::AssocConst,
167-
AssocKind::Fn { .. } => DefKind::AssocFn,
168-
AssocKind::Type { .. } => DefKind::AssocTy,
169-
}
170-
}
171-
}
172-
173170
impl std::fmt::Display for AssocKind {
174171
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
175172
match self {
@@ -250,7 +247,7 @@ impl AssocItems {
250247
parent_def_id: DefId,
251248
) -> Option<&ty::AssocItem> {
252249
self.filter_by_name_unhygienic(ident.name)
253-
.filter(|item| item.kind.namespace() == ns)
250+
.filter(|item| item.namespace() == ns)
254251
.find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
255252
}
256253
}

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
21162116
err.note(format!(
21172117
"{}s cannot be accessed directly on a `trait`, they can only be \
21182118
accessed through a specific `impl`",
2119-
self.tcx.def_kind_descr(assoc_item.kind.as_def_kind(), item_def_id)
2119+
self.tcx.def_kind_descr(assoc_item.as_def_kind(), item_def_id)
21202120
));
21212121
err.span_suggestion(
21222122
span,

src/librustdoc/passes/collect_intra_doc_links.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn filter_assoc_items_by_name_and_namespace(
6060
ns: Namespace,
6161
) -> impl Iterator<Item = &ty::AssocItem> {
6262
tcx.associated_items(assoc_items_of).filter_by_name_unhygienic(ident.name).filter(move |item| {
63-
item.kind.namespace() == ns && tcx.hygienic_eq(ident, item.ident(tcx), assoc_items_of)
63+
item.namespace() == ns && tcx.hygienic_eq(ident, item.ident(tcx), assoc_items_of)
6464
})
6565
}
6666

@@ -743,7 +743,7 @@ impl<'tcx> LinkCollector<'_, 'tcx> {
743743
ns,
744744
)
745745
.map(|item| {
746-
let res = Res::Def(item.kind.as_def_kind(), item.def_id);
746+
let res = Res::Def(item.as_def_kind(), item.def_id);
747747
(res, item.def_id)
748748
})
749749
.collect::<Vec<_>>(),

0 commit comments

Comments
 (0)