mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 12:36:47 +00:00
Stop using walk_crate.
This commit is contained in:
parent
ad3407f482
commit
7ec973d9ce
@ -478,7 +478,7 @@ pub trait Visitor<'v>: Sized {
|
||||
}
|
||||
|
||||
/// Walks the contents of a crate. See also `Crate::visit_all_items`.
|
||||
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
|
||||
pub fn walk_crate_and_attributes<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
|
||||
let top_mod = krate.module();
|
||||
visitor.visit_mod(top_mod, top_mod.inner, CRATE_HIR_ID);
|
||||
for (&id, attrs) in krate.attrs.iter() {
|
||||
|
@ -142,7 +142,7 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
|
||||
krate.visit_all_item_likes(&mut dirty_clean_visitor);
|
||||
|
||||
let mut all_attrs = FindAllAttrs { tcx, found_attrs: vec![] };
|
||||
intravisit::walk_crate(&mut all_attrs, krate);
|
||||
tcx.hir().walk_attributes(&mut all_attrs);
|
||||
|
||||
// Note that we cannot use the existing "unused attribute"-infrastructure
|
||||
// here, since that is running before codegen. This is also the reason why
|
||||
|
@ -451,9 +451,8 @@ fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T)
|
||||
// since the root module isn't visited as an item (because it isn't an
|
||||
// item), warn for it here.
|
||||
lint_callback!(cx, check_crate, krate);
|
||||
|
||||
hir_visit::walk_crate(cx, krate);
|
||||
|
||||
tcx.hir().walk_crate(cx);
|
||||
tcx.hir().walk_attributes(cx);
|
||||
lint_callback!(cx, check_crate_post, krate);
|
||||
})
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap {
|
||||
|
||||
let push = builder.levels.push(tcx.hir().attrs(hir::CRATE_HIR_ID), &store, true);
|
||||
builder.levels.register_id(hir::CRATE_HIR_ID);
|
||||
intravisit::walk_crate(&mut builder, krate);
|
||||
tcx.hir().walk_crate(&mut builder);
|
||||
builder.levels.pop(push);
|
||||
|
||||
builder.levels.build_map()
|
||||
|
@ -7,9 +7,9 @@ use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
|
||||
use rustc_hir::intravisit;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::*;
|
||||
use rustc_index::vec::Idx;
|
||||
@ -519,6 +519,22 @@ impl<'hir> Map<'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Walks the contents of a crate. See also `Crate::visit_all_items`.
|
||||
pub fn walk_crate(self, visitor: &mut impl Visitor<'hir>) {
|
||||
let (top_mod, span, hir_id) = self.get_module(CRATE_DEF_ID);
|
||||
visitor.visit_mod(top_mod, span, hir_id);
|
||||
}
|
||||
|
||||
/// Walks the attributes in a crate.
|
||||
pub fn walk_attributes(self, visitor: &mut impl Visitor<'hir>) {
|
||||
let krate = self.krate();
|
||||
for (&id, attrs) in krate.attrs.iter() {
|
||||
for a in *attrs {
|
||||
visitor.visit_attribute(id, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn visit_item_likes_in_module<V>(&self, module: LocalDefId, visitor: &mut V)
|
||||
where
|
||||
V: ItemLikeVisitor<'hir>,
|
||||
@ -934,7 +950,8 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx IndexedHir<'tc
|
||||
&tcx.untracked_resolutions.definitions,
|
||||
hcx,
|
||||
);
|
||||
intravisit::walk_crate(&mut collector, tcx.untracked_crate);
|
||||
let top_mod = tcx.untracked_crate.module();
|
||||
collector.visit_mod(top_mod, top_mod.inner, CRATE_HIR_ID);
|
||||
|
||||
let map = collector.finalize_and_compute_crate_hash();
|
||||
tcx.arena.alloc(map)
|
||||
|
@ -775,5 +775,5 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||
let krate = tcx.hir().krate();
|
||||
let live_symbols = find_live(tcx, access_levels, krate);
|
||||
let mut visitor = DeadVisitor { tcx, live_symbols };
|
||||
intravisit::walk_crate(&mut visitor, krate);
|
||||
tcx.hir().walk_crate(&mut visitor);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ pub fn print_hir_stats(krate: &hir::Crate<'_>) {
|
||||
data: FxHashMap::default(),
|
||||
seen: FxHashSet::default(),
|
||||
};
|
||||
hir_visit::walk_crate(&mut collector, krate);
|
||||
hir_visit::walk_crate_and_attributes(&mut collector, krate);
|
||||
collector.print("HIR STATS");
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
use rustc_ast::{Attribute, MetaItem, MetaItemKind};
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::intravisit::{NestedVisitorMap, Visitor};
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::middle::lib_features::LibFeatures;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
@ -126,9 +126,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> {
|
||||
|
||||
fn get_lib_features(tcx: TyCtxt<'_>, (): ()) -> LibFeatures {
|
||||
let mut collector = LibFeatureCollector::new(tcx);
|
||||
let krate = tcx.hir().krate();
|
||||
|
||||
intravisit::walk_crate(&mut collector, krate);
|
||||
tcx.hir().walk_attributes(&mut collector);
|
||||
collector.lib_features
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::hir_id::CRATE_HIR_ID;
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::{FieldDef, Generics, HirId, Item, TraitRef, Ty, TyKind, Variant};
|
||||
use rustc_middle::hir::map::Map;
|
||||
@ -678,7 +679,6 @@ fn stability_index(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> {
|
||||
.collect();
|
||||
|
||||
{
|
||||
let krate = tcx.hir().krate();
|
||||
let mut annotator = Annotator {
|
||||
tcx,
|
||||
index: &mut index,
|
||||
@ -711,13 +711,13 @@ fn stability_index(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> {
|
||||
|
||||
annotator.annotate(
|
||||
CRATE_DEF_ID,
|
||||
krate.module().inner,
|
||||
tcx.hir().span(CRATE_HIR_ID),
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
InheritDeprecation::Yes,
|
||||
InheritConstStability::No,
|
||||
InheritStability::No,
|
||||
|v| intravisit::walk_crate(v, krate),
|
||||
|v| tcx.hir().walk_crate(v),
|
||||
);
|
||||
}
|
||||
index
|
||||
@ -908,8 +908,8 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
||||
if tcx.stability().staged_api[&LOCAL_CRATE] {
|
||||
let krate = tcx.hir().krate();
|
||||
let mut missing = MissingStabilityAnnotations { tcx, access_levels };
|
||||
missing.check_missing_stability(CRATE_DEF_ID, krate.module().inner);
|
||||
intravisit::walk_crate(&mut missing, krate);
|
||||
missing.check_missing_stability(CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID));
|
||||
tcx.hir().walk_crate(&mut missing);
|
||||
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
|
||||
}
|
||||
|
||||
|
@ -2169,7 +2169,7 @@ fn privacy_access_levels(tcx: TyCtxt<'_>, (): ()) -> &AccessLevels {
|
||||
changed: false,
|
||||
};
|
||||
loop {
|
||||
intravisit::walk_crate(&mut visitor, tcx.hir().krate());
|
||||
tcx.hir().walk_crate(&mut visitor);
|
||||
if visitor.changed {
|
||||
visitor.changed = false;
|
||||
} else {
|
||||
@ -2192,11 +2192,11 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
|
||||
in_variant: false,
|
||||
old_error_set: Default::default(),
|
||||
};
|
||||
intravisit::walk_crate(&mut visitor, krate);
|
||||
tcx.hir().walk_crate(&mut visitor);
|
||||
|
||||
let has_pub_restricted = {
|
||||
let mut pub_restricted_visitor = PubRestrictedVisitor { tcx, has_pub_restricted: false };
|
||||
intravisit::walk_crate(&mut pub_restricted_visitor, krate);
|
||||
tcx.hir().walk_crate(&mut pub_restricted_visitor);
|
||||
pub_restricted_visitor.has_pub_restricted
|
||||
};
|
||||
|
||||
|
@ -1122,7 +1122,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
attributes: lower_attributes(attrs.to_owned(), &self.save_ctxt),
|
||||
},
|
||||
);
|
||||
intravisit::walk_crate(self, krate);
|
||||
self.tcx.hir().walk_crate(self);
|
||||
}
|
||||
|
||||
fn process_bounds(&mut self, bounds: hir::GenericBounds<'tcx>) {
|
||||
|
@ -1012,8 +1012,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
) {
|
||||
let module_did = self.tcx.parent_module(self.body_id);
|
||||
let module_id = self.tcx.hir().local_def_id_to_hir_id(module_did);
|
||||
let krate = self.tcx.hir().krate();
|
||||
let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id);
|
||||
let (span, found_use) = UsePlacementFinder::check(self.tcx, module_id);
|
||||
if let Some(span) = span {
|
||||
let path_strings = candidates.iter().map(|did| {
|
||||
// Produce an additional newline to separate the new use statement
|
||||
@ -1614,13 +1613,9 @@ struct UsePlacementFinder<'tcx> {
|
||||
}
|
||||
|
||||
impl UsePlacementFinder<'tcx> {
|
||||
fn check(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
krate: &'tcx hir::Crate<'tcx>,
|
||||
target_module: hir::HirId,
|
||||
) -> (Option<Span>, bool) {
|
||||
fn check(tcx: TyCtxt<'tcx>, target_module: hir::HirId) -> (Option<Span>, bool) {
|
||||
let mut finder = UsePlacementFinder { target_module, span: None, found_use: false, tcx };
|
||||
intravisit::walk_crate(&mut finder, krate);
|
||||
tcx.hir().walk_crate(&mut finder);
|
||||
(finder.span, finder.found_use)
|
||||
}
|
||||
}
|
||||
|
@ -691,7 +691,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
|
||||
debug!("find_opaque_ty_constraints: scope={:?}", scope);
|
||||
|
||||
if scope == hir::CRATE_HIR_ID {
|
||||
intravisit::walk_crate(&mut locator, tcx.hir().krate());
|
||||
tcx.hir().walk_crate(&mut locator);
|
||||
} else {
|
||||
debug!("find_opaque_ty_constraints: scope={:?}", tcx.hir().get(scope));
|
||||
match tcx.hir().get(scope) {
|
||||
|
@ -116,7 +116,6 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
|
||||
let mut global_ctxt = queries.global_ctxt()?.take();
|
||||
|
||||
let collector = global_ctxt.enter(|tcx| {
|
||||
let krate = tcx.hir().krate();
|
||||
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
|
||||
|
||||
let mut opts = scrape_test_config(crate_attrs);
|
||||
@ -144,10 +143,8 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
|
||||
hir_collector.visit_testable(
|
||||
"".to_string(),
|
||||
CRATE_HIR_ID,
|
||||
krate.module().inner,
|
||||
|this| {
|
||||
intravisit::walk_crate(this, krate);
|
||||
},
|
||||
tcx.hir().span(CRATE_HIR_ID),
|
||||
|this| tcx.hir().walk_crate(this),
|
||||
);
|
||||
|
||||
collector
|
||||
|
@ -45,7 +45,7 @@ crate fn collect_spans_and_sources(
|
||||
|
||||
if include_sources {
|
||||
if generate_link_to_definition {
|
||||
intravisit::walk_crate(&mut visitor, tcx.hir().krate());
|
||||
tcx.hir().walk_crate(&mut visitor);
|
||||
}
|
||||
let (krate, sources) = sources::collect_local_sources(tcx, src_root, krate);
|
||||
(krate, sources, visitor.matches)
|
||||
|
Loading…
Reference in New Issue
Block a user