Expand description
Trait Resolution. See the rustc dev guide for more information on how this works.
Re-exports§
- pub use self::normalize::NormalizeExt;
- pub use self::project::normalize_inherent_projection;
- pub use self::project::normalize_projection_term;
Modules§
- auto_trait 
- Support code for rustdoc and external tools. You really don’t want to be using this unless you need to.
- 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 🔒
- 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 
- 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
- specialization_graph 
- 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§
- BoundVarReplacer 
- DerivedCause 
- DerivedHost Cause 
- FulfillmentContext 
- The fulfillment context is used to drive trait resolution. It
consists of a list of obligations that must be (eventually)
satisfied. The job is to track which are satisfied, which yielded
errors, and which are still pending. At any point, users can call
try_evaluate_obligations, and the fulfillment context will try to do selection, retaining only those obligations that remain ambiguous. This may be helpful in pushing type inference along. Once all type inference constraints have been generated, the methodevaluate_obligations_error_on_ambiguitycan be used to report any remaining ambiguous cases as errors.
- FulfillmentError 
- FutureCompat Overlap Error 
- ImplDerived Cause 
- ImplDerived Host Cause 
- ImplSource 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.
- MatchExpression ArmCause 
- MismatchedProjection 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).
- ObligationCause 
- The reason why we incurred this obligation; used for error reporting.
- ObligationCause Code Handle 
- A compact form of ObligationCauseCode.
- ObligationCtxt 
- Used if you want to have pleasant experience when dealing with obligations outside of hir or mir typeck.
- OldSolverError 
- OverlapError 
- Information pertinent to an overlapping impl error.
- OverlapResult 
- PatternOrigin 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.
- PendingPredicate Obligation 
- PlaceholderReplacer 
- The inverse of BoundVarReplacer: replaces placeholders with the bound vars from which they came.
- ProjectionCache 
- 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.
- ProjectionCache Key 
- ProjectionCache Storage 
- SelectionContext 
- SignatureMismatch Data 
- UncoveredTyParams 
Enums§
- BuiltinImpl Source 
- CodegenObligation Error 
- These are the error cases for codegen_select_candidate.
- DynCompatibilityViolation 
- DynCompatibilityViolation Solution 
- EvaluateConst Err 
- EvaluationResult 
- The result of trait evaluation. The order is important here as the evaluation of a list is the maximum of the evaluations.
- FulfillmentError Code 
- FutureCompat Overlap Error Kind 
- ImplSource 
- 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.
- IntercrateAmbiguity Cause 
- IsConstable
- Whether a value can be extracted into a const. Used for diagnostics around array repeat expressions.
- IsFirstInput Type 
- MethodViolation Code 
- Reasons a method might not be dyn-compatible.
- ObligationCause Code 
- OrphanCheck Err 
- OrphanCheck Mode 
- OverflowError 
- Indicates that trait evaluation caused overflow and in which pass.
- ProjectionCache Entry 
- ScrubbedTrait 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).
- SelectionError 
- SkipLeak Check 
- Whether to skip the leak check, as part of a future compatibility warning step.
- TraitQuery Mode 
- The mode that trait queries run in.
- WellFormed 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§
- add_placeholder_ note 
- do_normalize_ 🔒predicates 
- dyn_compatibility_ violations_ for_ assoc_ item 
- Returns Some(_)if this item makes the containing trait dyn-incompatible.
- 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)
- expand_trait_ aliases 
- Return the trait and projection predicates that come from eagerly expanding the trait aliases in the list of clauses. For each trait predicate, record a stack of spans that trace from the user-written trait alias bound. For projection predicates, just record the span of the projection itself.
- hir_ty_ lowering_ dyn_ compatibility_ violations 
- Returns the dyn-compatibility violations that affect HIR ty lowering.
- impl_item_ is_ final 
- impossible_predicates 
- Normalizes the predicates and checks whether they hold in an empty environment. If this returns true, then either normalize encountered an error or one of the predicates did not hold. Used when creating vtables to check for unsatisfiable methods. This should not be used during analysis.
- instantiate_and_ 🔒check_ impossible_ predicates 
- is_impossible_ 🔒associated_ item 
- Checks whether a trait’s associated item is impossible to reference on a given impl.
- is_vtable_ safe_ method 
- We say a method is vtable safe if it can be invoked on a trait
object. Note that dyn-compatible traits can have some
non-vtable-safe methods, so long as they require Self: Sizedor otherwise ensure that they cannot be used whenSelf = Trait.
- 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.
- overlapping_inherent_ impls 
- If there are types that satisfy both impls, returns Somewith a suitably-freshenedImplHeaderwith those types instantiated. Otherwise, returnsNone.
- overlapping_trait_ impls 
- If there are types that satisfy both impls, returns Somewith a suitably-freshenedImplHeaderwith those types instantiated. Otherwise, returnsNone.
- 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_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.
- sizedness_fast_ path 
- 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).
- translate_args 
- Given the generic parameters for the requested impl, translate it to the generic parameters appropriate for the actual item definition (whether it be in that impl, a parent impl, or the trait).
- translate_args_ with_ cause 
- Like translate_args, but obligations from the parent implementation
are registered with the provided ObligationCause.
- 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).
- upcast_choices 
- Casts a trait reference into a reference to one of its super
traits; returns Noneiftarget_trait_def_idis not a supertrait.
- with_replaced_ escaping_ bound_ vars 
- Executes fonvalueafter replacing all escaping bound variables with placeholders and then replaces these placeholders with the original bound variables in the result.
Type Aliases§
- EvaluationCache 
- NormalizedTerm 
- ObligationInspector 
- A callback that can be provided to inspect_typeck. Invoked on evaluation of root obligations.
- PolyTrait Obligation 
- PredicateObligation 
- PredicateObligations 
- Selection
- SelectionCache 
- SelectionResult 
- When performing resolution, it is typically the case that there can be one of three outcomes:
- TraitObligation