Struct rustc::ty::DebruijnIndex [] [src]

pub struct DebruijnIndex {
    pub depth: u32,
}
🔬 This is a nightly-only experimental API. (rustc_private)

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)

Methods

impl DebruijnIndex
[src]

🔬 This is a nightly-only experimental API. (rustc_private)

🔬 This is a nightly-only experimental API. (rustc_private)

Trait Implementations

impl Clone for DebruijnIndex
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for DebruijnIndex
[src]

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

This method tests for !=.

impl Eq for DebruijnIndex
[src]

impl Hash for DebruijnIndex
[src]

Feeds this value into the state given, updating the hasher as necessary.

Feeds a slice of this type into the state provided.

impl Encodable for DebruijnIndex
[src]

🔬 This is a nightly-only experimental API. (rustc_private)

deprecated in favor of rustc-serialize on crates.io

impl Decodable for DebruijnIndex
[src]

🔬 This is a nightly-only experimental API. (rustc_private)

deprecated in favor of rustc-serialize on crates.io

impl Debug for DebruijnIndex
[src]

Formats the value using the given formatter.

impl Copy for DebruijnIndex
[src]