[][src]Struct rustc_middle::ty::DebruijnIndex

pub struct DebruijnIndex {
    private: u32,

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.


private: u32


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.

impl Clone for DebruijnIndex[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]

impl From<DebruijnIndex> for usize[src]

impl From<u32> for DebruijnIndex[src]

impl From<usize> for DebruijnIndex[src]

impl Hash for DebruijnIndex[src]

impl<'__ctx> HashStable<StableHashingContext<'__ctx>> for DebruijnIndex[src]

impl Idx for DebruijnIndex[src]

impl Ord for DebruijnIndex[src]

impl PartialEq<DebruijnIndex> for DebruijnIndex[src]

impl PartialOrd<DebruijnIndex> for DebruijnIndex[src]

impl Step for DebruijnIndex[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

impl<'tcx, T> ArenaAllocatable<'tcx, ()> for T where
    T: Copy

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<'a, T> Captures<'a> for T where
    T: ?Sized

impl<Ctxt, T> DepNodeParams<Ctxt> for T where
    Ctxt: DepContext,
    T: HashStable<<Ctxt as DepContext>::StableHashingContext> + Debug

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> MaybeResult<T> for T[src]

type Error = !

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> WithConstness for T[src]