1#![allow(internal_features)]
4#![feature(negative_impls)]
5#![feature(rustc_attrs)]
6
7use std::fmt::{self, Debug};
8
9use rustc_data_structures::stable_hasher::{
10 StableHash, StableHashCtxt, StableHasher, StableOrd, ToStableHashKey,
11};
12use rustc_macros::{Decodable, Encodable, StableHash};
13use rustc_span::def_id::{CRATE_DEF_ID, DefId, DefIndex, DefPathHash, LocalDefId};
14
15#[derive(#[automatically_derived]
impl ::core::marker::Copy for OwnerId { }Copy, #[automatically_derived]
impl ::core::clone::Clone for OwnerId {
#[inline]
fn clone(&self) -> OwnerId {
let _: ::core::clone::AssertParamIsClone<LocalDefId>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for OwnerId {
#[inline]
fn eq(&self, other: &OwnerId) -> bool { self.def_id == other.def_id }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for OwnerId {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<LocalDefId>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for OwnerId {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.def_id, state)
}
}Hash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for OwnerId {
fn encode(&self, __encoder: &mut __E) {
match *self {
OwnerId { def_id: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for OwnerId {
fn decode(__decoder: &mut __D) -> Self {
OwnerId {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable)]
16pub struct OwnerId {
17 pub def_id: LocalDefId,
18}
19
20impl Debug for OwnerId {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 Debug::fmt(&self.def_id, f)
24 }
25}
26
27impl From<OwnerId> for HirId {
28 fn from(owner: OwnerId) -> HirId {
29 HirId { owner, local_id: ItemLocalId::ZERO }
30 }
31}
32
33impl From<OwnerId> for DefId {
34 fn from(value: OwnerId) -> Self {
35 value.to_def_id()
36 }
37}
38
39impl OwnerId {
40 #[inline]
41 pub fn to_def_id(self) -> DefId {
42 self.def_id.to_def_id()
43 }
44}
45
46impl rustc_index::Idx for OwnerId {
47 #[inline]
48 fn new(idx: usize) -> Self {
49 OwnerId { def_id: LocalDefId { local_def_index: DefIndex::from_usize(idx) } }
50 }
51
52 #[inline]
53 fn index(self) -> usize {
54 self.def_id.local_def_index.as_usize()
55 }
56}
57
58impl StableHash for OwnerId {
59 #[inline]
60 fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
61 self.to_stable_hash_key(hcx).stable_hash(hcx, hasher);
62 }
63}
64
65impl ToStableHashKey for OwnerId {
66 type KeyType = DefPathHash;
67
68 #[inline]
69 fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> DefPathHash {
70 self.to_def_id().to_stable_hash_key(hcx)
71 }
72}
73
74#[derive(#[automatically_derived]
impl ::core::marker::Copy for HirId { }Copy, #[automatically_derived]
impl ::core::clone::Clone for HirId {
#[inline]
fn clone(&self) -> HirId {
let _: ::core::clone::AssertParamIsClone<OwnerId>;
let _: ::core::clone::AssertParamIsClone<ItemLocalId>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for HirId {
#[inline]
fn eq(&self, other: &HirId) -> bool {
self.owner == other.owner && self.local_id == other.local_id
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for HirId {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<OwnerId>;
let _: ::core::cmp::AssertParamIsEq<ItemLocalId>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for HirId {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.owner, state);
::core::hash::Hash::hash(&self.local_id, state)
}
}Hash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for HirId {
fn encode(&self, __encoder: &mut __E) {
match *self {
HirId { owner: ref __binding_0, local_id: ref __binding_1 }
=> {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for HirId {
fn decode(__decoder: &mut __D) -> Self {
HirId {
owner: ::rustc_serialize::Decodable::decode(__decoder),
local_id: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable, const _: () =
{
impl ::rustc_data_structures::stable_hasher::StableHash for HirId {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hasher::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
HirId { owner: ref __binding_0, local_id: ref __binding_1 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
85#[rustc_pass_by_value]
86pub struct HirId {
87 pub owner: OwnerId,
88 pub local_id: ItemLocalId,
89}
90
91impl !Ord for HirId {}
95impl !PartialOrd for HirId {}
96
97impl Debug for HirId {
98 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
99 f.write_fmt(format_args!("HirId({0:?}.{1:?})", self.owner, self.local_id))write!(f, "HirId({:?}.{:?})", self.owner, self.local_id)
102 }
103}
104
105impl HirId {
106 pub const INVALID: HirId =
108 HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::INVALID };
109
110 #[inline]
111 pub fn expect_owner(self) -> OwnerId {
112 match (&self.local_id.index(), &0) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(self.local_id.index(), 0);
113 self.owner
114 }
115
116 #[inline]
117 pub fn as_owner(self) -> Option<OwnerId> {
118 if self.local_id.index() == 0 { Some(self.owner) } else { None }
119 }
120
121 #[inline]
122 pub fn is_owner(self) -> bool {
123 self.local_id.index() == 0
124 }
125
126 #[inline]
127 pub fn make_owner(owner: LocalDefId) -> Self {
128 Self { owner: OwnerId { def_id: owner }, local_id: ItemLocalId::ZERO }
129 }
130}
131
132impl fmt::Display for HirId {
133 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
134 f.write_fmt(format_args!("{0:?}", self))write!(f, "{self:?}")
135 }
136}
137
138pub type HirIdMap<T> = ::rustc_data_structures::fx::FxIndexMap<HirId, T>;
pub type HirIdSet = ::rustc_data_structures::fx::FxIndexSet<HirId>;
pub type HirIdMapEntry<'a, T> =
::rustc_data_structures::fx::IndexEntry<'a, HirId, T>;rustc_data_structures::define_stable_id_collections!(HirIdMap, HirIdSet, HirIdMapEntry, HirId);
139pub type ItemLocalMap<T> =
::rustc_data_structures::unord::UnordMap<ItemLocalId, T>;
pub type ItemLocalSet = ::rustc_data_structures::unord::UnordSet<ItemLocalId>;
pub type ItemLocalMapEntry<'a, T> =
::rustc_data_structures::fx::StdEntry<'a, ItemLocalId, T>;rustc_data_structures::define_id_collections!(
140 ItemLocalMap,
141 ItemLocalSet,
142 ItemLocalMapEntry,
143 ItemLocalId
144);
145
146impl ::std::fmt::Debug for ItemLocalId {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
fmt.write_fmt(format_args!("{0}", self.as_u32()))
}
}rustc_index::newtype_index! {
147 #[stable_hash]
156 #[encodable]
157 #[orderable]
158 pub struct ItemLocalId {}
159}
160
161impl ItemLocalId {
162 pub const INVALID: ItemLocalId = ItemLocalId::MAX;
164}
165
166impl StableOrd for ItemLocalId {
167 const CAN_USE_UNSTABLE_SORT: bool = true;
168
169 const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
172}
173
174pub const CRATE_HIR_ID: HirId =
176 HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::ZERO };
177
178pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID };
179
180impl ToStableHashKey for HirId {
181 type KeyType = (DefPathHash, ItemLocalId);
182
183 #[inline]
184 fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> (DefPathHash, ItemLocalId) {
185 let def_path_hash = self.owner.def_id.to_stable_hash_key(hcx);
186 (def_path_hash, self.local_id)
187 }
188}
189
190impl ToStableHashKey for ItemLocalId {
191 type KeyType = ItemLocalId;
192
193 #[inline]
194 fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> ItemLocalId {
195 *self
196 }
197}