From 12a3024c573a8c2716432a063fa4ae21f335824a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 26 Nov 2020 19:12:24 +0100 Subject: [PATCH] Use visitor for its very purpose. --- compiler/rustc_passes/src/diagnostic_items.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_passes/src/diagnostic_items.rs b/compiler/rustc_passes/src/diagnostic_items.rs index 965a97b1b67..699c96bc49d 100644 --- a/compiler/rustc_passes/src/diagnostic_items.rs +++ b/compiler/rustc_passes/src/diagnostic_items.rs @@ -38,7 +38,9 @@ fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) { self.observe_item(&impl_item.attrs, impl_item.hir_id); } - fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {} + fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) { + self.observe_item(foreign_item.attrs, foreign_item.hir_id); + } } impl<'tcx> DiagnosticItemCollector<'tcx> { @@ -102,18 +104,6 @@ fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap { // Collect diagnostic items in this crate. tcx.hir().krate().visit_all_item_likes(&mut collector); - // FIXME(visit_all_item_likes): Foreign items are not visited - // here, so we have to manually look at them for now. - for (_, foreign_module) in tcx.foreign_modules(LOCAL_CRATE).iter() { - for &foreign_item in foreign_module.foreign_items.iter() { - match tcx.hir().get(tcx.hir().local_def_id_to_hir_id(foreign_item.expect_local())) { - hir::Node::ForeignItem(item) => { - collector.observe_item(item.attrs, item.hir_id); - } - item => bug!("unexpected foreign item {:?}", item), - } - } - } for m in tcx.hir().krate().exported_macros { collector.observe_item(m.attrs, m.hir_id);