Struct rustc_infer::infer::nll_relate::TypeGeneralizer [−][src]
struct TypeGeneralizer<'me, 'tcx, D> where
D: TypeRelatingDelegate<'tcx>, {
infcx: &'me InferCtxt<'me, 'tcx>,
delegate: &'me mut D,
ambient_variance: Variance,
first_free_index: DebruijnIndex,
for_vid_sub_root: TyVid,
universe: UniverseIndex,
}
Expand description
The “type generalizer” is used when handling inference variables.
The basic strategy for handling a constraint like ?A <: B
is to
apply a “generalization strategy” to the type B
– this replaces
all the lifetimes in the type B
with fresh inference
variables. (You can read more about the strategy in this blog
post.)
As an example, if we had ?A <: &'x u32
, we would generalize &'x u32
to &'0 u32
where '0
is a fresh variable. This becomes the
value of A
. Finally, we relate &'0 u32 <: &'x u32
, which
establishes '0: 'x
as a constraint.
As a side-effect of this generalization procedure, we also replace all the bound regions that we have traversed with concrete values, so that the resulting generalized type is independent from the scopes.
Fields
infcx: &'me InferCtxt<'me, 'tcx>
delegate: &'me mut D
ambient_variance: Variance
After we generalize this type, we are going to relative it to some other type. What will be the variance at this point?
first_free_index: DebruijnIndex
for_vid_sub_root: TyVid
The vid of the type variable that is in the process of being instantiated. If we find this within the value we are folding, that means we would have created a cyclic value.
universe: UniverseIndex
The universe of the type variable that is in the process of being instantiated. If we find anything that this universe cannot name, we reject the relation.
Trait Implementations
impl<D, 'tcx, 'me> TypeRelation<'tcx> for TypeGeneralizer<'me, 'tcx, D> where
D: TypeRelatingDelegate<'tcx>,
impl<D, 'tcx, 'me> TypeRelation<'tcx> for TypeGeneralizer<'me, 'tcx, D> where
D: TypeRelatingDelegate<'tcx>,
Returns true
if the value a
is the “expected” type in the
relation. Just affects error messages. Read more
fn relate_with_variance<T: Relate<'tcx>>(
&mut self,
variance: Variance,
_info: VarianceDiagInfo<'tcx>,
a: T,
b: T
) -> RelateResult<'tcx, T>
fn relate_with_variance<T: Relate<'tcx>>(
&mut self,
variance: Variance,
_info: VarianceDiagInfo<'tcx>,
a: T,
b: T
) -> RelateResult<'tcx, T>
Switch variance for the purpose of relating a
and b
.
fn consts(
&mut self,
a: &'tcx Const<'tcx>,
_: &'tcx Const<'tcx>
) -> RelateResult<'tcx, &'tcx Const<'tcx>>
fn binders<T>(
&mut self,
a: Binder<'tcx, T>,
_: Binder<'tcx, T>
) -> RelateResult<'tcx, Binder<'tcx, T>> where
T: Relate<'tcx>,
Generic relation routine suitable for most anything.
fn relate_item_substs(
&mut self,
item_def_id: DefId,
a_subst: &'tcx List<GenericArg<'tcx>>,
b_subst: &'tcx List<GenericArg<'tcx>>
) -> Result<&'tcx List<GenericArg<'tcx>>, TypeError<'tcx>>
fn relate_item_substs(
&mut self,
item_def_id: DefId,
a_subst: &'tcx List<GenericArg<'tcx>>,
b_subst: &'tcx List<GenericArg<'tcx>>
) -> Result<&'tcx List<GenericArg<'tcx>>, TypeError<'tcx>>
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
impl<'me, 'tcx, D> !RefUnwindSafe for TypeGeneralizer<'me, 'tcx, D>
impl<'me, 'tcx, D> !Send for TypeGeneralizer<'me, 'tcx, D>
impl<'me, 'tcx, D> !Sync for TypeGeneralizer<'me, 'tcx, D>
impl<'me, 'tcx, D> Unpin for TypeGeneralizer<'me, 'tcx, D> where
'tcx: 'me,
impl<'me, 'tcx, D> !UnwindSafe for TypeGeneralizer<'me, 'tcx, D>
Blanket Implementations
Layout
Note: Most layout information is completely unstable and may even differ between compilations. 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: 32 bytes