Module canonical

Source
Expand description

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 canonicalize_query 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 instantiate_query_result method.

For a more detailed look at what is happening here, check out the chapter in the rustc dev guide.

Modulesยง

instantiate
This module contains code to instantiate new values into a Canonical<'tcx, T>.