Skip to main content

Module infer

Module infer 

Source
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 Diagnostics type used during inference, and a wrapper around TyLoweringContext (InferenceTyLoweringContext) that replaces it and takes care of diagnostics in inference.
expr πŸ”’
Type inference for expressions.
fallback πŸ”’
Fallback of infer vars to ! and i32/f64.
mutability πŸ”’
Finds if an expression is an immutable context or a mutable context, which is used in selecting between Deref and DerefMut or Index and IndexMut or 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.
BindingMode
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. .0 is the by-reference mode (ref, ref mut, or by value), .1 is the mutability of the binding.
BreakableContext πŸ”’
CaptureInfo
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.
CaptureSourceStack
CapturedPlace
A composite describing a Place that is captured by a closure.
ClosureData
InferenceContext πŸ”’
The inference context contains all information needed during type inference.
InferenceResult
The result of type inference: A mapping from expressions and patterns to types.
OverloadedDeref
An overloaded autoderef step, representing a Deref(Mut)::deref(_mut) call, with the signature &'a T -> &'a U or &'a mut T -> &'a mut U. The target type is U in 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
AllowTwoPhase
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:
AutoBorrow
AutoBorrowMutability
BreakableKind πŸ”’
ByRef
CaptureSourceStackRepr πŸ”’
DerefPatBorrowMode πŸ”’
Diverges πŸ”’
Expectation πŸ”’
When inferring an expression, we propagate downward whatever type hint we are able in the form of an Expectation.
ExplicitDropMethodUseKind
InferenceDiagnostic
InferenceTyDiagnosticSource
PatAdjust
Represents implicit coercions of patterns’ types, rather than values’ types.
PointerCast
ReturnKind
UpvarCapture
Information describing the capture of an upvar. This is computed during typeck, specifically by regionck.

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Β§

MinCaptureList πŸ”’
Part of MinCaptureInformationMap; List of CapturePlaces.
RootVariableMinCaptureList πŸ”’
Part of MinCaptureInformationMap; Maps a root variable to the list of CapturedPlace. Used to track the minimum set of Places that need to be captured to support all Places captured by the closure starting at a given root variable.