Struct ra_ap_hir_ty::DebruijnIndex [−][src]
pub struct DebruijnIndex { /* fields omitted */ }
Expand description
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
Innermost index.
One level higher than the innermost index.
Creates a new de Bruijn index with a given depth.
Depth of the De Bruijn index, counting from 0 starting with the innermost binder.
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
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
Returns the resulting index when this value is moved into through one binder.
Update this index in place by shifting it “in” through
amount
number of binders.
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:
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 levelD
, has index 21.shifted_in_from(2) = 3
– i.e.,A
, when shifted in to the binding levelD
, has index 32.shifted_in_from(1) = 3
– here, we changed theouter_binder
to refer toC
. Therefore2
(relative toC
) refers toA
, so the result is still 3 (sinceA
, relative to the innermost binder, has index 3).
Returns the resulting index when this value is moved out from
amount
number of new binders.
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:
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 forC
can’t be named from the binding levelB
3.shifted_out_to(2) = Some(1)
– i.e.,A
, when shifted out to the binding levelB
, has index 1
Trait Implementations
type Result = DebruijnIndex
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
pub fn fold_with<'i>(
self,
_folder: &mut dyn Folder<'i, I>,
_outer_binder: DebruijnIndex
) -> Result<<DebruijnIndex as Fold<I>>::Result, NoSolution> where
I: 'i,
pub fn fold_with<'i>(
self,
_folder: &mut dyn Folder<'i, I>,
_outer_binder: DebruijnIndex
) -> Result<<DebruijnIndex as Fold<I>>::Result, NoSolution> where
I: 'i,
Apply the given folder folder
to self
; binders
is the
number of binders that are in scope when beginning the
folder. Typically binders
starts as 0, but is adjusted when
we encounter Binders<T>
in the IR or other similar
constructs. Read more
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
pub fn visit_with<'i, B>(
&self,
_visitor: &mut dyn Visitor<'i, I, BreakTy = B>,
_outer_binder: DebruijnIndex
) -> ControlFlow<B, ()> where
I: 'i,
pub fn visit_with<'i, B>(
&self,
_visitor: &mut dyn Visitor<'i, I, BreakTy = B>,
_outer_binder: DebruijnIndex
) -> ControlFlow<B, ()> where
I: 'i,
Apply the given visitor visitor
to self
; binders
is the
number of binders that are in scope when beginning the
visitor. Typically binders
starts as 0, but is adjusted when
we encounter Binders<T>
in the IR or other similar
constructs. Read more
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
Mutably borrows from an owned value. Read more
fn cast<U>(self, interner: &<U as HasInterner>::Interner) -> U where
Self: CastTo<U>,
U: HasInterner,
fn cast<U>(self, interner: &<U as HasInterner>::Interner) -> U where
Self: CastTo<U>,
U: HasInterner,
Cast a value to type U
using CastTo
.
Compare self to key
and return true
if they are equal.
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Shifts this term in one level of binders.
pub fn shifted_in_from(
self,
interner: &I,
source_binder: DebruijnIndex
) -> <T as Fold<I>>::Result
pub fn shifted_in_from(
self,
interner: &I,
source_binder: DebruijnIndex
) -> <T as Fold<I>>::Result
Shifts a term valid at outer_binder
so that it is
valid at the innermost binder. See DebruijnIndex::shifted_in_from
for a detailed explanation. Read more
pub fn shifted_out_to(
self,
interner: &I,
target_binder: DebruijnIndex
) -> Result<<T as Fold<I>>::Result, NoSolution>
pub fn shifted_out_to(
self,
interner: &I,
target_binder: DebruijnIndex
) -> Result<<T as Fold<I>>::Result, NoSolution>
Shifts a term valid at the innermost binder so that it is
valid at outer_binder
. See DebruijnIndex::shifted_out_to
for a detailed explanation. Read more
Shifts this term out one level of binders.
Check whether there are free (non-bound) variables.
impl<T> Any for T where
T: Any,