Canonicalization is the key to constructing a query in the
middle of type inference. Ordinarily, it is not possible to store
types from type inference in query keys, because they contain
references to inference variables whose lifetimes are too short
and so forth. Canonicalizing a value T1 using
produces two things:
- a value T2 where each unbound inference variable has been replaced with a canonical variable;
- a map M (of type
CanonicalVarValues) from those canonical variables back to the original.
We can then do queries using T2. These will give back constraints
on the canonical variables which can be translated, using the map
M, into constraints in our source context. This process of
translating the results back is done by the
For a more detailed look at what is happening here, check out the chapter in the rustc dev guide.
Vis one where all free inference variables have been rewritten to “canonical vars”. These are numbered starting from 0 in order of first appearance.
Canonical. You can give these values to
canonical_value.substituteto substitute them into the canonical value at the right places.
Canonical<QueryResponse<..>>. You can use
instantiate_query_resultto access the data in this result.