Rollup merge of #114772 - fee1-dead-contrib:typed-did, r=b-naber
Add `{Local}ModDefId` to more strongly type DefIds`
Based on #110862 by `@Nilstrieb`
This commit is contained in:
@@ -235,6 +235,7 @@ trivial! {
|
||||
rustc_hir::def_id::DefId,
|
||||
rustc_hir::def_id::DefIndex,
|
||||
rustc_hir::def_id::LocalDefId,
|
||||
rustc_hir::def_id::LocalModDefId,
|
||||
rustc_hir::def::DefKind,
|
||||
rustc_hir::Defaultness,
|
||||
rustc_hir::definitions::DefKey,
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::ty::fast_reject::SimplifiedType;
|
||||
use crate::ty::layout::{TyAndLayout, ValidityRequirement};
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
use crate::ty::{GenericArg, GenericArgsRef};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalModDefId, ModDefId, LOCAL_CRATE};
|
||||
use rustc_hir::hir_id::{HirId, OwnerId};
|
||||
use rustc_query_system::query::{DefaultCacheSelector, SingleCacheSelector, VecCacheSelector};
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
@@ -175,6 +175,41 @@ impl AsLocalKey for DefId {
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for LocalModDefId {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(*self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn key_as_def_id(&self) -> Option<DefId> {
|
||||
Some(self.to_def_id())
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for ModDefId {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(*self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn key_as_def_id(&self) -> Option<DefId> {
|
||||
Some(self.to_def_id())
|
||||
}
|
||||
}
|
||||
|
||||
impl AsLocalKey for ModDefId {
|
||||
type LocalKey = LocalModDefId;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
self.as_local()
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for SimplifiedType {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, DocLinkResMap};
|
||||
use rustc_hir::def_id::{
|
||||
CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LocalDefIdMap, LocalDefIdSet,
|
||||
CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LocalDefIdMap, LocalDefIdSet, LocalModDefId,
|
||||
};
|
||||
use rustc_hir::lang_items::{LangItem, LanguageItems};
|
||||
use rustc_hir::{Crate, ItemLocalId, TraitCandidate};
|
||||
@@ -167,7 +167,7 @@ rustc_queries! {
|
||||
///
|
||||
/// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
|
||||
/// Avoid calling this query directly.
|
||||
query hir_module_items(key: LocalDefId) -> &'tcx rustc_middle::hir::ModuleItems {
|
||||
query hir_module_items(key: LocalModDefId) -> &'tcx rustc_middle::hir::ModuleItems {
|
||||
arena_cache
|
||||
desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key) }
|
||||
cache_on_disk_if { true }
|
||||
@@ -896,7 +896,7 @@ rustc_queries! {
|
||||
}
|
||||
|
||||
/// Performs lint checking for the module.
|
||||
query lint_mod(key: LocalDefId) -> () {
|
||||
query lint_mod(key: LocalModDefId) -> () {
|
||||
desc { |tcx| "linting {}", describe_as_module(key, tcx) }
|
||||
}
|
||||
|
||||
@@ -905,35 +905,35 @@ rustc_queries! {
|
||||
}
|
||||
|
||||
/// Checks the attributes in the module.
|
||||
query check_mod_attrs(key: LocalDefId) -> () {
|
||||
query check_mod_attrs(key: LocalModDefId) -> () {
|
||||
desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
|
||||
}
|
||||
|
||||
/// Checks for uses of unstable APIs in the module.
|
||||
query check_mod_unstable_api_usage(key: LocalDefId) -> () {
|
||||
query check_mod_unstable_api_usage(key: LocalModDefId) -> () {
|
||||
desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
|
||||
}
|
||||
|
||||
/// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
|
||||
query check_mod_const_bodies(key: LocalDefId) -> () {
|
||||
query check_mod_const_bodies(key: LocalModDefId) -> () {
|
||||
desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
|
||||
}
|
||||
|
||||
/// Checks the loops in the module.
|
||||
query check_mod_loops(key: LocalDefId) -> () {
|
||||
query check_mod_loops(key: LocalModDefId) -> () {
|
||||
desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
|
||||
}
|
||||
|
||||
query check_mod_naked_functions(key: LocalDefId) -> () {
|
||||
query check_mod_naked_functions(key: LocalModDefId) -> () {
|
||||
desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
|
||||
}
|
||||
|
||||
query check_mod_item_types(key: LocalDefId) -> () {
|
||||
query check_mod_item_types(key: LocalModDefId) -> () {
|
||||
desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
|
||||
}
|
||||
|
||||
query check_mod_privacy(key: LocalDefId) -> () {
|
||||
desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
|
||||
query check_mod_privacy(key: LocalModDefId) -> () {
|
||||
desc { |tcx| "checking privacy in {}", describe_as_module(key.to_local_def_id(), tcx) }
|
||||
}
|
||||
|
||||
query check_liveness(key: LocalDefId) {
|
||||
@@ -952,19 +952,19 @@ rustc_queries! {
|
||||
desc { "finding live symbols in crate" }
|
||||
}
|
||||
|
||||
query check_mod_deathness(key: LocalDefId) -> () {
|
||||
query check_mod_deathness(key: LocalModDefId) -> () {
|
||||
desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
|
||||
}
|
||||
|
||||
query check_mod_impl_wf(key: LocalDefId) -> () {
|
||||
query check_mod_impl_wf(key: LocalModDefId) -> () {
|
||||
desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
|
||||
}
|
||||
|
||||
query check_mod_type_wf(key: LocalDefId) -> () {
|
||||
query check_mod_type_wf(key: LocalModDefId) -> () {
|
||||
desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
|
||||
}
|
||||
|
||||
query collect_mod_item_types(key: LocalDefId) -> () {
|
||||
query collect_mod_item_types(key: LocalModDefId) -> () {
|
||||
desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
|
||||
}
|
||||
|
||||
|
||||
@@ -545,6 +545,7 @@ macro_rules! define_feedable {
|
||||
|
||||
mod sealed {
|
||||
use super::{DefId, LocalDefId, OwnerId};
|
||||
use rustc_hir::def_id::{LocalModDefId, ModDefId};
|
||||
|
||||
/// An analogue of the `Into` trait that's intended only for query parameters.
|
||||
///
|
||||
@@ -588,6 +589,27 @@ mod sealed {
|
||||
self.to_def_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoQueryParam<DefId> for ModDefId {
|
||||
#[inline(always)]
|
||||
fn into_query_param(self) -> DefId {
|
||||
self.to_def_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoQueryParam<DefId> for LocalModDefId {
|
||||
#[inline(always)]
|
||||
fn into_query_param(self) -> DefId {
|
||||
self.to_def_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoQueryParam<LocalDefId> for LocalModDefId {
|
||||
#[inline(always)]
|
||||
fn into_query_param(self) -> LocalDefId {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub use sealed::IntoQueryParam;
|
||||
|
||||
Reference in New Issue
Block a user