diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 61280c964360..b83c008d7174 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -458,7 +458,7 @@ pub trait Visitor<'v>: Sized { fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding<'v>) { walk_assoc_type_binding(self, type_binding) } - fn visit_attribute(&mut self, _attr: &'v Attribute) {} + fn visit_attribute(&mut self, _id: HirId, _attr: &'v Attribute) {} fn visit_macro_def(&mut self, macro_def: &'v MacroDef<'v>) { walk_macro_def(self, macro_def) } @@ -477,8 +477,10 @@ pub trait Visitor<'v>: Sized { pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) { visitor.visit_mod(&krate.item.module, krate.item.span, CRATE_HIR_ID); walk_list!(visitor, visit_macro_def, krate.exported_macros); - for attr in krate.attrs.iter().flat_map(|l| *l) { - visitor.visit_attribute(attr) + for (id, attrs) in krate.attrs.iter_enumerated() { + for a in *attrs { + visitor.visit_attribute(id, a) + } } } diff --git a/compiler/rustc_incremental/src/persist/dirty_clean.rs b/compiler/rustc_incremental/src/persist/dirty_clean.rs index 8a83149d7323..9f85aa4e8265 100644 --- a/compiler/rustc_incremental/src/persist/dirty_clean.rs +++ b/compiler/rustc_incremental/src/persist/dirty_clean.rs @@ -554,7 +554,7 @@ impl intravisit::Visitor<'tcx> for FindAllAttrs<'_, 'tcx> { intravisit::NestedVisitorMap::All(self.tcx.hir()) } - fn visit_attribute(&mut self, attr: &'tcx Attribute) { + fn visit_attribute(&mut self, _: hir::HirId, attr: &'tcx Attribute) { if self.is_active_attr(attr) { self.found_attrs.push(attr); } diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index e6b4a418309d..9a64737f3a25 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -16,7 +16,6 @@ use crate::{passes::LateLintPassObject, LateContext, LateLintPass, LintStore}; use rustc_ast as ast; -use rustc_ast::walk_list; use rustc_data_structures::sync::{join, par_iter, ParallelIterator}; use rustc_hir as hir; use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE}; @@ -333,8 +332,10 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas hir_visit::walk_path(self, p); } - fn visit_attribute(&mut self, attr: &'tcx ast::Attribute) { - lint_callback!(self, check_attribute, attr); + fn visit_attribute(&mut self, hir_id: hir::HirId, attr: &'tcx ast::Attribute) { + self.with_lint_attrs(hir_id, |cx| { + lint_callback!(cx, check_attribute, attr); + }) } } @@ -395,7 +396,9 @@ fn late_lint_mod_pass<'tcx, T: LateLintPass<'tcx>>( // Visit the crate attributes if hir_id == hir::CRATE_HIR_ID { - walk_list!(cx, visit_attribute, tcx.hir().attrs(hir::CRATE_HIR_ID)); + for attr in tcx.hir().attrs(hir::CRATE_HIR_ID).iter() { + cx.visit_attribute(hir_id, attr) + } } } diff --git a/compiler/rustc_passes/src/hir_stats.rs b/compiler/rustc_passes/src/hir_stats.rs index a2b6dd17ad9b..ccbfc6b16616 100644 --- a/compiler/rustc_passes/src/hir_stats.rs +++ b/compiler/rustc_passes/src/hir_stats.rs @@ -241,7 +241,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_assoc_type_binding(self, type_binding) } - fn visit_attribute(&mut self, attr: &'v ast::Attribute) { + fn visit_attribute(&mut self, _: hir::HirId, attr: &'v ast::Attribute) { self.record("Attribute", Id::Attr(attr.id), attr); } diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index 02b20e45d000..3dfe317a4bd1 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -120,7 +120,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> { NestedVisitorMap::All(self.tcx.hir()) } - fn visit_attribute(&mut self, attr: &'tcx Attribute) { + fn visit_attribute(&mut self, _: rustc_hir::HirId, attr: &'tcx Attribute) { if let Some((feature, stable, span)) = self.extract(attr) { self.collect_feature(feature, stable, span); } @@ -131,7 +131,7 @@ fn collect(tcx: TyCtxt<'_>) -> LibFeatures { let mut collector = LibFeatureCollector::new(tcx); let krate = tcx.hir().krate(); for attr in krate.non_exported_macro_attrs { - collector.visit_attribute(attr); + collector.visit_attribute(rustc_hir::CRATE_HIR_ID, attr); } intravisit::walk_crate(&mut collector, krate); collector.lib_features