Module rustc::middle::traitsExperimental [-]  [+] [src]

Trait Resolution. See doc.rs.

Reexports

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

Structs

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 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
Obligation

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

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

SelectionCache
SelectionContext
Supertraits
VtableBuiltinData
VtableImplData

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.

VtableParamData

A vtable provided as a parameter by the caller. For example, in a function like fn foo<T:Eq>(...), if the eq() method is invoked on an instance of T, the vtable would be of type VtableParam.

Enums

FulfillmentErrorCode
MethodMatchResult
MethodMatchedData
ObligationCauseCode
SelectionError
Vtable

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

is_orphan_impl

True if neither the trait nor self type is local. Note that impl_def_id must refer to an impl of a trait, not an inherent impl.

obligation_for_builtin_bound
obligations_for_generics

Given generic bounds from an impl like:

overlapping_impls

True if there exist types that satisfy both of the two given impls.

search_trait_and_supertraits_from_bound

Starting from a caller obligation caller_bound (which has coordinates space/i in the list of caller obligations), search through the trait and supertraits to find one where test(d) is true, where d is the def-id of the trait/supertrait. If any is found, return Some(p) where p is the path to that trait/supertrait. Else None.

select_inherent_impl

Matches the self type of the inherent impl impl_def_id against self_ty and returns the resulting resolution. This routine may modify the surrounding type context (for example, it may unify variables).

supertraits

Returns an iterator over the trait reference T and all of its supertrait references. May contain duplicates. In general the ordering is not defined.

transitive_bounds

Type Definitions

Obligations
Selection
SelectionResult

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