From 99ba08e6d38765d8d62e223a1c393d9f26b64c7a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Nov 2020 00:34:23 +0100 Subject: [PATCH] Access attrs directly from HirId in rustc_passes::diagnostic_item. --- compiler/rustc_passes/src/diagnostic_items.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_passes/src/diagnostic_items.rs b/compiler/rustc_passes/src/diagnostic_items.rs index 3ec7ea39248..8dd3700e5b6 100644 --- a/compiler/rustc_passes/src/diagnostic_items.rs +++ b/compiler/rustc_passes/src/diagnostic_items.rs @@ -27,19 +27,19 @@ struct DiagnosticItemCollector<'tcx> { impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> { fn visit_item(&mut self, item: &hir::Item<'_>) { - self.observe_item(&item.attrs, item.def_id); + self.observe_item(item.def_id); } fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { - self.observe_item(&trait_item.attrs, trait_item.def_id); + self.observe_item(trait_item.def_id); } fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) { - self.observe_item(&impl_item.attrs, impl_item.def_id); + self.observe_item(impl_item.def_id); } fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) { - self.observe_item(foreign_item.attrs, foreign_item.def_id); + self.observe_item(foreign_item.def_id); } } @@ -48,7 +48,9 @@ fn new(tcx: TyCtxt<'tcx>) -> DiagnosticItemCollector<'tcx> { DiagnosticItemCollector { tcx, items: Default::default() } } - fn observe_item(&mut self, attrs: &[ast::Attribute], def_id: LocalDefId) { + fn observe_item(&mut self, def_id: LocalDefId) { + let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); + let attrs = self.tcx.hir().attrs(hir_id); if let Some(name) = extract(&self.tcx.sess, attrs) { // insert into our table collect_item(self.tcx, &mut self.items, name, def_id.to_def_id()); @@ -105,7 +107,7 @@ fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap { tcx.hir().krate().visit_all_item_likes(&mut collector); for m in tcx.hir().krate().exported_macros { - collector.observe_item(m.attrs, m.def_id); + collector.observe_item(m.def_id); } collector.items