[−][src]Struct rustc_middle::ty::sty::DebruijnIndex
A De Bruijn index is a standard means of representing regions (and perhaps later types) in a higher-ranked setting. In particular, imagine a type like this:
for<'a> fn(for<'b> fn(&'b isize, &'a isize), &'a char) ^ ^ | | | | | | | | | +------------+ 0 | | | | | +----------------------------------+ 1 | | | +----------------------------------------------+ 0
In this type, there are two binders (the outer fn and the inner fn). We need to be able to determine, for any given region, which fn type it is bound by, the inner or the outer one. There are various ways you can do this, but a De Bruijn index is one of the more convenient and has some nice properties. The basic idea is to count the number of binders, inside out. Some examples should help clarify what I mean.
Let's start with the reference type &'b isize that is the first
argument to the inner function. This region 'b is assigned a De
Bruijn index of 0, meaning "the innermost binder" (in this case, a
fn). The region 'a that appears in the second argument type (&'a isize) would then be assigned a De Bruijn index of 1, meaning "the
second-innermost binder". (These indices are written on the arrays
in the diagram).
What is interesting is that De Bruijn index attached to a particular
variable will vary depending on where it appears. For example,
the final type &'a char also refers to the region 'a declared on
the outermost fn. But this time, this reference is not nested within
any other binders (i.e., it is not an argument to the inner fn, but
rather the outer one). Therefore, in this case, it is assigned a
De Bruijn index of 0, because the innermost binder in that location
is the outer fn.
Fields
private: u32Implementations
impl DebruijnIndex[src]
pub const MAX_AS_U32: u32[src]
pub const MAX: Self[src]
pub const fn from_usize(value: usize) -> Self[src]
pub const fn from_u32(value: u32) -> Self[src]
pub const unsafe fn from_u32_unchecked(value: u32) -> Self[src]
pub const fn index(self) -> usize[src]
Extracts the value of this index as an integer.
pub const fn as_u32(self) -> u32[src]
Extracts the value of this index as a u32.
pub const fn as_usize(self) -> usize[src]
Extracts the value of this index as a usize.
impl DebruijnIndex[src]
#[must_use]pub fn shifted_in(self, amount: u32) -> DebruijnIndex[src]
Returns the resulting index when this value is moved into
amount number of new binders. So, e.g., if you had
for<'a> fn(&'a x)
and you wanted to change it to
for<'a> fn(for<'b> fn(&'a x))
you would need to shift the index for 'a into a new binder.
pub fn shift_in(&mut self, amount: u32)[src]
Update this index in place by shifting it "in" through
amount number of binders.
#[must_use]pub fn shifted_out(self, amount: u32) -> DebruijnIndex[src]
Returns the resulting index when this value is moved out from
amount number of new binders.
pub fn shift_out(&mut self, amount: u32)[src]
Update in place by shifting out from amount binders.
pub fn shifted_out_to_binder(self, to_binder: DebruijnIndex) -> Self[src]
Adjusts any De Bruijn indices so as to make to_binder the
innermost binder. That is, if we have something bound at to_binder,
it will now be bound at INNERMOST. This is an appropriate thing to do
when moving a region out from inside binders:
for<'a> fn(for<'b> for<'c> fn(&'a u32), _)
// Binder: D3 D2 D1 ^^Here, the region 'a would have the De Bruijn index D3,
because it is the bound 3 binders out. However, if we wanted
to refer to that region 'a in the second argument (the _),
those two binders would not be in scope. In that case, we
might invoke shift_out_to_binder(D3). This would adjust the
De Bruijn index of 'a to D1 (the innermost binder).
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).
Trait Implementations
impl Add<usize> for DebruijnIndex[src]
type Output = Self
The resulting type after applying the + operator.
pub fn add(self, other: usize) -> Self[src]
impl Clone for DebruijnIndex[src]
pub fn clone(&self) -> Self[src]
pub fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Copy for DebruijnIndex[src]
impl Debug for DebruijnIndex[src]
impl<D: Decoder> Decodable<D> for DebruijnIndex[src]
impl<E: Encoder> Encodable<E> for DebruijnIndex[src]
impl Eq for DebruijnIndex[src]
impl From<DebruijnIndex> for u32[src]
pub fn from(v: DebruijnIndex) -> u32[src]
impl From<DebruijnIndex> for usize[src]
pub fn from(v: DebruijnIndex) -> usize[src]
impl From<u32> for DebruijnIndex[src]
impl From<usize> for DebruijnIndex[src]
impl Hash for DebruijnIndex[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
impl<'__ctx> HashStable<StableHashingContext<'__ctx>> for DebruijnIndex[src]
pub fn hash_stable(
&self,
__hcx: &mut StableHashingContext<'__ctx>,
__hasher: &mut StableHasher
)[src]
&self,
__hcx: &mut StableHashingContext<'__ctx>,
__hasher: &mut StableHasher
)
impl Idx for DebruijnIndex[src]
pub fn new(value: usize) -> Self[src]
pub fn index(self) -> usize[src]
pub fn increment_by(&mut self, amount: usize)[src]
pub fn plus(self, amount: usize) -> Self[src]
impl Ord for DebruijnIndex[src]
pub fn cmp(&self, other: &DebruijnIndex) -> Ordering[src]
#[must_use]pub fn max(self, other: Self) -> Self1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self[src]
impl PartialEq<DebruijnIndex> for DebruijnIndex[src]
pub fn eq(&self, other: &DebruijnIndex) -> bool[src]
pub fn ne(&self, other: &DebruijnIndex) -> bool[src]
impl PartialOrd<DebruijnIndex> for DebruijnIndex[src]
pub fn partial_cmp(&self, other: &DebruijnIndex) -> Option<Ordering>[src]
pub fn lt(&self, other: &DebruijnIndex) -> bool[src]
pub fn le(&self, other: &DebruijnIndex) -> bool[src]
pub fn gt(&self, other: &DebruijnIndex) -> bool[src]
pub fn ge(&self, other: &DebruijnIndex) -> bool[src]
impl Step for DebruijnIndex[src]
pub fn steps_between(start: &Self, end: &Self) -> Option<usize>[src]
pub fn forward_checked(start: Self, u: usize) -> Option<Self>[src]
pub fn backward_checked(start: Self, u: usize) -> Option<Self>[src]
pub fn forward(start: Self, count: usize) -> Self[src]
pub unsafe fn forward_unchecked(start: Self, count: usize) -> Self[src]
pub fn backward(start: Self, count: usize) -> Self[src]
pub unsafe fn backward_unchecked(start: Self, count: usize) -> Self[src]
impl StructuralEq for DebruijnIndex[src]
impl StructuralPartialEq for DebruijnIndex[src]
Auto Trait Implementations
impl RefUnwindSafe for DebruijnIndex
impl Send for DebruijnIndex
impl Sync for DebruijnIndex
impl Unpin for DebruijnIndex
impl UnwindSafe for DebruijnIndex
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<'tcx, T> ArenaAllocatable<'tcx, ()> for T where
T: Copy, [src]
T: Copy,
pub fn allocate_on(Self, &'a Arena<'tcx>) -> &'a mut T[src]
pub fn allocate_from_iter(
&'a Arena<'tcx>,
impl IntoIterator<Item = T>
) -> &'a mut [T][src]
&'a Arena<'tcx>,
impl IntoIterator<Item = T>
) -> &'a mut [T]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<'a, T> Captures<'a> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> MaybeResult<T> for T[src]
type Error = !
pub fn from(Result<T, <T as MaybeResult<T>>::Error>) -> T[src]
pub fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>[src]
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.