]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_hir/src/hir_id.rs
Rollup merge of #104792 - notriddle:notriddle/crate-search-title-display, r=Guillaume...
[rust.git] / compiler / rustc_hir / src / hir_id.rs
index 752f760ea9719395fcf8982ea0600b8f45aa2fc4..33f02a115ef38639019453ff23630ed239863ef3 100644 (file)
@@ -1,4 +1,4 @@
-use crate::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
+use crate::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_ID};
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
 use rustc_span::{def_id::DefPathHash, HashStableContext};
 use std::fmt;
@@ -22,6 +22,18 @@ pub fn to_def_id(self) -> DefId {
     }
 }
 
+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) {