Expand description
Trait Resolution. See the rustc dev guide for more information on how this works.
Re-exportsยง
use std::fmt::Debug;๐use std::fmt::Debug;๐use std::ops::ControlFlow;๐use rustc_errors::ErrorGuaranteed;๐use rustc_macros::TypeVisitable;๐use rustc_middle::query::Providers;๐use rustc_middle::ty::error::ExpectedFound;๐use rustc_middle::ty::error::TypeError;๐use rustc_middle::ty;๐use rustc_middle::ty::BottomUpFolder;๐use rustc_middle::ty::CallerBoundsIterator;๐use rustc_middle::ty::Clause;๐use rustc_middle::ty::GenericArgs;๐use rustc_middle::ty::Ty;๐use rustc_middle::ty::TyCtxt;๐use rustc_middle::ty::TypeFoldable;๐use rustc_middle::ty::TypeFolder;๐use rustc_middle::ty::TypeSuperFoldable;๐use rustc_middle::ty::TypeSuperVisitable;๐use rustc_middle::ty::TypeVisitable;๐use rustc_middle::ty::TypeVisitableExt;๐use rustc_middle::ty::TypingMode;๐use rustc_middle::ty::Unnormalized;๐use rustc_middle::ty::Upcast;๐use rustc_span::Span;๐use rustc_span::def_id::DefId;๐use tracing::debug;๐use tracing::instrument;๐use tracing::instrument;๐pub use self::coherence::OverlapResult;pub use self::coherence::add_placeholder_note;pub use self::coherence::overlapping_inherent_impls;pub use self::coherence::overlapping_trait_impls;pub use self::dyn_compatibility::dyn_compatibility_violations_for_assoc_item;pub use self::dyn_compatibility::hir_ty_lowering_dyn_compatibility_violations;pub use self::dyn_compatibility::is_vtable_safe_method;pub use self::engine::FulfillmentEngine;pub use self::engine::ObligationCtxt;pub use self::fulfill::FulfillmentContext;pub use self::fulfill::OldSolverError;pub use self::fulfill::PendingPredicateObligation;pub use self::normalize::NormalizeExt;pub use self::project::normalize_inherent_projection;pub use self::project::normalize_projection_term;pub use self::select::IntercrateAmbiguityCause;pub use self::select::SelectionContext;pub use self::specialize::specialization_graph::FutureCompatOverlapError;pub use self::specialize::specialization_graph::FutureCompatOverlapErrorKind;pub use self::specialize::OverlapError;pub use self::specialize::specialization_graph;pub use self::specialize::translate_args;pub use self::specialize::translate_args_with_cause;pub use self::structural_normalize::StructurallyNormalizeExt;pub use self::util::expand_trait_aliases;pub use self::util::impl_item_is_final;pub use self::util::implicit_fast_path;pub use self::util::upcast_choices;pub use self::util::with_replaced_escaping_bound_vars;use crate::error_reporting::InferCtxtErrorExt;๐use crate::infer::outlives::env::OutlivesEnvironment;๐use crate::infer::InferCtxt;๐use crate::infer::TyCtxtInferExt;๐use crate::regions::InferCtxtRegionExt;๐use crate::traits::query::evaluate_obligation::InferCtxtExt as _;๐
Modulesยง
- auto_
trait - Support code for rustdoc and external tools. You really donโt want to be using this unless you need to.
- cache
- Cache for candidate selection.
- coherence ๐
- See Rustc Dev Guide chapters on trait-resolution and trait-specialization for more info on how this works.
- const_
evaluatable - Checking that constant values used in types can be successfully evaluated.
- dyn_
compatibility ๐ - โDyn-compatibilityโ refers to the ability for a trait to be converted to a trait object. In general, traits may only be converted to a trait object if certain criteria are met.
- effects
- engine ๐
- fulfill ๐
- implied_
outlives_ bounds - misc
- Miscellaneous type-system utilities that are too small to deserve their own modules.
- normalize
- Deeply normalize types using the old trait solver.
- outlives_
bounds - outlives_
for_ liveness - project
- Code for projecting associated types out of trait references.
- query
- Experimental types for the trait query interface. The methods
defined in this module are all based on canonicalization,
which makes a canonical query by replacing unbound inference
variables and regions, so that results can be reused more broadly.
The providers for the queries defined here can be found in
rustc_traits. - select
- Candidate selection. See the rustc dev guide for more information on how this works.
- solve
- specialize
- Logic and data structures related to impl specialization, explained in greater detail below.
- structural_
normalize ๐ - util
- vtable
- wf
- Core logic responsible for determining what it means for various type system primitives to be โwell formedโ. Actually checking whether these primitives are well formed is performed elsewhere (e.g. during type checking or item well formedness checking).
Structsยง
- Bound
VarReplacer - Derived
Cause - Derived
Host Cause - Fulfillment
Error - Impl
Derived Cause - Impl
Derived Host Cause - Impl
Source User Defined Data - Identifies a particular impl in the source, along with a set of
generic parameters from the implโs type/lifetime parameters. The
nestedvector corresponds to the nested obligations attached to the implโs type parameters. - Match
Expression ArmCause - Mismatched
Projection Types - Normalized
- Obligation
- An
Obligationrepresents some trait reference (e.g.,i32: Eq) for which the โimpl_sourceโ must be found. The process of finding an โimpl_sourceโ is called โresolvingโ theObligation. This process consists of either identifying animpl(e.g.,impl Eq for i32) that satisfies the obligation, or else finding a bound that is in scope. The eventual result is usually aSelection(defined below). - Obligation
Cause - The reason why we incurred this obligation; used for error reporting.
- Obligation
Cause Code Handle - A compact form of
ObligationCauseCode. - Pattern
Origin Expr - Information about the origin expression of a pattern, relevant to diagnostics. Fields here refer to the scrutinee of a pattern. If the scrutinee isnโt given in the diagnostic, then this wonโt exist.
- Placeholder
Replacer - The inverse of
BoundVarReplacer: replaces placeholders with the bound vars from which they came. - Projection
Cache - The projection cache. Unlike the standard caches, this can include infcx-dependent type variables, therefore we have to roll the cache back each time we roll a snapshot back, to avoid assumptions on yet-unresolved inference variables. Types with placeholder regions also have to be removed when the respective snapshot ends.
- Projection
Cache Key - Projection
Cache Storage - Signature
Mismatch Data - Uncovered
TyParams
Enumsยง
- Assoc
Const Violation - Reasons an associated const might not be dyn compatible.
- Builtin
Impl Source - Codegen
Obligation Error - These are the error cases for
codegen_select_candidate. - DynCompatibility
Violation - DynCompatibility
Violation Solution - Evaluate
Const Err - Evaluation
Result - The result of trait evaluation. The order is important here as the evaluation of a list is the maximum of the evaluations.
- Fulfillment
Error Code - Impl
Source - Given the successful resolution of an obligation, the
ImplSourceindicates where the impl comes from. - InCrate
- Whether we do the orphan check relative to this crate or to some remote crate.
- IsConstable
- Whether a value can be extracted into a const. Used for diagnostics around array repeat expressions.
- IsFirst
Input Type - Method
Violation - Reasons a method might not be dyn-compatible.
- Obligation
Cause Code - Orphan
Check Err - Orphan
Check Mode - Overflow
Error - Indicates that trait evaluation caused overflow and in which pass.
- Projection
Cache Entry - Replace
Regions ๐ - Scrubbed
Trait Error - A trait error with most of its information removed. This is the error
returned by an
ObligationCtxtby default, and suitable if you just want to see if a predicate holds, and donโt particularly care about the error itself (except for if itโs an ambiguity or true error). - Selection
Error - Skip
Leak Check - Whether to skip the leak check, as part of a future compatibility warning step.
- Trait
Errors - Trait
Query Mode - The mode that trait queries run in.
- Well
Formed Loc - The โlocationโ at which we try to perform HIR-based wf checking.
This information is used to obtain an
hir::Ty, which we can walk in order to obtain precise spans for any โnestedโ types (e.g.FooinOption<Foo>).
Traitsยง
Functionsยง
- do_
normalize_ ๐clauses - elaborate
- evaluate_
const - Evaluates a type system constant returning a
ConstKind::Errorin cases where CTFE failed and returning the passed in constant if it was not fully concrete (i.e. depended on generic parameters or inference variables) - impossible_
clauses - Normalizes the clauses and checks whether they hold in an empty environment. If this returns true, then either normalize encountered an error or one of the clauses did not hold. Used when creating vtables to check for unsatisfiable methods. This should not be used during analysis.
- instantiate_
and_ ๐check_ impossible_ clauses - is_
impossible_ ๐associated_ item - Checks whether a traitโs associated item is impossible to reference on a given impl.
- normalize_
param_ env_ or_ error - Normalizes the parameter environment, reporting errors if they occur.
- orphan_
check_ trait_ ref - Checks whether a trait-ref is potentially implementable by a crate.
- pred_
known_ ๐to_ hold_ modulo_ regions - FIXME(@lcnr): this function doesnโt seem right and shouldnโt exist?
- predicates_
for_ generics - Creates predicate obligations from the generic bounds.
- provide
- replace_
infer_ ๐and_ non_ rigid_ alias_ with_ error - replace_
param_ ๐and_ infer_ args_ with_ placeholder - Replaces args that reference param or infer variables with suitable placeholders. This function is meant to remove these param and infer args when theyโre not actually needed to evaluate a constant.
- set_
projection_ ๐term_ to_ non_ rigid - supertrait_
def_ ids - Computes the def-ids of the transitive supertraits of
trait_def_id. This (intentionally) does not compute the full elaborated super-predicates but just the set of def-ids. It is used to identify which traits may define a given associated type to help avoid cycle errors, and to make size estimates for vtable layout computation. - supertraits
- transitive_
bounds_ that_ define_ assoc_ item - A specialized variant of
elaboratethat only elaborates trait references that may define the given associated item with the nameassoc_name. It uses theexplicit_supertraits_containing_assoc_itemquery to avoid enumerating super-predicates that arenโt related toassoc_item. This is used when resolving types likeSelf::ItemorT::Itemand helps to avoid cycle errors (see e.g. #35237). - try_
evaluate_ const - Evaluates a type system constant making sure to not allow constants that depend on generic parameters or inference variables to succeed in evaluating.
- type_
known_ to_ meet_ bound_ modulo_ regions - Determines whether the type
tyis known to meetboundand returns true if so. Returns false iftyeither does not meetboundor is not known to meet bound (note that this is conservative towards no impl, which is the opposite of theevaluatemethods).
Type Aliasesยง
- Evaluation
Cache - Normalized
Term - Obligation
Inspector - A callback that can be provided to
inspect_typeck. Invoked on evaluation of root obligations. - Poly
Trait Obligation - Predicate
Obligation - Predicate
Obligations - Selection
- Selection
Cache - Selection
Result - When performing resolution, it is typically the case that there can be one of three outcomes:
- Trait
Obligation