Skip to content

Commit dab0e75

Browse files
committed
remove DiagnosticItemCollector
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
1 parent 52f833a commit dab0e75

File tree

1 file changed

+28
-39
lines changed

1 file changed

+28
-39
lines changed

compiler/rustc_passes/src/diagnostic_items.rs

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,22 @@
1010
//! * Compiler internal types like `Ty` and `TyCtxt`
1111
1212
use rustc_ast as ast;
13-
use rustc_hir as hir;
1413
use rustc_hir::diagnostic_items::DiagnosticItems;
15-
use rustc_hir::itemlikevisit::ItemLikeVisitor;
1614
use rustc_middle::ty::query::Providers;
1715
use rustc_middle::ty::TyCtxt;
1816
use rustc_span::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
1917
use rustc_span::symbol::{sym, Symbol};
2018

21-
struct DiagnosticItemCollector<'tcx> {
19+
fn observe_item<'tcx>(
2220
tcx: TyCtxt<'tcx>,
23-
diagnostic_items: DiagnosticItems,
24-
}
25-
26-
impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> {
27-
fn visit_item(&mut self, item: &hir::Item<'_>) {
28-
self.observe_item(item.def_id);
29-
}
30-
31-
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
32-
self.observe_item(trait_item.def_id);
33-
}
34-
35-
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
36-
self.observe_item(impl_item.def_id);
37-
}
38-
39-
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
40-
self.observe_item(foreign_item.def_id);
41-
}
42-
}
43-
44-
impl<'tcx> DiagnosticItemCollector<'tcx> {
45-
fn new(tcx: TyCtxt<'tcx>) -> DiagnosticItemCollector<'tcx> {
46-
DiagnosticItemCollector { tcx, diagnostic_items: DiagnosticItems::default() }
47-
}
48-
49-
fn observe_item(&mut self, def_id: LocalDefId) {
50-
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
51-
let attrs = self.tcx.hir().attrs(hir_id);
52-
if let Some(name) = extract(attrs) {
53-
// insert into our table
54-
collect_item(self.tcx, &mut self.diagnostic_items, name, def_id.to_def_id());
55-
}
21+
diagnostic_items: &mut DiagnosticItems,
22+
def_id: LocalDefId,
23+
) {
24+
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
25+
let attrs = tcx.hir().attrs(hir_id);
26+
if let Some(name) = extract(attrs) {
27+
// insert into our table
28+
collect_item(tcx, diagnostic_items, name, def_id.to_def_id());
5629
}
5730
}
5831

@@ -95,12 +68,28 @@ fn diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> DiagnosticItems
9568
assert_eq!(cnum, LOCAL_CRATE);
9669

9770
// Initialize the collector.
98-
let mut collector = DiagnosticItemCollector::new(tcx);
71+
let mut diagnostic_items = DiagnosticItems::default();
9972

10073
// Collect diagnostic items in this crate.
101-
tcx.hir().visit_all_item_likes(&mut collector);
74+
let crate_items = tcx.hir_crate_items(());
75+
76+
for id in crate_items.items() {
77+
observe_item(tcx, &mut diagnostic_items, id.def_id);
78+
}
79+
80+
for id in crate_items.trait_items() {
81+
observe_item(tcx, &mut diagnostic_items, id.def_id);
82+
}
83+
84+
for id in crate_items.impl_items() {
85+
observe_item(tcx, &mut diagnostic_items, id.def_id);
86+
}
87+
88+
for id in crate_items.foreign_items() {
89+
observe_item(tcx, &mut diagnostic_items, id.def_id);
90+
}
10291

103-
collector.diagnostic_items
92+
diagnostic_items
10493
}
10594

10695
/// Traverse and collect all the diagnostic items in all crates.

0 commit comments

Comments
 (0)