Struct rustc_infer::infer::nll_relate::TypeGeneralizer
source · [−]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 relate 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
sourceimpl<'tcx, D> TypeRelation<'tcx> for TypeGeneralizer<'_, 'tcx, D>where
D: TypeRelatingDelegate<'tcx>,
impl<'tcx, D> TypeRelation<'tcx> for TypeGeneralizer<'_, 'tcx, D>where
D: TypeRelatingDelegate<'tcx>,
fn tcx(&self) -> TyCtxt<'tcx>
fn param_env(&self) -> ParamEnv<'tcx>
sourcefn a_is_expected(&self) -> bool
fn a_is_expected(&self) -> bool
true
if the value a
is the “expected” type in the
relation. Just affects error messages. Read moresourcefn 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>
a
and b
.fn tys(&mut self, a: Ty<'tcx>, _: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>>
fn regions(
&mut self,
a: Region<'tcx>,
_: Region<'tcx>
) -> RelateResult<'tcx, Region<'tcx>>
fn consts(
&mut self,
a: Const<'tcx>,
_: Const<'tcx>
) -> RelateResult<'tcx, Const<'tcx>>
fn binders<T>(
&mut self,
a: Binder<'tcx, T>,
_: Binder<'tcx, T>
) -> RelateResult<'tcx, Binder<'tcx, T>>where
T: Relate<'tcx>,
fn with_cause<F, R>(&mut self, _cause: Cause, f: F) -> Rwhere
F: FnOnce(&mut Self) -> R,
sourcefn relate<T>(&mut self, a: T, b: T) -> Result<T, TypeError<'tcx>>where
T: Relate<'tcx>,
fn relate<T>(&mut self, a: T, b: T) -> Result<T, TypeError<'tcx>>where
T: Relate<'tcx>,
sourcefn 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>>
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
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