separate definitions and HIR
owners
fix a ui test use `into` fix clippy ui test fix a run-make-fulldeps test implement `IntoQueryParam<DefId>` for `OwnerId` use `OwnerId` for more queries change the type of `ParentOwnerIterator::Item` to `(OwnerId, OwnerNode)`
This commit is contained in:
parent
bb5a016175
commit
8fe936099a
114 changed files with 659 additions and 518 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::def::{CtorKind, DefKind, Res};
|
||||
use crate::def_id::DefId;
|
||||
pub(crate) use crate::hir_id::{HirId, ItemLocalId};
|
||||
pub(crate) use crate::hir_id::{HirId, ItemLocalId, OwnerId};
|
||||
use crate::intravisit::FnKind;
|
||||
use crate::LangItem;
|
||||
|
||||
|
@ -2206,14 +2206,14 @@ pub struct FnSig<'hir> {
|
|||
// so it can fetched later.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
|
||||
pub struct TraitItemId {
|
||||
pub def_id: LocalDefId,
|
||||
pub def_id: OwnerId,
|
||||
}
|
||||
|
||||
impl TraitItemId {
|
||||
#[inline]
|
||||
pub fn hir_id(&self) -> HirId {
|
||||
// Items are always HIR owners.
|
||||
HirId::make_owner(self.def_id)
|
||||
HirId::make_owner(self.def_id.def_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2224,7 +2224,7 @@ impl TraitItemId {
|
|||
#[derive(Debug, HashStable_Generic)]
|
||||
pub struct TraitItem<'hir> {
|
||||
pub ident: Ident,
|
||||
pub def_id: LocalDefId,
|
||||
pub def_id: OwnerId,
|
||||
pub generics: &'hir Generics<'hir>,
|
||||
pub kind: TraitItemKind<'hir>,
|
||||
pub span: Span,
|
||||
|
@ -2235,7 +2235,7 @@ impl TraitItem<'_> {
|
|||
#[inline]
|
||||
pub fn hir_id(&self) -> HirId {
|
||||
// Items are always HIR owners.
|
||||
HirId::make_owner(self.def_id)
|
||||
HirId::make_owner(self.def_id.def_id)
|
||||
}
|
||||
|
||||
pub fn trait_item_id(&self) -> TraitItemId {
|
||||
|
@ -2270,14 +2270,14 @@ pub enum TraitItemKind<'hir> {
|
|||
// so it can fetched later.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
|
||||
pub struct ImplItemId {
|
||||
pub def_id: LocalDefId,
|
||||
pub def_id: OwnerId,
|
||||
}
|
||||
|
||||
impl ImplItemId {
|
||||
#[inline]
|
||||
pub fn hir_id(&self) -> HirId {
|
||||
// Items are always HIR owners.
|
||||
HirId::make_owner(self.def_id)
|
||||
HirId::make_owner(self.def_id.def_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2285,7 +2285,7 @@ impl ImplItemId {
|
|||
#[derive(Debug, HashStable_Generic)]
|
||||
pub struct ImplItem<'hir> {
|
||||
pub ident: Ident,
|
||||
pub def_id: LocalDefId,
|
||||
pub def_id: OwnerId,
|
||||
pub generics: &'hir Generics<'hir>,
|
||||
pub kind: ImplItemKind<'hir>,
|
||||
pub defaultness: Defaultness,
|
||||
|
@ -2297,7 +2297,7 @@ impl ImplItem<'_> {
|
|||
#[inline]
|
||||
pub fn hir_id(&self) -> HirId {
|
||||
// Items are always HIR owners.
|
||||
HirId::make_owner(self.def_id)
|
||||
HirId::make_owner(self.def_id.def_id)
|
||||
}
|
||||
|
||||
pub fn impl_item_id(&self) -> ImplItemId {
|
||||
|
@ -2888,14 +2888,14 @@ impl<'hir> VariantData<'hir> {
|
|||
// so it can fetched later.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash, HashStable_Generic)]
|
||||
pub struct ItemId {
|
||||
pub def_id: LocalDefId,
|
||||
pub def_id: OwnerId,
|
||||
}
|
||||
|
||||
impl ItemId {
|
||||
#[inline]
|
||||
pub fn hir_id(&self) -> HirId {
|
||||
// Items are always HIR owners.
|
||||
HirId::make_owner(self.def_id)
|
||||
HirId::make_owner(self.def_id.def_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2905,7 +2905,7 @@ impl ItemId {
|
|||
#[derive(Debug, HashStable_Generic)]
|
||||
pub struct Item<'hir> {
|
||||
pub ident: Ident,
|
||||
pub def_id: LocalDefId,
|
||||
pub def_id: OwnerId,
|
||||
pub kind: ItemKind<'hir>,
|
||||
pub span: Span,
|
||||
pub vis_span: Span,
|
||||
|
@ -2915,7 +2915,7 @@ impl Item<'_> {
|
|||
#[inline]
|
||||
pub fn hir_id(&self) -> HirId {
|
||||
// Items are always HIR owners.
|
||||
HirId::make_owner(self.def_id)
|
||||
HirId::make_owner(self.def_id.def_id)
|
||||
}
|
||||
|
||||
pub fn item_id(&self) -> ItemId {
|
||||
|
@ -3132,14 +3132,14 @@ pub enum AssocItemKind {
|
|||
// so it can fetched later.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
|
||||
pub struct ForeignItemId {
|
||||
pub def_id: LocalDefId,
|
||||
pub def_id: OwnerId,
|
||||
}
|
||||
|
||||
impl ForeignItemId {
|
||||
#[inline]
|
||||
pub fn hir_id(&self) -> HirId {
|
||||
// Items are always HIR owners.
|
||||
HirId::make_owner(self.def_id)
|
||||
HirId::make_owner(self.def_id.def_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3160,7 +3160,7 @@ pub struct ForeignItemRef {
|
|||
pub struct ForeignItem<'hir> {
|
||||
pub ident: Ident,
|
||||
pub kind: ForeignItemKind<'hir>,
|
||||
pub def_id: LocalDefId,
|
||||
pub def_id: OwnerId,
|
||||
pub span: Span,
|
||||
pub vis_span: Span,
|
||||
}
|
||||
|
@ -3169,7 +3169,7 @@ impl ForeignItem<'_> {
|
|||
#[inline]
|
||||
pub fn hir_id(&self) -> HirId {
|
||||
// Items are always HIR owners.
|
||||
HirId::make_owner(self.def_id)
|
||||
HirId::make_owner(self.def_id.def_id)
|
||||
}
|
||||
|
||||
pub fn foreign_item_id(&self) -> ForeignItemId {
|
||||
|
@ -3263,7 +3263,7 @@ impl<'hir> OwnerNode<'hir> {
|
|||
Node::generics(self.into())
|
||||
}
|
||||
|
||||
pub fn def_id(self) -> LocalDefId {
|
||||
pub fn def_id(self) -> OwnerId {
|
||||
match self {
|
||||
OwnerNode::Item(Item { def_id, .. })
|
||||
| OwnerNode::TraitItem(TraitItem { def_id, .. })
|
||||
|
|
|
@ -1,6 +1,43 @@
|
|||
use crate::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||
use crate::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
|
||||
use rustc_span::{def_id::DefPathHash, HashStableContext};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
#[derive(Encodable, Decodable)]
|
||||
pub struct OwnerId {
|
||||
pub def_id: LocalDefId,
|
||||
}
|
||||
|
||||
impl From<OwnerId> for HirId {
|
||||
fn from(owner: OwnerId) -> HirId {
|
||||
HirId { owner, local_id: ItemLocalId::from_u32(0) }
|
||||
}
|
||||
}
|
||||
|
||||
impl OwnerId {
|
||||
#[inline]
|
||||
pub fn to_def_id(self) -> DefId {
|
||||
self.def_id.to_def_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX: HashStableContext> HashStable<CTX> for OwnerId {
|
||||
#[inline]
|
||||
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
|
||||
self.to_stable_hash_key(hcx).hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX: HashStableContext> ToStableHashKey<CTX> for OwnerId {
|
||||
type KeyType = DefPathHash;
|
||||
|
||||
#[inline]
|
||||
fn to_stable_hash_key(&self, hcx: &CTX) -> DefPathHash {
|
||||
hcx.def_path_hash(self.to_def_id())
|
||||
}
|
||||
}
|
||||
|
||||
/// Uniquely identifies a node in the HIR of the current crate. It is
|
||||
/// composed of the `owner`, which is the `LocalDefId` of the directly enclosing
|
||||
/// `hir::Item`, `hir::TraitItem`, or `hir::ImplItem` (i.e., the closest "item-like"),
|
||||
|
@ -15,22 +52,23 @@ use std::fmt;
|
|||
#[derive(Encodable, Decodable, HashStable_Generic)]
|
||||
#[rustc_pass_by_value]
|
||||
pub struct HirId {
|
||||
pub owner: LocalDefId,
|
||||
pub owner: OwnerId,
|
||||
pub local_id: ItemLocalId,
|
||||
}
|
||||
|
||||
impl HirId {
|
||||
/// Signal local id which should never be used.
|
||||
pub const INVALID: HirId = HirId { owner: CRATE_DEF_ID, local_id: ItemLocalId::INVALID };
|
||||
pub const INVALID: HirId =
|
||||
HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::INVALID };
|
||||
|
||||
#[inline]
|
||||
pub fn expect_owner(self) -> LocalDefId {
|
||||
pub fn expect_owner(self) -> OwnerId {
|
||||
assert_eq!(self.local_id.index(), 0);
|
||||
self.owner
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_owner(self) -> Option<LocalDefId> {
|
||||
pub fn as_owner(self) -> Option<OwnerId> {
|
||||
if self.local_id.index() == 0 { Some(self.owner) } else { None }
|
||||
}
|
||||
|
||||
|
@ -41,11 +79,14 @@ impl HirId {
|
|||
|
||||
#[inline]
|
||||
pub fn make_owner(owner: LocalDefId) -> Self {
|
||||
Self { owner, local_id: ItemLocalId::from_u32(0) }
|
||||
Self { owner: OwnerId { def_id: owner }, local_id: ItemLocalId::from_u32(0) }
|
||||
}
|
||||
|
||||
pub fn index(self) -> (usize, usize) {
|
||||
(rustc_index::vec::Idx::index(self.owner), rustc_index::vec::Idx::index(self.local_id))
|
||||
(
|
||||
rustc_index::vec::Idx::index(self.owner.def_id),
|
||||
rustc_index::vec::Idx::index(self.local_id),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,4 +135,7 @@ impl ItemLocalId {
|
|||
}
|
||||
|
||||
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`.
|
||||
pub const CRATE_HIR_ID: HirId = HirId { owner: CRATE_DEF_ID, local_id: ItemLocalId::from_u32(0) };
|
||||
pub const CRATE_HIR_ID: HirId =
|
||||
HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::from_u32(0) };
|
||||
|
||||
pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID };
|
||||
|
|
|
@ -20,7 +20,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
|
|||
|
||||
#[inline]
|
||||
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
|
||||
let def_path_hash = self.owner.to_stable_hash_key(hcx);
|
||||
let def_path_hash = self.owner.def_id.to_stable_hash_key(hcx);
|
||||
(def_path_hash, self.local_id)
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemId {
|
|||
|
||||
#[inline]
|
||||
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
|
||||
self.def_id.to_stable_hash_key(hcx)
|
||||
self.def_id.def_id.to_stable_hash_key(hcx)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
|
|||
|
||||
#[inline]
|
||||
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
|
||||
self.def_id.to_stable_hash_key(hcx)
|
||||
self.def_id.def_id.to_stable_hash_key(hcx)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
|
|||
|
||||
#[inline]
|
||||
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
|
||||
self.def_id.to_stable_hash_key(hcx)
|
||||
self.def_id.def_id.to_stable_hash_key(hcx)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId
|
|||
|
||||
#[inline]
|
||||
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
|
||||
self.def_id.to_stable_hash_key(hcx)
|
||||
self.def_id.def_id.to_stable_hash_key(hcx)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue