Access attrs directly from HirId in rustc_passes::diagnostic_item.

This commit is contained in:
Camille GILLOT 2020-11-27 00:34:23 +01:00
parent 662f11ade6
commit 99ba08e6d3

View File

@ -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<Symbol, DefId> {
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