Implement Idx for OwnerId.
This commit is contained in:
parent
024207ab43
commit
07f1948043
@ -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) {
|
||||
|
@ -17,10 +17,12 @@ pub trait Idx: Copy + 'static + Eq + PartialEq + Debug + Hash {
|
||||
|
||||
fn index(self) -> usize;
|
||||
|
||||
#[inline]
|
||||
fn increment_by(&mut self, amount: usize) {
|
||||
*self = self.plus(amount);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn plus(self, amount: usize) -> Self {
|
||||
Self::new(self.index() + amount)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user