summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_hir/src/hir_id.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_hir/src/hir_id.rs')
-rw-r--r--compiler/rustc_hir/src/hir_id.rs22
1 files changed, 19 insertions, 3 deletions
diff --git a/compiler/rustc_hir/src/hir_id.rs b/compiler/rustc_hir/src/hir_id.rs
index 752f760ea..060f40919 100644
--- a/compiler/rustc_hir/src/hir_id.rs
+++ b/compiler/rustc_hir/src/hir_id.rs
@@ -1,5 +1,5 @@
-use crate::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
+use crate::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_ID};
+use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey};
use rustc_span::{def_id::DefPathHash, HashStableContext};
use std::fmt;
@@ -22,6 +22,18 @@ impl OwnerId {
}
}
+impl rustc_index::vec::Idx for OwnerId {
+ #[inline]
+ fn new(idx: usize) -> Self {
+ OwnerId { def_id: LocalDefId { local_def_index: DefIndex::from_usize(idx) } }
+ }
+
+ #[inline]
+ fn index(self) -> usize {
+ self.def_id.local_def_index.as_usize()
+ }
+}
+
impl<CTX: HashStableContext> HashStable<CTX> for OwnerId {
#[inline]
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
@@ -104,7 +116,7 @@ impl Ord for HirId {
impl PartialOrd for HirId {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
- Some(self.cmp(&other))
+ Some(self.cmp(other))
}
}
@@ -134,6 +146,10 @@ impl ItemLocalId {
pub const INVALID: ItemLocalId = ItemLocalId::MAX;
}
+// Safety: Ord is implement as just comparing the LocalItemId's numerical
+// values and these are not changed by (de-)serialization.
+unsafe impl StableOrd for ItemLocalId {}
+
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`.
pub const CRATE_HIR_ID: HirId =
HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::from_u32(0) };