Struct rustc::middle::ty::DebruijnIndexUnstable [-] [+] [src]

pub struct DebruijnIndex {
    pub depth: u32,
}
[-]

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 int, &'a int), &'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 int 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 int) 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

Methods

impl DebruijnIndex

fn new(depth: u32) -> DebruijnIndex

fn shifted(&self, amount: u32) -> DebruijnIndex

Trait Implementations

Derived Implementations

impl Copy for DebruijnIndex

impl Debug for DebruijnIndex

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl Decodable for DebruijnIndex

fn decode<__D: Decoder>(__arg_0: &mut __D) -> Result<DebruijnIndex, Error>

impl Encodable for DebruijnIndex

fn encode<__S: Encoder>(&self, __arg_0: &mut __S) -> Result<(), Error>

impl Hash for DebruijnIndex

fn hash<__H: Hasher>(&self, __arg_0: &mut __H)

fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher

impl Eq for DebruijnIndex

fn assert_receiver_is_total_eq(&self)

impl PartialEq for DebruijnIndex

fn eq(&self, __arg_0: &DebruijnIndex) -> bool

fn ne(&self, __arg_0: &DebruijnIndex) -> bool

impl Clone for DebruijnIndex

fn clone(&self) -> DebruijnIndex

fn clone_from(&mut self, source: &Self)