Expand description
Type inference, i.e. the process of walking through the code and determining the type of each expression and pattern.
For type inference, compare the implementations in rustc (the various
check_* methods in rustc_hir_typeck/check.rs are a good entry point) and
IntelliJ-Rust (org.rust.lang.core.types.infer). Our entry point for
inference here is the infer function, which infers the types of all
expressions in a given function.
During inference, types (i.e. the Ty struct) can contain type βvariablesβ
which represent currently unknown types; as we walk through the expressions,
we might determine that certain variables need to be equal to each other, or
to certain types. To record this, we use the union-find implementation from
the ena crate, which is extracted from rustc.
Re-exportsΒ§
pub use coerce::could_coerce;pub use unify::could_unify;pub use unify::could_unify_deeply;
ModulesΒ§
- autoderef π
- Autoderef helpers for inference.
- callee π
- Inference of calls.
- cast π
- Type cast logic. Basically coercion + additional casts.
- closure π
- Inference of closure parameter types based on the closureβs expected type.
- coerce π
- Type Coercion
- diagnostics π
- This file contains the
Diagnosticstype used during inference, and a wrapper aroundTyLoweringContext(InferenceTyLoweringContext) that replaces it and takes care of diagnostics in inference. - expr π
- Type inference for expressions.
- fallback π
- Fallback of infer vars to
!andi32/f64. - mutability π
- Finds if an expression is an immutable context or a mutable context, which is used in selecting
between
DerefandDerefMutorIndexandIndexMutor similar. - op π
- Inference of binary and unary operators.
- opaques π
- Defining opaque types via inference.
- pat π
- Type inference for patterns.
- path π
- Path expression resolution.
- place_
op π - Inference of place operators: deref and indexing (operators that create places, as opposed to values).
- unify π
- Unification and canonicalization logic.
StructsΒ§
- Adjustment
- Represents coercing a value to a different type of value.
- Binding
Mode - The mode of a binding (
mut,ref mut, etc). Used for both the explicit binding annotations given in the HIR for a binding and the final binding mode that we infer after type inference/match ergonomics..0is the by-reference mode (ref,ref mut, or by value),.1is the mutability of the binding. - Breakable
Context π - Capture
Info - Part of
MinCaptureInformationMap; describes the capture kind (&, &mut, move) for a particular capture as well as identifying the part of the source code that triggered this capture to occur. - Capture
Source Stack - Captured
Place - A composite describing a
Placethat is captured by a closure. - Closure
Data - Inference
Context π - The inference context contains all information needed during type inference.
- Inference
Result - The result of type inference: A mapping from expressions and patterns to types.
- Overloaded
Deref - An overloaded autoderef step, representing a
Deref(Mut)::deref(_mut)call, with the signature&'a T -> &'a Uor&'a mut T -> &'a mut U. The target type isUin both cases, with the region and mutability being those shared by both the receiver and the returned reference. - PatAdjustment
- Represents an implicit coercion applied to the scrutinee of a match before testing a pattern against it. Currently, this is used only for implicit dereferences.
EnumsΒ§
- Adjust
- Allow
TwoPhase - At least for initial deployment, we want to limit two-phase borrows to only a few specific cases. Right now, those are mostly βthings that desugarβ into method calls:
- Auto
Borrow - Auto
Borrow Mutability - Breakable
Kind π - ByRef
- Capture
Source πStack Repr - Deref
PatBorrow πMode - Diverges π
- Expectation π
- When inferring an expression, we propagate downward whatever type hint we
are able in the form of an
Expectation. - Explicit
Drop Method UseKind - Inference
Diagnostic - Inference
TyDiagnostic Source - PatAdjust
- Represents implicit coercions of patternsβ types, rather than valuesβ types.
- Pointer
Cast - Return
Kind - Upvar
Capture - Information describing the capture of an upvar. This is computed
during
typeck, specifically byregionck.
FunctionsΒ§
- find_
breakable π - find_
continuable π - infer_
anon_ πconst_ cycle_ result - infer_
anon_ πconst_ query - Infer types for an anonymous const expression.
- infer_
cycle_ πresult - infer_
finalize π - infer_
query π - The entry point of type inference.
- infer_
query_ with_ inspect
Type AliasesΒ§
- MinCapture
List π - Part of
MinCaptureInformationMap; List ofCapturePlaces. - Root
Variable πMinCapture List - Part of
MinCaptureInformationMap; Maps a root variable to the list ofCapturedPlace. Used to track the minimum set ofPlaces that need to be captured to support all Places captured by the closure starting at a given root variable.