mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-29 03:37:26 +03:00
Track HirId when visiting attributes.
This commit is contained in:
@@ -458,7 +458,7 @@ fn visit_generic_args(&mut self, path_span: Span, generic_args: &'v GenericArgs<
|
||||
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 @@ fn visit_defaultness(&mut self, defaultness: &'v Defaultness) {
|
||||
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 @@ fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
|
||||
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 @@ fn visit_path(&mut self, p: &'tcx hir::Path<'tcx>, id: hir::HirId) {
|
||||
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 @@ fn visit_assoc_type_binding(&mut self, type_binding: &'v hir::TypeBinding<'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 @@ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user