Skip to content

Commit

Permalink
Inline DebruijnIndex methods
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSeulArtichaut committed Dec 15, 2020
1 parent 99baddb commit 2208f5e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_type_ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,28 @@ impl DebruijnIndex {
///
/// you would need to shift the index for `'a` into a new binder.
#[must_use]
#[inline]
pub fn shifted_in(self, amount: u32) -> DebruijnIndex {
DebruijnIndex::from_u32(self.as_u32() + amount)
}

/// Update this index in place by shifting it "in" through
/// `amount` number of binders.
#[inline]
pub fn shift_in(&mut self, amount: u32) {
*self = self.shifted_in(amount);
}

/// Returns the resulting index when this value is moved out from
/// `amount` number of new binders.
#[must_use]
#[inline]
pub fn shifted_out(self, amount: u32) -> DebruijnIndex {
DebruijnIndex::from_u32(self.as_u32() - amount)
}

/// Update in place by shifting out from `amount` binders.
#[inline]
pub fn shift_out(&mut self, amount: u32) {
*self = self.shifted_out(amount);
}
Expand All @@ -192,6 +196,7 @@ impl DebruijnIndex {
/// If we invoke `shift_out_to_binder` and the region is in fact
/// bound by one of the binders we are shifting out of, that is an
/// error (and should fail an assertion failure).
#[inline]
pub fn shifted_out_to_binder(self, to_binder: DebruijnIndex) -> Self {
self.shifted_out(to_binder.as_u32() - INNERMOST.as_u32())
}
Expand Down

0 comments on commit 2208f5e

Please sign in to comment.