Reduce uses of hir_crate.
This commit is contained in:
@@ -292,7 +292,11 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
|
||||
}
|
||||
HirTree => {
|
||||
debug!("pretty printing HIR tree");
|
||||
format!("{:#?}", ex.tcx().hir_crate(()))
|
||||
ex.tcx()
|
||||
.hir_crate_items(())
|
||||
.owners()
|
||||
.map(|owner| format!("{:#?} => {:#?}\n", owner, ex.tcx().hir_owner_nodes(owner)))
|
||||
.collect()
|
||||
}
|
||||
Mir => {
|
||||
let mut out = Vec::new();
|
||||
|
||||
@@ -1011,7 +1011,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
|
||||
// Prefetch this to prevent multiple threads from blocking on it later.
|
||||
// This is needed since the `hir_id_validator::check_crate` call above is not guaranteed
|
||||
// to use `hir_crate`.
|
||||
tcx.ensure_done().hir_crate(());
|
||||
tcx.ensure_done().hir_crate_items(());
|
||||
|
||||
let sess = tcx.sess;
|
||||
sess.time("misc_checking_1", || {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::CRATE_OWNER_ID;
|
||||
use rustc_middle::lint::LintExpectation;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
@@ -18,7 +17,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
|
||||
|
||||
let mut expectations = Vec::new();
|
||||
|
||||
for owner in std::iter::once(CRATE_OWNER_ID).chain(krate.owners()) {
|
||||
for owner in krate.owners() {
|
||||
let lints = tcx.shallow_lint_levels_on(owner);
|
||||
expectations.extend_from_slice(&lints.expectations);
|
||||
}
|
||||
|
||||
@@ -328,8 +328,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}
|
||||
|
||||
/// Returns an iterator of the `DefId`s for all body-owners in this
|
||||
/// crate. If you would prefer to iterate over the bodies
|
||||
/// themselves, you can do `self.hir_crate(()).body_ids.iter()`.
|
||||
/// crate.
|
||||
#[inline]
|
||||
pub fn hir_body_owners(self) -> impl Iterator<Item = LocalDefId> {
|
||||
self.hir_crate_items(()).body_owners.iter().copied()
|
||||
@@ -396,12 +395,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
where
|
||||
V: Visitor<'tcx>,
|
||||
{
|
||||
let krate = self.hir_crate(());
|
||||
for info in krate.owners.iter() {
|
||||
if let MaybeOwner::Owner(info) = info {
|
||||
for attrs in info.attrs.map.values() {
|
||||
walk_list!(visitor, visit_attribute, *attrs);
|
||||
}
|
||||
let krate = self.hir_crate_items(());
|
||||
for owner in krate.owners() {
|
||||
let attrs = self.hir_attr_map(owner);
|
||||
for attrs in attrs.map.values() {
|
||||
walk_list!(visitor, visit_attribute, *attrs);
|
||||
}
|
||||
}
|
||||
V::Result::output()
|
||||
@@ -1225,6 +1223,7 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
|
||||
..
|
||||
} = collector;
|
||||
ModuleItems {
|
||||
add_root: false,
|
||||
submodules: submodules.into_boxed_slice(),
|
||||
free_items: items.into_boxed_slice(),
|
||||
trait_items: trait_items.into_boxed_slice(),
|
||||
@@ -1258,6 +1257,7 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
|
||||
} = collector;
|
||||
|
||||
ModuleItems {
|
||||
add_root: true,
|
||||
submodules: submodules.into_boxed_slice(),
|
||||
free_items: items.into_boxed_slice(),
|
||||
trait_items: trait_items.into_boxed_slice(),
|
||||
|
||||
@@ -24,6 +24,9 @@ use crate::ty::{EarlyBinder, ImplSubject, TyCtxt};
|
||||
/// bodies. The Ids are in visitor order. This is used to partition a pass between modules.
|
||||
#[derive(Debug, HashStable, Encodable, Decodable)]
|
||||
pub struct ModuleItems {
|
||||
/// Whether this represents the whole crate, in which case we need to add `CRATE_OWNER_ID` to
|
||||
/// the iterators if we want to account for the crate root.
|
||||
add_root: bool,
|
||||
submodules: Box<[OwnerId]>,
|
||||
free_items: Box<[ItemId]>,
|
||||
trait_items: Box<[TraitItemId]>,
|
||||
@@ -60,9 +63,10 @@ impl ModuleItems {
|
||||
}
|
||||
|
||||
pub fn owners(&self) -> impl Iterator<Item = OwnerId> {
|
||||
self.free_items
|
||||
.iter()
|
||||
.map(|id| id.owner_id)
|
||||
self.add_root
|
||||
.then_some(CRATE_OWNER_ID)
|
||||
.into_iter()
|
||||
.chain(self.free_items.iter().map(|id| id.owner_id))
|
||||
.chain(self.trait_items.iter().map(|id| id.owner_id))
|
||||
.chain(self.impl_items.iter().map(|id| id.owner_id))
|
||||
.chain(self.foreign_items.iter().map(|id| id.owner_id))
|
||||
|
||||
@@ -2118,7 +2118,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
) -> &'tcx rustc_hir::def_path_hash_map::DefPathHashMap {
|
||||
// Create a dependency to the crate to be sure we re-execute this when the amount of
|
||||
// definitions change.
|
||||
self.ensure_ok().hir_crate(());
|
||||
self.ensure_ok().hir_crate_items(());
|
||||
// Freeze definitions once we start iterating on them, to prevent adding new ones
|
||||
// while iterating. If some query needs to add definitions, it should be `ensure`d above.
|
||||
self.untracked.definitions.freeze().def_path_hash_to_def_index_map()
|
||||
|
||||
@@ -387,8 +387,6 @@ pub(crate) fn run_global_ctxt(
|
||||
ctxt.external_traits.insert(sized_trait_did, sized_trait);
|
||||
}
|
||||
|
||||
debug!("crate: {:?}", tcx.hir_crate(()));
|
||||
|
||||
let mut krate = tcx.sess.time("clean_crate", || clean::krate(&mut ctxt));
|
||||
|
||||
if krate.module.doc_value().is_empty() {
|
||||
|
||||
@@ -24,10 +24,7 @@ error: `size_of_val` is not yet stable as a const intrinsic
|
||||
LL | unstable_intrinsic::size_of_val(&x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||
|
|
||||
LL + #![feature(unstable)]
|
||||
|
|
||||
= help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||
|
||||
error: `align_of_val` is not yet stable as a const intrinsic
|
||||
--> $DIR/const-unstable-intrinsic.rs:20:9
|
||||
@@ -35,10 +32,7 @@ error: `align_of_val` is not yet stable as a const intrinsic
|
||||
LL | unstable_intrinsic::align_of_val(&x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||
|
|
||||
LL + #![feature(unstable)]
|
||||
|
|
||||
= help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||
|
||||
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(local)]`
|
||||
--> $DIR/const-unstable-intrinsic.rs:24:9
|
||||
|
||||
@@ -4,10 +4,7 @@ error: `foobar` is not yet stable as a const fn
|
||||
LL | foobar();
|
||||
| ^^^^^^^^
|
||||
|
|
||||
help: add `#![feature(const_foobar)]` to the crate attributes to enable
|
||||
|
|
||||
LL + #![feature(const_foobar)]
|
||||
|
|
||||
= help: add `#![feature(const_foobar)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
||||
@@ -15,10 +15,7 @@ error: `staged_api::MyTrait` is not yet stable as a const trait
|
||||
LL | Unstable::func();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||
|
|
||||
LL + #![feature(unstable)]
|
||||
|
|
||||
= help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
||||
Reference in New Issue
Block a user