Track HirId when visiting attributes.
This commit is contained in:
parent
6b5d2de97e
commit
27ef0eeaa4
5 changed files with 16 additions and 11 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue