Skip to main content

Module infer

Module infer 

Source

Re-exportsΒ§

use std::cell::Cell; πŸ”’
use std::cell::RefCell; πŸ”’
use std::fmt; πŸ”’
use std::range::RangeInclusive; πŸ”’
pub use at::DefineOpaqueTypes;
use free_regions::RegionRelations; πŸ”’
use lexical_region_resolve::LexicalRegionResolutions; πŸ”’
use region_constraints::GenericKind; πŸ”’
use region_constraints::RegionConstraintCollector; πŸ”’
use region_constraints::RegionConstraintStorage; πŸ”’
use region_constraints::VarInfos; πŸ”’
use region_constraints::VerifyBound; πŸ”’
use rustc_data_structures::fx::FxHashSet; πŸ”’
use rustc_data_structures::fx::FxIndexMap; πŸ”’
use rustc_data_structures::snapshot_vec as sv; πŸ”’
use rustc_data_structures::undo_log::Rollback; πŸ”’
use rustc_data_structures::undo_log::UndoLogs; πŸ”’
use rustc_data_structures::unify as ut; πŸ”’
use rustc_data_structures::unify::UnifyKey; πŸ”’
use rustc_data_structures::unify::UnifyValue; πŸ”’
use rustc_errors::DiagCtxtHandle; πŸ”’
use rustc_errors::ErrorGuaranteed; πŸ”’
use rustc_hir::def_id::DefId; πŸ”’
use rustc_hir::def_id::LocalDefId; πŸ”’
use rustc_hir as hir; πŸ”’
use rustc_hir::HirId; πŸ”’
use rustc_index::IndexVec; πŸ”’
use rustc_macros::extension; πŸ”’
use rustc_middle::infer::canonical::CanonicalQueryInput; πŸ”’
use rustc_middle::infer::canonical::CanonicalVarValues; πŸ”’
use rustc_middle::mir::ConstraintCategory; πŸ”’
use rustc_middle::traits::select; πŸ”’
use rustc_middle::traits::solve::Goal; πŸ”’
use rustc_middle::ty::error::ExpectedFound; πŸ”’
use rustc_middle::ty::error::TypeError; πŸ”’
use rustc_middle::ty; πŸ”’
use rustc_middle::ty::BoundVarReplacerDelegate; πŸ”’
use rustc_middle::ty::ConstVid; πŸ”’
use rustc_middle::ty::FloatVid; πŸ”’
use rustc_middle::ty::GenericArg; πŸ”’
use rustc_middle::ty::GenericArgKind; πŸ”’
use rustc_middle::ty::GenericArgs; πŸ”’
use rustc_middle::ty::GenericArgsRef; πŸ”’
use rustc_middle::ty::GenericParamDefKind; πŸ”’
use rustc_middle::ty::InferConst; πŸ”’
use rustc_middle::ty::OpaqueTypeKey; πŸ”’
use rustc_middle::ty::ProvisionalHiddenType; πŸ”’
use rustc_middle::ty::PseudoCanonicalInput; πŸ”’
use rustc_middle::ty::Term; πŸ”’
use rustc_middle::ty::Ty; πŸ”’
use rustc_middle::ty::TyCtxt; πŸ”’
use rustc_middle::ty::TyVid; πŸ”’
use rustc_middle::ty::TypeFoldable; πŸ”’
use rustc_middle::ty::TypeFolder; πŸ”’
use rustc_middle::ty::TypeSuperFoldable; πŸ”’
use rustc_middle::ty::TypeVisitable; πŸ”’
use rustc_middle::ty::TypeVisitableExt; πŸ”’
use rustc_middle::ty::TypingEnv; πŸ”’
use rustc_middle::ty::TypingMode; πŸ”’
use rustc_middle::ty::fold_regions; πŸ”’
use rustc_span::DUMMY_SP; πŸ”’
use rustc_span::Span; πŸ”’
use rustc_span::Symbol; πŸ”’
use rustc_span::bug; πŸ”’
use rustc_type_ir::CanonicalizerState; πŸ”’
use rustc_type_ir::MayBeErased; πŸ”’
use snapshot::undo_log::InferCtxtUndoLogs; πŸ”’
use tracing::debug; πŸ”’
use tracing::instrument; πŸ”’
use tracing::instrument; πŸ”’
use ty::solve::TyOrConstInferVar; πŸ”’
use type_variable::TypeVariableOrigin; πŸ”’
use crate::infer::snapshot::undo_log::UndoLog; πŸ”’
use crate::infer::type_variable::FloatVariableOrigin; πŸ”’
use crate::infer::type_variable::TypeVariableValue; πŸ”’
use crate::infer::unify_key::ConstVariableOrigin; πŸ”’
use crate::infer::unify_key::ConstVariableValue; πŸ”’
use crate::infer::unify_key::ConstVidKey; πŸ”’
use crate::traits; πŸ”’
use crate::traits::ObligationCause; πŸ”’
use crate::traits::ObligationInspector; πŸ”’
use crate::traits::PredicateObligation; πŸ”’
use crate::traits::PredicateObligations; πŸ”’
use crate::traits::TraitEngine; πŸ”’
pub use region_constraints::SolverRegionConstraint;

ModulesΒ§

at
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 .sub(a, b) or .eq(a, b) to create a subtype or equality relationship respectively. The first argument is always the β€œexpected” output from the POV of diagnostics.
canonical
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:
context πŸ”’
Definition of InferCtxtLike from the librarified type layer.
free_regions πŸ”’
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 TransitiveRelation type, and use that to decide when one free region outlives another, and so forth.
freshen πŸ”’
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.
lexical_region_resolve πŸ”’
Lexical region resolution.
opaque_types πŸ”’
outlives
Various code related to computing outlives relations.
projection πŸ”’
region_constraints
See README.md.
relate
This module contains the definitions of most TypeRelations in the type system (except for some relations used for diagnostics and heuristics in the compiler). As well as the implementation of Relate for interned things (Ty/Const/etc).
resolve
snapshot πŸ”’
type_variable πŸ”’
unify_key πŸ”’

StructsΒ§

FixupError
InferCtxt
InferCtxtBuilder
Used to configure inference contexts before their creation.
InferCtxtInner
This type contains all the things within InferCtxt that sit within a RefCell and are involved with taking/rolling back snapshots. Snapshot operations are hot enough that we want only one call to RefCell::borrow_mut per call to InferCtxt::start_snapshot and InferCtxt::rollback_to.
InferOk
InferOk<'tcx, ()> is used a lot. It may seem like a useless wrapper around PredicateObligations<'tcx>, but it has one important property: because InferOk is marked with #[must_use], if you have a method InferCtxt::f that returns InferResult<'tcx, ()> and you call it with infcx.f()?; you’ll get a warning about the obligations being discarded without use, which is probably unintentional and has been a source of bugs in the past.
InferenceLiteralEraser πŸ”’
Replace {integer} with i32 and {float} with f64. Used only for diagnostics.
OpaqueTypeStorage
OpaqueTypeStorageEntries
The number of entries in the opaque type storage at a given point.
OpaqueTypeTable
TypeFreshener
TypeOutlivesConstraint
See the region_obligations field for more information.
TypeTrace
The trace designates the path through inference that we took to encounter an error or subtyping constraint.

EnumsΒ§

BoundRegionConversionTime
Times when we replace bound regions with existentials:
NllRegionVariableOrigin
RegionResolutionError
RegionVariableOrigin
Reasons to create a region inference variable.
SubregionOrigin
The origin of a r1 <= r2 constraint.
ValuePairs
See the error_reporting module for more details.

TraitsΒ§

PredicateEmittingRelation
TyCtxtInferExt

FunctionsΒ§

unresolved_root_variables_of πŸ”’
Returns unresolved root variables from table, according to is_unresolved.

Type AliasesΒ§

FixupResult πŸ”’
InferResult
UnificationTable πŸ”’

Derive MacrosΒ§

TypeFoldable
Derives TypeFoldable for the annotated struct or enum (union is not supported).
TypeVisitable
Derives TypeVisitable for the annotated struct or enum (union is not supported).