Skip to content

Commit 07f1948

Browse files
committed
Implement Idx for OwnerId.
1 parent 024207a commit 07f1948

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

compiler/rustc_hir/src/hir_id.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
1+
use crate::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_ID};
22
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
33
use rustc_span::{def_id::DefPathHash, HashStableContext};
44
use std::fmt;
@@ -22,6 +22,18 @@ impl OwnerId {
2222
}
2323
}
2424

25+
impl rustc_index::vec::Idx for OwnerId {
26+
#[inline]
27+
fn new(idx: usize) -> Self {
28+
OwnerId { def_id: LocalDefId { local_def_index: DefIndex::from_usize(idx) } }
29+
}
30+
31+
#[inline]
32+
fn index(self) -> usize {
33+
self.def_id.local_def_index.as_usize()
34+
}
35+
}
36+
2537
impl<CTX: HashStableContext> HashStable<CTX> for OwnerId {
2638
#[inline]
2739
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {

compiler/rustc_index/src/vec.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ pub trait Idx: Copy + 'static + Eq + PartialEq + Debug + Hash {
1717

1818
fn index(self) -> usize;
1919

20+
#[inline]
2021
fn increment_by(&mut self, amount: usize) {
2122
*self = self.plus(amount);
2223
}
2324

25+
#[inline]
2426
fn plus(self, amount: usize) -> Self {
2527
Self::new(self.index() + amount)
2628
}

0 commit comments

Comments
 (0)