mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 18:43:38 +00:00
remove ItemLikeVisitor impls in incremental, interface, metadata and symbol_mangling crates
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
This commit is contained in:
parent
28aa2dd3b4
commit
0d01ee9558
@ -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};
|
||||
@ -409,24 +408,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 {
|
||||
|
@ -1,6 +1,5 @@
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::symbol::sym;
|
||||
@ -9,10 +8,9 @@ fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
|
||||
let mut finder = Finder { tcx, decls: None };
|
||||
|
||||
for id in tcx.hir().items() {
|
||||
let item = tcx.hir().item(id);
|
||||
let attrs = finder.tcx.hir().attrs(item.hir_id());
|
||||
let attrs = finder.tcx.hir().attrs(id.hir_id());
|
||||
if finder.tcx.sess.contains_name(attrs, sym::rustc_proc_macro_decls) {
|
||||
finder.decls = Some(item.hir_id());
|
||||
finder.decls = Some(id.hir_id());
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,21 +22,6 @@ struct Finder<'tcx> {
|
||||
decls: Option<hir::HirId>,
|
||||
}
|
||||
|
||||
impl<'v> ItemLikeVisitor<'v> for Finder<'_> {
|
||||
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
||||
let attrs = self.tcx.hir().attrs(item.hir_id());
|
||||
if self.tcx.sess.contains_name(attrs, sym::rustc_proc_macro_decls) {
|
||||
self.decls = Some(item.hir_id());
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {}
|
||||
|
||||
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {}
|
||||
|
||||
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {}
|
||||
}
|
||||
|
||||
pub(crate) fn provide(providers: &mut Providers) {
|
||||
*providers = Providers { proc_macro_decls_static, ..*providers };
|
||||
}
|
||||
|
@ -1,36 +1,19 @@
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::cstore::ForeignModule;
|
||||
|
||||
crate fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> {
|
||||
let mut modules = Vec::new();
|
||||
for id in tcx.hir().items() {
|
||||
let item = tcx.hir().item(id);
|
||||
let hir::ItemKind::ForeignMod { items, .. } = item.kind else {
|
||||
if !matches!(tcx.hir().def_kind(id.def_id), DefKind::ForeignMod) {
|
||||
continue;
|
||||
};
|
||||
let foreign_items = items.iter().map(|it| it.id.def_id.to_def_id()).collect();
|
||||
modules.push(ForeignModule { foreign_items, def_id: id.def_id.to_def_id() });
|
||||
}
|
||||
let item = tcx.hir().item(id);
|
||||
if let hir::ItemKind::ForeignMod { items, .. } = item.kind {
|
||||
let foreign_items = items.iter().map(|it| it.id.def_id.to_def_id()).collect();
|
||||
modules.push(ForeignModule { foreign_items, def_id: id.def_id.to_def_id() });
|
||||
}
|
||||
}
|
||||
modules
|
||||
}
|
||||
|
||||
struct Collector {
|
||||
modules: Vec<ForeignModule>,
|
||||
}
|
||||
|
||||
impl<'tcx> ItemLikeVisitor<'tcx> for Collector {
|
||||
fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
|
||||
let hir::ItemKind::ForeignMod { items, .. } = it.kind else {
|
||||
return;
|
||||
};
|
||||
|
||||
let foreign_items = items.iter().map(|it| it.id.def_id.to_def_id()).collect();
|
||||
self.modules.push(ForeignModule { foreign_items, def_id: it.def_id.to_def_id() });
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {}
|
||||
fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem<'tcx>) {}
|
||||
fn visit_foreign_item(&mut self, _it: &'tcx hir::ForeignItem<'tcx>) {}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use rustc_attr as attr;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_middle::ty::{List, ParamEnv, ParamEnvAnd, Ty, TyCtxt};
|
||||
use rustc_session::cstore::{DllCallingConvention, DllImport, NativeLib};
|
||||
use rustc_session::parse::feature_err;
|
||||
@ -16,8 +16,7 @@ use rustc_target::spec::abi::Abi;
|
||||
crate fn collect(tcx: TyCtxt<'_>) -> Vec<NativeLib> {
|
||||
let mut collector = Collector { tcx, libs: Vec::new() };
|
||||
for id in tcx.hir().items() {
|
||||
let item = tcx.hir().item(id);
|
||||
collector.visit_item(item);
|
||||
collector.process_item(id);
|
||||
}
|
||||
collector.process_command_line();
|
||||
collector.libs
|
||||
@ -35,8 +34,13 @@ struct Collector<'tcx> {
|
||||
libs: Vec<NativeLib>,
|
||||
}
|
||||
|
||||
impl<'tcx> ItemLikeVisitor<'tcx> for Collector<'tcx> {
|
||||
fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
|
||||
impl<'tcx> Collector<'tcx> {
|
||||
fn process_item(&mut self, id: rustc_hir::ItemId) {
|
||||
if !matches!(self.tcx.hir().def_kind(id.def_id), DefKind::ForeignMod) {
|
||||
return;
|
||||
}
|
||||
|
||||
let it = self.tcx.hir().item(id);
|
||||
let hir::ItemKind::ForeignMod { abi, items: foreign_mod_items } = it.kind else {
|
||||
return;
|
||||
};
|
||||
@ -255,12 +259,6 @@ impl<'tcx> ItemLikeVisitor<'tcx> for Collector<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, _it: &'tcx hir::TraitItem<'tcx>) {}
|
||||
fn visit_impl_item(&mut self, _it: &'tcx hir::ImplItem<'tcx>) {}
|
||||
fn visit_foreign_item(&mut self, _it: &'tcx hir::ForeignItem<'tcx>) {}
|
||||
}
|
||||
|
||||
impl Collector<'_> {
|
||||
fn register_native_lib(&mut self, span: Option<Span>, lib: NativeLib) {
|
||||
if lib.name.as_ref().map_or(false, |&s| s == kw::Empty) {
|
||||
match span {
|
||||
|
@ -4,9 +4,7 @@
|
||||
//! def-path. This is used for unit testing the code that generates
|
||||
//! paths etc in all kinds of annoying scenarios.
|
||||
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt};
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
@ -23,27 +21,23 @@ pub fn report_symbol_names(tcx: TyCtxt<'_>) {
|
||||
}
|
||||
|
||||
tcx.dep_graph.with_ignore(|| {
|
||||
let mut visitor = SymbolNamesTest { tcx };
|
||||
let mut symbol_names = SymbolNamesTest { tcx };
|
||||
let crate_items = tcx.hir_crate_items(());
|
||||
|
||||
for id in crate_items.items() {
|
||||
let item = tcx.hir().item(id);
|
||||
visitor.visit_item(item);
|
||||
symbol_names.process_attrs(id.def_id);
|
||||
}
|
||||
|
||||
for id in crate_items.trait_items() {
|
||||
let item = tcx.hir().trait_item(id);
|
||||
visitor.visit_trait_item(item);
|
||||
symbol_names.process_attrs(id.def_id);
|
||||
}
|
||||
|
||||
for id in crate_items.impl_items() {
|
||||
let item = tcx.hir().impl_item(id);
|
||||
visitor.visit_impl_item(item);
|
||||
symbol_names.process_attrs(id.def_id);
|
||||
}
|
||||
|
||||
for id in crate_items.foreign_items() {
|
||||
let item = tcx.hir().foreign_item(id);
|
||||
visitor.visit_foreign_item(item);
|
||||
symbol_names.process_attrs(id.def_id);
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -79,21 +73,3 @@ impl SymbolNamesTest<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'tcx> {
|
||||
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
||||
self.process_attrs(item.def_id);
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
|
||||
self.process_attrs(trait_item.def_id);
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
self.process_attrs(impl_item.def_id);
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, foreign_item: &'tcx hir::ForeignItem<'tcx>) {
|
||||
self.process_attrs(foreign_item.def_id);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user