Struct rustc_infer::infer::generalize::Generalizer
source · struct Generalizer<'me, 'tcx, D> {
infcx: &'me InferCtxt<'tcx>,
delegate: &'me mut D,
ambient_variance: Variance,
root_vid: TermVid<'tcx>,
for_universe: UniverseIndex,
root_term: Term<'tcx>,
cache: SsoHashMap<Ty<'tcx>, Ty<'tcx>>,
needs_wf: bool,
}
Expand description
The “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 term B
– this replaces
all the lifetimes in the term 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.
Fields§
§infcx: &'me InferCtxt<'tcx>
§delegate: &'me mut D
This is used to abstract the behaviors of the three previous
generalizer-like implementations (Generalizer
, TypeGeneralizer
,
and ConstInferUnifier
). See GeneralizerDelegate
for more
information.
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?
root_vid: TermVid<'tcx>
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.
for_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.
root_term: Term<'tcx>
The root term (const or type) we’re generalizing. Used for cycle errors.
cache: SsoHashMap<Ty<'tcx>, Ty<'tcx>>
§needs_wf: bool
See the field needs_wf
in Generalization
.
Implementations§
source§impl<'tcx, D> Generalizer<'_, 'tcx, D>
impl<'tcx, D> Generalizer<'_, 'tcx, D>
sourcefn cyclic_term_error(&self) -> TypeError<'tcx>
fn cyclic_term_error(&self) -> TypeError<'tcx>
Create an error that corresponds to the term kind in root_term
Trait Implementations§
source§impl<'tcx, D> TypeRelation<'tcx> for Generalizer<'_, 'tcx, D>where
D: GeneralizerDelegate<'tcx>,
impl<'tcx, D> TypeRelation<'tcx> for Generalizer<'_, 'tcx, D>where D: GeneralizerDelegate<'tcx>,
fn tcx(&self) -> TyCtxt<'tcx>
fn param_env(&self) -> ParamEnv<'tcx>
source§fn 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.source§fn relate_item_args(
&mut self,
item_def_id: DefId,
a_subst: GenericArgsRef<'tcx>,
b_subst: GenericArgsRef<'tcx>
) -> RelateResult<'tcx, GenericArgsRef<'tcx>>
fn relate_item_args( &mut self, item_def_id: DefId, a_subst: GenericArgsRef<'tcx>, b_subst: GenericArgsRef<'tcx> ) -> RelateResult<'tcx, GenericArgsRef<'tcx>>
source§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>
a
and b
.fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>>
fn regions( &mut self, r: Region<'tcx>, r2: Region<'tcx> ) -> RelateResult<'tcx, Region<'tcx>>
fn consts( &mut self, c: Const<'tcx>, c2: 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,
Auto Trait Implementations§
impl<'me, 'tcx, D> !RefUnwindSafe for Generalizer<'me, 'tcx, D>
impl<'me, 'tcx, D> !Send for Generalizer<'me, 'tcx, D>
impl<'me, 'tcx, D> !Sync for Generalizer<'me, 'tcx, D>
impl<'me, 'tcx, D> Unpin for Generalizer<'me, 'tcx, D>
impl<'me, 'tcx, D> !UnwindSafe for Generalizer<'me, 'tcx, D>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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: 184 bytes