Struct rustc_middle::ty::subst::SubstFolder[][src]

struct SubstFolder<'a, 'tcx> {
    tcx: TyCtxt<'tcx>,
    substs: &'a [GenericArg<'tcx>],
    span: Option<Span>,
    binders_passed: u32,


tcx: TyCtxt<'tcx>substs: &'a [GenericArg<'tcx>]span: Option<Span>

The location for which the substitution is performed, if available.

binders_passed: u32

Number of region binders we have passed through while doing the substitution


It is sometimes necessary to adjust the De Bruijn indices during substitution. This occurs when we are substituting a type with escaping bound vars into a context where we have passed through binders. That’s quite a mouthful. Let’s see an example:

type Func<A> = fn(A);
type MetaFunc = for<'a> fn(Func<&'a i32>)

The type MetaFunc, when fully expanded, will be

for<'a> fn(fn(&'a i32))
        ^~ ^~ ^~~
        |  |  |
        |  |  DebruijnIndex of 2

Here the 'a lifetime is bound in the outer function, but appears as an argument of the inner one. Therefore, that appearance will have a DebruijnIndex of 2, because we must skip over the inner binder (remember that we count De Bruijn indices from 1). However, in the definition of MetaFunc, the binder is not visible, so the type &'a i32 will have a De Bruijn index of 1. It’s only during the substitution that we can see we must increase the depth by 1 to account for the binder that we passed through.

As a second example, consider this twist:

type FuncTuple<A> = (A,fn(A));
type MetaFuncTuple = for<'a> fn(FuncTuple<&'a i32>)

Here the final type will be:

for<'a> fn((&'a i32, fn(&'a i32)))
            ^~~         ^~~
            |           |
     DebruijnIndex of 1 |
                 DebruijnIndex of 2

As indicated in the diagram, here the same type &'a i32 is substituted once, but in the first case we do not increase the De Bruijn index and in the second case we do. The reason is that only in the second case have we passed through a fn binder.

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.


Note: Most layout information is completely unstable and may be different between compiler versions and platforms. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 40 bytes