[][src]Struct ra_ap_hir_ty::DebruijnIndex

pub struct DebruijnIndex { /* fields omitted */ }

References the binder at the given depth. The index is a de Bruijn index, so it counts back through the in-scope binders, with 0 being the innermost binder. This is used in impls and the like. For example, if we had a rule like for<T> { (T: Clone) :- (T: Copy) }, then T would be represented as a BoundVar(0) (as the for is the innermost binder).

Implementations

impl DebruijnIndex[src]

pub const INNERMOST: DebruijnIndex[src]

Innermost index.

pub const ONE: DebruijnIndex[src]

One level higher than the innermost index.

pub fn new(depth: u32) -> DebruijnIndex[src]

Creates a new de Bruijn index with a given depth.

pub fn depth(self) -> u32[src]

Depth of the De Bruijn index, counting from 0 starting with the innermost binder.

pub fn within(self, outer_binder: DebruijnIndex) -> bool[src]

True if the binder identified by this index is within the binder identified by the index outer_binder.

Example

Imagine you have the following binders in scope

This example is not tested
forall<a> forall<b> forall<c>

then the Debruijn index for c would be 0, the index for b would be 1, and so on. Now consider the following calls:

  • c.within(a) = true
  • b.within(a) = true
  • a.within(a) = false
  • a.within(c) = false

#[must_use]pub fn shifted_in(self) -> DebruijnIndex[src]

Returns the resulting index when this value is moved into through one binder.

pub fn shift_in(&mut self)[src]

Update this index in place by shifting it "in" through amount number of binders.

#[must_use]pub fn shifted_in_from(self, outer_binder: DebruijnIndex) -> DebruijnIndex[src]

Adds outer_binder levels to the self index. Intuitively, this shifts the self index, which was valid at the outer binder, so that it is valid at the innermost binder.

Example: Assume that the following binders are in scope:

This example is not tested
for<A> for<B> for<C> for<D>
           ^ outer binder

Assume further that the outer_binder argument is 2, which means that it is referring to the for<B> binder (since D would be the innermost binder).

This means that self is relative to the binder B -- so if self is 0 (INNERMOST), then it refers to B, and if self is 1, then it refers to A.

We will return as follows:

  • 0.shifted_in_from(2) = 2 -- i.e., B, when shifted in to the binding level D, has index 2
  • 1.shifted_in_from(2) = 3 -- i.e., A, when shifted in to the binding level D, has index 3
  • 2.shifted_in_from(1) = 3 -- here, we changed the outer_binder to refer to C. Therefore 2 (relative to C) refers to A, so the result is still 3 (since A, relative to the innermost binder, has index 3).

#[must_use]pub fn shifted_out(self) -> Option<DebruijnIndex>[src]

Returns the resulting index when this value is moved out from amount number of new binders.

pub fn shift_out(&mut self)[src]

Update in place by shifting out from amount binders.

pub fn shifted_out_to(
    self,
    outer_binder: DebruijnIndex
) -> Option<DebruijnIndex>
[src]

Subtracts outer_binder levels from the self index. Intuitively, this shifts the self index, which was valid at the innermost binder, to one that is valid at the binder outer_binder.

This will return None if the self index is internal to the outer binder (i.e., if self < outer_binder).

Example: Assume that the following binders are in scope:

This example is not tested
for<A> for<B> for<C> for<D>
           ^ outer binder

Assume further that the outer_binder argument is 2, which means that it is referring to the for<B> binder (since D would be the innermost binder).

This means that the result is relative to the binder B -- so if self is 0 (INNERMOST), then it refers to B, and if self is 1, then it refers to A.

We will return as follows:

  • 1.shifted_out_to(2) = None -- i.e., the binder for C can't be named from the binding level B
  • 3.shifted_out_to(2) = Some(1) -- i.e., A, when shifted out to the binding level B, has index 1

Trait Implementations

impl Clone for DebruijnIndex[src]

impl Copy for DebruijnIndex[src]

impl Debug for DebruijnIndex[src]

impl Eq for DebruijnIndex[src]

impl<I, TI> Fold<I, TI> for DebruijnIndex where
    I: Interner,
    TI: TargetInterner<I>, 
[src]

type Result = DebruijnIndex

The type of value that will be produced once folding is done. Typically this is Self, unless Self contains borrowed values, in which case owned values are produced (for example, one can fold over a &T value where T: Fold, in which case you get back a T, not a &T). Read more

impl Hash for DebruijnIndex[src]

impl Ord for DebruijnIndex[src]

impl PartialEq<DebruijnIndex> for DebruijnIndex[src]

impl PartialOrd<DebruijnIndex> for DebruijnIndex[src]

impl<I> Visit<I> for DebruijnIndex where
    I: Interner
[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Cast for T[src]

impl<T> CloneAny for T where
    T: Clone + Any

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<N> NodeTrait for N where
    N: Copy + Ord + Hash
[src]

impl<T, I> Shift<I> for T where
    I: Interner,
    T: Fold<I, I>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T, I> VisitExt<I> for T where
    I: Interner,
    T: Visit<I>, 
[src]