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>

source

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>,

source§

fn tcx(&self) -> TyCtxt<'tcx>

source§

fn param_env(&self) -> ParamEnv<'tcx>

source§

fn tag(&self) -> &'static str

Returns a static string we can use for printouts.
source§

fn a_is_expected(&self) -> bool

Returns 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>>

Relate the two args for the given item. The default is to look up the variance for the item and proceed accordingly.
source§

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.
source§

fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>>

source§

fn regions( &mut self, r: Region<'tcx>, r2: Region<'tcx> ) -> RelateResult<'tcx, Region<'tcx>>

source§

fn consts( &mut self, c: Const<'tcx>, c2: Const<'tcx> ) -> RelateResult<'tcx, Const<'tcx>>

source§

fn binders<T>( &mut self, a: Binder<'tcx, T>, _: Binder<'tcx, T> ) -> RelateResult<'tcx, Binder<'tcx, T>>where T: Relate<'tcx>,

source§

fn with_cause<F, R>(&mut self, _cause: Cause, f: F) -> Rwhere F: FnOnce(&mut Self) -> R,

source§

fn relate<T>(&mut self, a: T, b: T) -> Result<T, TypeError<'tcx>>where T: Relate<'tcx>,

Generic relation routine suitable for most anything.

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

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