Skip to content

Commit a722527

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

File tree

1 file changed

+49
-38
lines changed
  • compiler/rustc_typeck/src/variance

1 file changed

+49
-38
lines changed

compiler/rustc_typeck/src/variance/terms.rs

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use rustc_arena::DroplessArena;
1313
use rustc_hir as hir;
14-
use rustc_hir::itemlikevisit::ItemLikeVisitor;
14+
use rustc_hir::def::DefKind;
1515
use rustc_hir::HirIdMap;
1616
use rustc_middle::ty::{self, TyCtxt};
1717
use std::fmt;
@@ -79,7 +79,29 @@ pub fn determine_parameters_to_be_inferred<'a, 'tcx>(
7979
//
8080
// - https://rustc-dev-guide.rust-lang.org/query.html
8181
// - https://rustc-dev-guide.rust-lang.org/variance.html
82-
tcx.hir().visit_all_item_likes(&mut terms_cx);
82+
let crate_items = tcx.hir_crate_items(());
83+
84+
for id in crate_items.items() {
85+
terms_cx.check_item(id);
86+
}
87+
88+
for id in crate_items.trait_items() {
89+
if let DefKind::AssocFn = tcx.hir().def_kind(id.def_id) {
90+
terms_cx.add_inferreds_for_item(id.hir_id());
91+
}
92+
}
93+
94+
for id in crate_items.impl_items() {
95+
if let DefKind::AssocFn = tcx.hir().def_kind(id.def_id) {
96+
terms_cx.add_inferreds_for_item(id.hir_id());
97+
}
98+
}
99+
100+
for id in crate_items.foreign_items() {
101+
if let DefKind::Fn = tcx.hir().def_kind(id.def_id) {
102+
terms_cx.add_inferreds_for_item(id.hir_id());
103+
}
104+
}
83105

84106
terms_cx
85107
}
@@ -124,54 +146,43 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> {
124146
(start..(start + count)).map(|i| &*arena.alloc(InferredTerm(InferredIndex(i)))),
125147
);
126148
}
127-
}
128149

129-
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
130-
fn visit_item(&mut self, item: &hir::Item<'_>) {
131-
debug!("add_inferreds for item {}", self.tcx.hir().node_to_string(item.hir_id()));
150+
fn check_item(&mut self, id: hir::ItemId) {
151+
debug!("add_inferreds for item {}", self.tcx.hir().node_to_string(id.hir_id()));
152+
153+
let def_kind = self.tcx.hir().def_kind(id.def_id);
154+
match def_kind {
155+
DefKind::Struct | DefKind::Union => {
156+
let item = self.tcx.hir().item(id);
132157

133-
match item.kind {
134-
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
135-
self.add_inferreds_for_item(item.hir_id());
158+
if let hir::ItemKind::Struct(ref struct_def, _)
159+
| hir::ItemKind::Union(ref struct_def, _) = item.kind
160+
{
161+
self.add_inferreds_for_item(item.hir_id());
136162

137-
if let hir::VariantData::Tuple(..) = *struct_def {
138-
self.add_inferreds_for_item(struct_def.ctor_hir_id().unwrap());
163+
if let hir::VariantData::Tuple(..) = *struct_def {
164+
self.add_inferreds_for_item(struct_def.ctor_hir_id().unwrap());
165+
}
139166
}
140167
}
168+
DefKind::Enum => {
169+
let item = self.tcx.hir().item(id);
141170

142-
hir::ItemKind::Enum(ref enum_def, _) => {
143-
self.add_inferreds_for_item(item.hir_id());
171+
if let hir::ItemKind::Enum(ref enum_def, _) = item.kind {
172+
self.add_inferreds_for_item(item.hir_id());
144173

145-
for variant in enum_def.variants {
146-
if let hir::VariantData::Tuple(..) = variant.data {
147-
self.add_inferreds_for_item(variant.data.ctor_hir_id().unwrap());
174+
for variant in enum_def.variants {
175+
if let hir::VariantData::Tuple(..) = variant.data {
176+
self.add_inferreds_for_item(variant.data.ctor_hir_id().unwrap());
177+
}
148178
}
149179
}
150180
}
151-
152-
hir::ItemKind::Fn(..) => {
153-
self.add_inferreds_for_item(item.hir_id());
181+
DefKind::Fn => {
182+
self.add_inferreds_for_item(id.hir_id());
154183
}
155-
156184
_ => {}
157185
}
158186
}
159-
160-
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
161-
if let hir::TraitItemKind::Fn(..) = trait_item.kind {
162-
self.add_inferreds_for_item(trait_item.hir_id());
163-
}
164-
}
165-
166-
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
167-
if let hir::ImplItemKind::Fn(..) = impl_item.kind {
168-
self.add_inferreds_for_item(impl_item.hir_id());
169-
}
170-
}
171-
172-
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
173-
if let hir::ForeignItemKind::Fn(..) = foreign_item.kind {
174-
self.add_inferreds_for_item(foreign_item.hir_id());
175-
}
176-
}
177187
}
188+

0 commit comments

Comments
 (0)