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

🔬 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]

[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?

[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]

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

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl PartialEq for DebruijnIndex
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Eq for DebruijnIndex
[src]

impl Hash for DebruijnIndex
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Encodable for DebruijnIndex
[src]

[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]

[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]

[src]

Formats the value using the given formatter.

impl Copy for DebruijnIndex
[src]