pub use self::LateBoundRegionConversionTime::*;
pub use self::RegionVariableOrigin::*;
pub use self::SubregionOrigin::*;
pub use self::ValuePairs::*;
A nice interface for working with the infcx. The basic idea is to do
infcx.at(cause, param_env), which sets the “cause” of the operation as well as the surrounding parameter environment. Then you can do something like
.eq(a, b)to create a subtype or equality relationship respectively. The first argument is always the “expected” output from the POV of diagnostics.
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_queryproduces two things:
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.
Error Reporting Code for the inference engine
This module handles the relationships between “free regions”, i.e., lifetime parameters. Ordinarily, free regions are unrelated to one another, but they can be related via implied or explicit bounds. In that case, we track the bounds using the
TransitiveRelationtype, and use that to decide when one free region outlives another, and so forth.
Freshening is the process of replacing unknown variables with fresh types. The idea is that the type, after freshening, contains no inference variables but instead contains either a value for each variable or fresh “arbitrary” types wherever a variable would have been.
Helper routines for higher-ranked things. See the
docmodule at the end of the file for details.
Lexical region resolution.
This code is kind of an alternate way of doing subtyping, supertyping, and type equating, distinct from the
combine.rscode but very similar in its effect and design. Eventually the two ought to be merged. This code is intended for use in NLL and chalk.
Various code related to computing outlives relations.
Used to configure inference contexts before their creation
This type contains all the things within
InferCtxtthat sit within a
RefCelland are involved with taking/rolling back snapshots. Snapshot operations are hot enough that we want only one call to
borrow_mutper call to
f64. Used only for diagnostics.
region_obligationsfield for more information.
The trace designates the path through inference that we took to encounter an error or subtyping constraint.
Times when we replace late-bound regions with variables:
Reasons to create a region inference variable
The origin of a
r1 <= r2constraint.
ty_or_const_infer_var_changed(see comment on that), currently used only for
traits::fulfill’s list of
error_reportingmodule for more details.
Replaces substs that reference param or infer variables with suitable placeholders. This function is meant to remove these param and infer substs when they’re not actually needed to evaluate a constant.