Skip to content

Commit 7064033

Browse files
committed
remove ItemLikeVisitor impl for ContraintContext
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
1 parent 9a25164 commit 7064033

File tree

1 file changed

+50
-40
lines changed

1 file changed

+50
-40
lines changed

compiler/rustc_typeck/src/variance/constraints.rs

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use hir::def_id::{DefId, LocalDefId};
77
use rustc_hir as hir;
8-
use rustc_hir::itemlikevisit::ItemLikeVisitor;
8+
use rustc_hir::def::DefKind;
99
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
1010
use rustc_middle::ty::{self, Ty, TyCtxt};
1111

@@ -62,61 +62,71 @@ pub fn add_constraints_from_crate<'a, 'tcx>(
6262
constraints: Vec::new(),
6363
};
6464

65-
tcx.hir().visit_all_item_likes(&mut constraint_cx);
65+
let crate_items = tcx.hir_crate_items(());
66+
67+
for id in crate_items.items() {
68+
constraint_cx.check_item(id);
69+
}
70+
71+
for id in crate_items.trait_items() {
72+
if let DefKind::AssocFn = tcx.hir().def_kind(id.def_id) {
73+
constraint_cx.check_node_helper(id.hir_id());
74+
}
75+
}
76+
77+
for id in crate_items.impl_items() {
78+
if let DefKind::AssocFn = tcx.hir().def_kind(id.def_id) {
79+
constraint_cx.check_node_helper(id.hir_id());
80+
}
81+
}
82+
83+
for id in crate_items.foreign_items() {
84+
if let DefKind::AssocFn = tcx.hir().def_kind(id.def_id) {
85+
constraint_cx.check_node_helper(id.hir_id());
86+
}
87+
}
6688

6789
constraint_cx
6890
}
6991

70-
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
71-
fn visit_item(&mut self, item: &hir::Item<'_>) {
72-
match item.kind {
73-
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
74-
self.visit_node_helper(item.hir_id());
75-
76-
if let hir::VariantData::Tuple(..) = *struct_def {
77-
self.visit_node_helper(struct_def.ctor_hir_id().unwrap());
92+
impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
93+
fn check_item(&mut self, id: hir::ItemId) {
94+
let def_kind = self.tcx().hir().def_kind(id.def_id);
95+
match def_kind {
96+
DefKind::Struct | DefKind::Union => {
97+
let item = self.tcx().hir().item(id);
98+
99+
if let hir::ItemKind::Struct(ref struct_def, _)
100+
| hir::ItemKind::Union(ref struct_def, _) = item.kind
101+
{
102+
self.check_node_helper(item.hir_id());
103+
104+
if let hir::VariantData::Tuple(..) = *struct_def {
105+
self.check_node_helper(struct_def.ctor_hir_id().unwrap());
106+
}
78107
}
79108
}
109+
DefKind::Enum => {
110+
let item = self.tcx().hir().item(id);
80111

81-
hir::ItemKind::Enum(ref enum_def, _) => {
82-
self.visit_node_helper(item.hir_id());
112+
if let hir::ItemKind::Enum(ref enum_def, _) = item.kind {
113+
self.check_node_helper(item.hir_id());
83114

84-
for variant in enum_def.variants {
85-
if let hir::VariantData::Tuple(..) = variant.data {
86-
self.visit_node_helper(variant.data.ctor_hir_id().unwrap());
115+
for variant in enum_def.variants {
116+
if let hir::VariantData::Tuple(..) = variant.data {
117+
self.check_node_helper(variant.data.ctor_hir_id().unwrap());
118+
}
87119
}
88120
}
89121
}
90-
91-
hir::ItemKind::Fn(..) => {
92-
self.visit_node_helper(item.hir_id());
122+
DefKind::Fn => {
123+
self.check_node_helper(id.hir_id());
93124
}
94-
95125
_ => {}
96126
}
97127
}
98128

99-
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
100-
if let hir::TraitItemKind::Fn(..) = trait_item.kind {
101-
self.visit_node_helper(trait_item.hir_id());
102-
}
103-
}
104-
105-
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
106-
if let hir::ImplItemKind::Fn(..) = impl_item.kind {
107-
self.visit_node_helper(impl_item.hir_id());
108-
}
109-
}
110-
111-
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
112-
if let hir::ForeignItemKind::Fn(..) = foreign_item.kind {
113-
self.visit_node_helper(foreign_item.hir_id());
114-
}
115-
}
116-
}
117-
118-
impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
119-
fn visit_node_helper(&mut self, id: hir::HirId) {
129+
fn check_node_helper(&mut self, id: hir::HirId) {
120130
let tcx = self.terms_cx.tcx;
121131
let def_id = tcx.hir().local_def_id(id);
122132
self.build_constraints_for_item(def_id);

0 commit comments

Comments
 (0)