Module rustc_infer::infer::combine
source · Expand description
There are four type combiners: Equate, Sub, Lub, and Glb.
Each implements the trait TypeRelation and contains methods for
combining two instances of various things and yielding a new instance.
These combiner methods always yield a Result<T>
. To relate two
types, you can use infcx.at(cause, param_env)
which then allows
you to use the relevant methods of At.
Combiners mostly do their specific behavior and then hand off the bulk of the work to InferCtxt::super_combine_tys and InferCtxt::super_combine_consts.
Combining two types may have side-effects on the inference contexts which can be undone by using snapshots. You probably want to use either InferCtxt::commit_if_ok or InferCtxt::probe.
On success, the LUB/GLB operations return the appropriate bound. The
return value of Equate
or Sub
shouldn’t really be used.
Contravariance
We explicitly track which argument is expected using TypeRelation::a_is_expected, so when dealing with contravariance this should be correctly updated.