Module rustc_trait_selection::solve::alias_relate
source · Expand description
Implements the AliasRelate
goal, which is used when unifying aliases.
Doing this via a separate goal is called “deferred alias relation” and part
of our more general approach to “lazy normalization”.
This is done by first normalizing both sides of the goal, ending up in either a concrete type, rigid alias, or an infer variable. These are related further according to the rules below:
(1.) If we end up with two rigid aliases, then we relate them structurally.
(2.) If we end up with an infer var and a rigid alias, then we instantiate the infer var with the constructor of the alias and then recursively relate the terms.
(3.) Otherwise, if we end with two rigid (non-projection) or infer types, relate them structurally.
Subtle: when relating an opaque to another type, we emit a
NormalizesTo(opaque, ?fresh_var)
goal when trying to normalize the opaque.
This nested goal starts out as ambiguous and does not actually define the opaque.
However, if ?fresh_var
ends up geteting equated to another type, we retry the
NormalizesTo
goal, at which point the opaque is actually defined.