Skip to content

Commit 27ef0ee

Browse files
committed
Track HirId when visiting attributes.
1 parent 6b5d2de commit 27ef0ee

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

compiler/rustc_hir/src/intravisit.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ pub trait Visitor<'v>: Sized {
458458
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding<'v>) {
459459
walk_assoc_type_binding(self, type_binding)
460460
}
461-
fn visit_attribute(&mut self, _attr: &'v Attribute) {}
461+
fn visit_attribute(&mut self, _id: HirId, _attr: &'v Attribute) {}
462462
fn visit_macro_def(&mut self, macro_def: &'v MacroDef<'v>) {
463463
walk_macro_def(self, macro_def)
464464
}
@@ -477,8 +477,10 @@ pub trait Visitor<'v>: Sized {
477477
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
478478
visitor.visit_mod(&krate.item.module, krate.item.span, CRATE_HIR_ID);
479479
walk_list!(visitor, visit_macro_def, krate.exported_macros);
480-
for attr in krate.attrs.iter().flat_map(|l| *l) {
481-
visitor.visit_attribute(attr)
480+
for (id, attrs) in krate.attrs.iter_enumerated() {
481+
for a in *attrs {
482+
visitor.visit_attribute(id, a)
483+
}
482484
}
483485
}
484486

compiler/rustc_incremental/src/persist/dirty_clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ impl intravisit::Visitor<'tcx> for FindAllAttrs<'_, 'tcx> {
554554
intravisit::NestedVisitorMap::All(self.tcx.hir())
555555
}
556556

557-
fn visit_attribute(&mut self, attr: &'tcx Attribute) {
557+
fn visit_attribute(&mut self, _: hir::HirId, attr: &'tcx Attribute) {
558558
if self.is_active_attr(attr) {
559559
self.found_attrs.push(attr);
560560
}

compiler/rustc_lint/src/late.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
1717
use crate::{passes::LateLintPassObject, LateContext, LateLintPass, LintStore};
1818
use rustc_ast as ast;
19-
use rustc_ast::walk_list;
2019
use rustc_data_structures::sync::{join, par_iter, ParallelIterator};
2120
use rustc_hir as hir;
2221
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
@@ -333,8 +332,10 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
333332
hir_visit::walk_path(self, p);
334333
}
335334

336-
fn visit_attribute(&mut self, attr: &'tcx ast::Attribute) {
337-
lint_callback!(self, check_attribute, attr);
335+
fn visit_attribute(&mut self, hir_id: hir::HirId, attr: &'tcx ast::Attribute) {
336+
self.with_lint_attrs(hir_id, |cx| {
337+
lint_callback!(cx, check_attribute, attr);
338+
})
338339
}
339340
}
340341

@@ -395,7 +396,9 @@ fn late_lint_mod_pass<'tcx, T: LateLintPass<'tcx>>(
395396

396397
// Visit the crate attributes
397398
if hir_id == hir::CRATE_HIR_ID {
398-
walk_list!(cx, visit_attribute, tcx.hir().attrs(hir::CRATE_HIR_ID));
399+
for attr in tcx.hir().attrs(hir::CRATE_HIR_ID).iter() {
400+
cx.visit_attribute(hir_id, attr)
401+
}
399402
}
400403
}
401404

compiler/rustc_passes/src/hir_stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
241241
hir_visit::walk_assoc_type_binding(self, type_binding)
242242
}
243243

244-
fn visit_attribute(&mut self, attr: &'v ast::Attribute) {
244+
fn visit_attribute(&mut self, _: hir::HirId, attr: &'v ast::Attribute) {
245245
self.record("Attribute", Id::Attr(attr.id), attr);
246246
}
247247

compiler/rustc_passes/src/lib_features.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> {
120120
NestedVisitorMap::All(self.tcx.hir())
121121
}
122122

123-
fn visit_attribute(&mut self, attr: &'tcx Attribute) {
123+
fn visit_attribute(&mut self, _: rustc_hir::HirId, attr: &'tcx Attribute) {
124124
if let Some((feature, stable, span)) = self.extract(attr) {
125125
self.collect_feature(feature, stable, span);
126126
}
@@ -131,7 +131,7 @@ fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
131131
let mut collector = LibFeatureCollector::new(tcx);
132132
let krate = tcx.hir().krate();
133133
for attr in krate.non_exported_macro_attrs {
134-
collector.visit_attribute(attr);
134+
collector.visit_attribute(rustc_hir::CRATE_HIR_ID, attr);
135135
}
136136
intravisit::walk_crate(&mut collector, krate);
137137
collector.lib_features

0 commit comments

Comments
 (0)