Struct rustc::ty::DebruijnIndex
[−]
[src]
pub struct DebruijnIndex { pub depth: u32, }
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
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) ^ ^ | | | | | | | | | +------------+ 1 | | | | | +--------------------------------+ 2 | | | +------------------------------------------+ 1
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 1, 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 2, 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 1, because the innermost binder in that location
is the outer fn.
Fields
depth: u32
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
We maintain the invariant that this is never 0. So 1 indicates
the innermost binder. To ensure this, create with DebruijnIndex::new
.
Methods
impl DebruijnIndex
[src]
pub fn new(depth: u32) -> DebruijnIndex
[src]
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
pub fn shifted(&self, amount: u32) -> DebruijnIndex
[src]
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
Trait Implementations
impl<'tcx> HashStable<StableHashingContext<'tcx>> for DebruijnIndex
[src]
fn hash_stable<W: StableHasherResult>(
&self,
__ctx: &mut StableHashingContext<'tcx>,
__hasher: &mut StableHasher<W>
)
[src]
&self,
__ctx: &mut StableHashingContext<'tcx>,
__hasher: &mut StableHasher<W>
)
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
impl Clone for DebruijnIndex
[src]
fn clone(&self) -> DebruijnIndex
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl PartialEq for DebruijnIndex
[src]
fn eq(&self, __arg_0: &DebruijnIndex) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &DebruijnIndex) -> bool
[src]
This method tests for !=
.
impl Eq for DebruijnIndex
[src]
impl Hash for DebruijnIndex
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Encodable for DebruijnIndex
[src]
fn encode<__S: Encoder>(&self, __arg_0: &mut __S) -> Result<(), __S::Error>
[src]
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
impl Decodable for DebruijnIndex
[src]
fn decode<__D: Decoder>(__arg_0: &mut __D) -> Result<DebruijnIndex, __D::Error>
[src]
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
impl Debug for DebruijnIndex
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Copy for DebruijnIndex
[src]
impl PartialOrd for DebruijnIndex
[src]
fn partial_cmp(&self, __arg_0: &DebruijnIndex) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &DebruijnIndex) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &DebruijnIndex) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &DebruijnIndex) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &DebruijnIndex) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for DebruijnIndex
[src]
fn cmp(&self, __arg_0: &DebruijnIndex) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more