Module rustc::traits [] [src]

🔬 This is a nightly-only experimental API. (rustc_private)

Trait Resolution. See README.md for an overview of how this works.

Reexports

pub use self::SelectionError::*;
pub use self::FulfillmentErrorCode::*;
pub use self::Vtable::*;
pub use self::ObligationCauseCode::*;
pub use self::select::MethodMatched;
pub use self::select::MethodAmbiguous;
pub use self::select::MethodDidNotMatch;

Modules

specialization_graph [
Experimental
]

Structs

DerivedObligationCause [
Experimental
]
EvaluationCache [
Experimental
]
FulfillmentContext [
Experimental
]

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 select_where_possible, and the fulfilment 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 method select_all_or_error can be used to report any remaining ambiguous cases as errors.

FulfillmentError [
Experimental
]
GlobalFulfilledPredicates [
Experimental
]
MismatchedProjectionTypes [
Experimental
]
Normalized [
Experimental
]
Obligation [
Experimental
]

An Obligation represents some trait reference (e.g. int:Eq) for which the vtable must be found. The process of finding a vtable is called "resolving" the Obligation. This process consists of either identifying an impl (e.g., impl Eq for int) that provides the required vtable, or else finding a bound that is in scope. The eventual result is usually a Selection (defined below).

ObligationCause [
Experimental
]

Why did we incur this obligation? Used for error reporting.

OverlapError [
Experimental
]

Information pertinent to an overlapping impl error.

ProjectionCache [
Experimental
]
ProjectionCacheSnapshot [
Experimental
]
RegionObligation [
Experimental
]
SelectionCache [
Experimental
]
SelectionContext [
Experimental
]
SpecializesCache [
Experimental
]
SupertraitDefIds [
Experimental
]
TraitErrorKey [
Experimental
]
VtableBuiltinData [
Experimental
]
VtableClosureData [
Experimental
]
VtableDefaultImplData [
Experimental
]
VtableFnPointerData [
Experimental
]
VtableImplData [
Experimental
]

Identifies a particular impl in the source, along with a set of substitutions from the impl's type/lifetime parameters. The nested vector corresponds to the nested obligations attached to the impl's type parameters.

VtableObjectData [
Experimental
]

A vtable for some object-safe trait Foo automatically derived for the object type Foo.

Enums

FulfillmentErrorCode [
Experimental
]
MethodMatchResult [
Experimental
]
MethodMatchedData [
Experimental
]
MethodViolationCode [
Experimental
]

Reasons a method might not be object-safe.

ObjectSafetyViolation [
Experimental
]
ObligationCauseCode [
Experimental
]
OrphanCheckErr [
Experimental
]
Reveal [
Experimental
]

Depending on the stage of compilation, we want projection to be more or less conservative.

SelectionError [
Experimental
]
Vtable [
Experimental
]

Given the successful resolution of an obligation, the Vtable indicates where the vtable comes from. Note that while we call this a "vtable", it does not necessarily indicate dynamic dispatch at runtime. Vtable instances just tell the compiler where to find methods, but in generic code those methods are typically statically dispatched -- only when an object is constructed is a Vtable instance reified into an actual vtable.

Functions

elaborate_predicates [
Experimental
]
find_method [
Experimental
]

Given a selected impl described by impl_data, returns the definition and substitions for the method with the name name, and trait method substitutions substs, in that impl, a less specialized impl, or the trait default, whichever applies.

fully_normalize [
Experimental
]
get_vtable_methods [
Experimental
]

Given a trait trait_ref, iterates the vtable entries that come from trait_ref, including its supertraits.

normalize [
Experimental
]

Normalizes any associated type projections in value, replacing them with a fully resolved type where possible. The return value combines the normalized result and any additional obligations that were incurred as result.

normalize_and_test_predicates [
Experimental
]

Normalizes the predicates and checks whether they hold. If this returns false, then either normalize encountered an error or one of the predicates did not hold. Used when creating vtables to check for unsatisfiable methods.

normalize_param_env_or_error [
Experimental
]

Normalizes the parameter environment, reporting errors if they occur.

normalize_projection_type [
Experimental
]

The guts of normalize: normalize a specific projection like <T as Trait>::Item. The result is always a type (and possibly additional obligations). If ambiguity arises, which implies that there are unresolved type variables in the projection, we will substitute a fresh type variable $X and generate a new obligation <T as Trait>::Item == $X for later.

orphan_check [
Experimental
]

Checks the coherence orphan rules. impl_def_id should be the def-id of a trait impl. To pass, either the trait must be local, or else two conditions must be satisfied:

overlapping_impls [
Experimental
]

If there are types that satisfy both impls, returns a suitably-freshened ImplHeader with those types substituted

predicates_for_generics [
Experimental
]

Creates predicate obligations from the generic bounds.

specializes [
Experimental
]

Is impl1 a specialization of impl2?

supertrait_def_ids [
Experimental
]
supertraits [
Experimental
]
transitive_bounds [
Experimental
]
translate_substs [
Experimental
]

Given a subst for the requested impl, translate it to a subst appropriate for the actual item definition (whether it be in that impl, a parent impl, or the trait). When we have selected one impl, but are actually using item definitions from a parent impl providing a default, we need a way to translate between the type parameters of the two impls. Here the source_impl is the one we've selected, and source_substs is a substitution of its generics. And target_node is the impl/trait we're actually going to get the definition from. The resulting substitution will map from target_node's generics to source_impl's generics as instantiated by source_subst.

type_known_to_meet_bound [
Experimental
]

Determines whether the type ty is known to meet bound and returns true if so. Returns false if ty either does not meet bound or is not known to meet bound (note that this is conservative towards no impl, which is the opposite of the evaluate methods).

Type Definitions

Obligations [
Experimental
]
PredicateObligation [
Experimental
]
PredicateObligations [
Experimental
]
Selection [
Experimental
]
SelectionResult [
Experimental
]

When performing resolution, it is typically the case that there can be one of three outcomes:

Supertraits [
Experimental
]
TraitObligation [
Experimental
]
TraitObligations [
Experimental
]