Auto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot
Refactor HIR item-like traversal (part 1) Issue #95004 - Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems - use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId - use tcx.hir_crate_items to introduce a tcx.hir().par_items(impl Fn(hir::ItemId)) to traverse all items in parallel; Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com> cc `@cjgillot`
This commit is contained in:
commit
edba282770
18 changed files with 435 additions and 422 deletions
|
@ -24,7 +24,6 @@ use rustc_data_structures::fx::FxHashSet;
|
|||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::intravisit;
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::Node as HirNode;
|
||||
use rustc_hir::{ImplItemKind, ItemKind as HirItem, TraitItemKind};
|
||||
use rustc_middle::dep_graph::{label_strs, DepNode, DepNodeExt};
|
||||
|
@ -147,7 +146,24 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
|
|||
|
||||
tcx.dep_graph.with_ignore(|| {
|
||||
let mut dirty_clean_visitor = DirtyCleanVisitor { tcx, checked_attrs: Default::default() };
|
||||
tcx.hir().visit_all_item_likes(&mut dirty_clean_visitor);
|
||||
|
||||
let crate_items = tcx.hir_crate_items(());
|
||||
|
||||
for id in crate_items.items() {
|
||||
dirty_clean_visitor.check_item(id.def_id);
|
||||
}
|
||||
|
||||
for id in crate_items.trait_items() {
|
||||
dirty_clean_visitor.check_item(id.def_id);
|
||||
}
|
||||
|
||||
for id in crate_items.impl_items() {
|
||||
dirty_clean_visitor.check_item(id.def_id);
|
||||
}
|
||||
|
||||
for id in crate_items.foreign_items() {
|
||||
dirty_clean_visitor.check_item(id.def_id);
|
||||
}
|
||||
|
||||
let mut all_attrs = FindAllAttrs { tcx, found_attrs: vec![] };
|
||||
tcx.hir().walk_attributes(&mut all_attrs);
|
||||
|
@ -365,7 +381,8 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_item(&mut self, item_id: LocalDefId, item_span: Span) {
|
||||
fn check_item(&mut self, item_id: LocalDefId) {
|
||||
let item_span = self.tcx.def_span(item_id.to_def_id());
|
||||
let def_path_hash = self.tcx.def_path_hash(item_id.to_def_id());
|
||||
for attr in self.tcx.get_attrs(item_id.to_def_id()).iter() {
|
||||
let Some(assertion) = self.assertion_maybe(item_id, attr) else {
|
||||
|
@ -388,24 +405,6 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> {
|
||||
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
||||
self.check_item(item.def_id, item.span);
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, item: &hir::TraitItem<'_>) {
|
||||
self.check_item(item.def_id, item.span);
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, item: &hir::ImplItem<'_>) {
|
||||
self.check_item(item.def_id, item.span);
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, item: &hir::ForeignItem<'_>) {
|
||||
self.check_item(item.def_id, item.span);
|
||||
}
|
||||
}
|
||||
|
||||
/// Given a `#[rustc_clean]` attribute, scan for a `cfg="foo"` attribute and check whether we have
|
||||
/// a cfg flag called `foo`.
|
||||
fn check_config(tcx: TyCtxt<'_>, attr: &Attribute) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue