pub struct TypeRelating<'me, 'tcx, D>where
    D: TypeRelatingDelegate<'tcx>,
{ infcx: &'me InferCtxt<'tcx>, delegate: D, ambient_variance: Variance, ambient_variance_info: VarianceDiagInfo<'tcx>, a_scopes: Vec<BoundRegionScope<'tcx>>, b_scopes: Vec<BoundRegionScope<'tcx>>, }

Fields§

§infcx: &'me InferCtxt<'tcx>§delegate: D

Callback to use when we deduce an outlives relationship.

§ambient_variance: Variance

How are we relating a and b?

  • Covariant means a <: b.
  • Contravariant means b <: a.
  • Invariant means `a == b.
  • Bivariant means that it doesn’t matter.
§ambient_variance_info: VarianceDiagInfo<'tcx>§a_scopes: Vec<BoundRegionScope<'tcx>>

When we pass through a set of binders (e.g., when looking into a fn type), we push a new bound region scope onto here. This will contain the instantiated region for each region in those binders. When we then encounter a ReLateBound(d, br), we can use the De Bruijn index d to find the right scope, and then bound region name br to find the specific instantiation from within that scope. See replace_bound_region.

This field stores the instantiations for late-bound regions in the a type.

§b_scopes: Vec<BoundRegionScope<'tcx>>

Same as a_scopes, but for the b type.

Implementations§

When we encounter binders during the type traversal, we record the value to substitute for each of the things contained in that binder. (This will be either a universal placeholder or an existential inference variable.) Given the De Bruijn index debruijn (and name br) of some binder we have now encountered, this routine finds the value that we instantiated the region with; to do so, it indexes backwards into the list of ambient scopes scopes.

If r is a bound region, find the scope in which it is bound (from scopes) and return the value that we instantiated it with. Otherwise just return r.

Push a new outlives requirement into our output set of constraints.

Relate a projection type and some value type lazily. This will always succeed, but we push an additional ProjectionEq goal depending on the value type:

  • if the value type is any type T which is not a projection, we push ProjectionEq(projection = T).
  • if the value type is another projection other_projection, we create a new inference variable ?U and push the two goals ProjectionEq(projection = ?U), ProjectionEq(other_projection = ?U).

Relate a type inference variable with a value type. This works by creating a “generalization” G of the value where all the lifetimes are replaced with fresh inference values. This generalization G becomes the value of the inference variable, and is then related in turn to the value. So e.g. if you had vid = ?0 and value = &'a u32, we might first instantiate ?0 to a type like &'0 u32 where '0 is a fresh variable, and then relate &'0 u32 with &'a u32 (resulting in relations between '0 and 'a).

The variable pair can be either a (vid, ty) or (ty, vid) – in other words, it is always an (unresolved) inference variable vid and a type ty that are being related, but the vid may appear either as the “a” type or the “b” type, depending on where it appears in the tuple. The trait VidValuePair lets us work with the vid/type while preserving the “sidedness” when necessary – the sidedness is relevant in particular for the variance and set of in-scope things.

Trait Implementations§

Register an obligation that both constants must be equal to each other. Read more
Returns a static string we can use for printouts.
Returns true if the value a is the “expected” type in the relation. Just affects error messages. Read more
Used during coherence. If called, must emit an always-ambiguous obligation.
Switch variance for the purpose of relating a and b.
Generic relation routine suitable for most anything.
Relate the two substitutions for the given item. The default is to look up the variance for the item and proceed accordingly. Read more

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.