Auto merge of #87568 - petrochenkov:localevel, r=cjgillot
rustc: Replace `HirId`s with `LocalDefId`s in `AccessLevels` tables and passes using those tables - primarily privacy checking, stability checking and dead code checking. All these passes work with definitions rather than with arbitrary HIR nodes. r? `@cjgillot` cc `@lambinoo` (#87487)
This commit is contained in:
commit
bb744e1e9f
27 changed files with 299 additions and 333 deletions
|
@ -581,14 +581,6 @@ impl<'hir> Map<'hir> {
|
|||
self.body_const_context(self.local_def_id(self.enclosing_body_owner(hir_id))).is_some()
|
||||
}
|
||||
|
||||
/// Whether `hir_id` corresponds to a `mod` or a crate.
|
||||
pub fn is_hir_id_module(&self, hir_id: HirId) -> bool {
|
||||
matches!(
|
||||
self.get(hir_id),
|
||||
Node::Item(Item { kind: ItemKind::Mod(_), .. }) | Node::Crate(..)
|
||||
)
|
||||
}
|
||||
|
||||
/// Retrieves the `HirId` for `id`'s enclosing method, unless there's a
|
||||
/// `while` or `loop` before reaching it, as block tail returns are not
|
||||
/// available in them.
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
//! which are available for use externally when compiled as a library.
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::HirId;
|
||||
use rustc_macros::HashStable;
|
||||
use std::fmt;
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use std::hash::Hash;
|
||||
|
||||
/// Represents the levels of accessibility an item can have.
|
||||
|
@ -27,8 +26,8 @@ pub enum AccessLevel {
|
|||
}
|
||||
|
||||
/// Holds a map of accessibility levels for reachable HIR nodes.
|
||||
#[derive(Clone)]
|
||||
pub struct AccessLevels<Id = HirId> {
|
||||
#[derive(Debug)]
|
||||
pub struct AccessLevels<Id = LocalDefId> {
|
||||
pub map: FxHashMap<Id, AccessLevel>,
|
||||
}
|
||||
|
||||
|
@ -49,14 +48,8 @@ impl<Id: Hash + Eq> AccessLevels<Id> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Id: Hash + Eq> Default for AccessLevels<Id> {
|
||||
impl<Id> Default for AccessLevels<Id> {
|
||||
fn default() -> Self {
|
||||
AccessLevels { map: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<Id: Hash + Eq + fmt::Debug> fmt::Debug for AccessLevels<Id> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Debug::fmt(&self.map, f)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
|
|||
use rustc_feature::GateIssue;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
|
||||
use rustc_hir::{self, HirId};
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE};
|
||||
|
@ -36,12 +36,12 @@ pub struct DeprecationEntry {
|
|||
pub attr: Deprecation,
|
||||
/// The `DefId` where the attr was originally attached. `None` for non-local
|
||||
/// `DefId`'s.
|
||||
origin: Option<HirId>,
|
||||
origin: Option<LocalDefId>,
|
||||
}
|
||||
|
||||
impl DeprecationEntry {
|
||||
pub fn local(attr: Deprecation, id: HirId) -> DeprecationEntry {
|
||||
DeprecationEntry { attr, origin: Some(id) }
|
||||
pub fn local(attr: Deprecation, def_id: LocalDefId) -> DeprecationEntry {
|
||||
DeprecationEntry { attr, origin: Some(def_id) }
|
||||
}
|
||||
|
||||
pub fn external(attr: Deprecation) -> DeprecationEntry {
|
||||
|
@ -61,9 +61,9 @@ impl DeprecationEntry {
|
|||
pub struct Index<'tcx> {
|
||||
/// This is mostly a cache, except the stabilities of local items
|
||||
/// are filled by the annotator.
|
||||
pub stab_map: FxHashMap<HirId, &'tcx Stability>,
|
||||
pub const_stab_map: FxHashMap<HirId, &'tcx ConstStability>,
|
||||
pub depr_map: FxHashMap<HirId, DeprecationEntry>,
|
||||
pub stab_map: FxHashMap<LocalDefId, &'tcx Stability>,
|
||||
pub const_stab_map: FxHashMap<LocalDefId, &'tcx ConstStability>,
|
||||
pub depr_map: FxHashMap<LocalDefId, DeprecationEntry>,
|
||||
|
||||
/// Maps for each crate whether it is part of the staged API.
|
||||
pub staged_api: FxHashMap<CrateNum, bool>,
|
||||
|
@ -73,16 +73,16 @@ pub struct Index<'tcx> {
|
|||
}
|
||||
|
||||
impl<'tcx> Index<'tcx> {
|
||||
pub fn local_stability(&self, id: HirId) -> Option<&'tcx Stability> {
|
||||
self.stab_map.get(&id).cloned()
|
||||
pub fn local_stability(&self, def_id: LocalDefId) -> Option<&'tcx Stability> {
|
||||
self.stab_map.get(&def_id).copied()
|
||||
}
|
||||
|
||||
pub fn local_const_stability(&self, id: HirId) -> Option<&'tcx ConstStability> {
|
||||
self.const_stab_map.get(&id).cloned()
|
||||
pub fn local_const_stability(&self, def_id: LocalDefId) -> Option<&'tcx ConstStability> {
|
||||
self.const_stab_map.get(&def_id).copied()
|
||||
}
|
||||
|
||||
pub fn local_deprecation_entry(&self, id: HirId) -> Option<DeprecationEntry> {
|
||||
self.depr_map.get(&id).cloned()
|
||||
pub fn local_deprecation_entry(&self, def_id: LocalDefId) -> Option<DeprecationEntry> {
|
||||
self.depr_map.get(&def_id).cloned()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2854,18 +2854,11 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
|||
tcx.arena.alloc(tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default())
|
||||
};
|
||||
|
||||
providers.lookup_stability = |tcx, id| {
|
||||
let id = tcx.hir().local_def_id_to_hir_id(id.expect_local());
|
||||
tcx.stability().local_stability(id)
|
||||
};
|
||||
providers.lookup_const_stability = |tcx, id| {
|
||||
let id = tcx.hir().local_def_id_to_hir_id(id.expect_local());
|
||||
tcx.stability().local_const_stability(id)
|
||||
};
|
||||
providers.lookup_deprecation_entry = |tcx, id| {
|
||||
let id = tcx.hir().local_def_id_to_hir_id(id.expect_local());
|
||||
tcx.stability().local_deprecation_entry(id)
|
||||
};
|
||||
providers.lookup_stability = |tcx, id| tcx.stability().local_stability(id.expect_local());
|
||||
providers.lookup_const_stability =
|
||||
|tcx, id| tcx.stability().local_const_stability(id.expect_local());
|
||||
providers.lookup_deprecation_entry =
|
||||
|tcx, id| tcx.stability().local_deprecation_entry(id.expect_local());
|
||||
providers.extern_mod_stmt_cnum =
|
||||
|tcx, id| tcx.resolutions(()).extern_crate_map.get(&id).cloned();
|
||||
providers.output_filenames = |tcx, ()| tcx.output_filenames.clone();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue