[][src]Module rustc::traits

⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

Trait Resolution. See the rustc guide for more information on how this works.

Re-exports

pub use self::SelectionError::*;
pub use self::FulfillmentErrorCode::*;
pub use self::Vtable::*;
pub use self::ObligationCauseCode::*;
pub use self::ObligationCauseCode::*;
pub use self::FulfillmentErrorCode::*;
pub use self::SelectionError::*;
pub use self::Vtable::*;

Modules

auto_traitInternal

Support code for rustdoc and external tools . You really don't want to be using this unless you need to.

chalk_fulfillInternal
codegenInternal
coherenceInternal

See Rustc Guide chapters on trait-resolution and trait-specialization for more info on how this works.

engineInternal
error_reportingInternal
fulfillInternal
object_safetyInternal

"Object safety" refers to the ability for a trait to be converted to an object. In general, traits may only be converted to an object if all of their methods meet certain criteria. In particular, they must:

on_unimplementedInternal
projectInternal

Code for projecting associated types out of trait references.

queryInternal

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 librustc_traits.

selectInternal

Candidate selection. See the rustc guide for more information on how this works.

specialization_graphInternal
specializeInternal

Logic and data structures related to impl specialization, explained in greater detail below.

structural_implsInternal
utilInternal

Structs

ChalkFulfillmentContextInternal
DerivedObligationCauseInternal
EnvironmentInternal

A set of clauses that we assume to be true.

EvaluationCacheInternal
FulfillmentContextInternal

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

FulfillmentErrorInternal
FutureCompatOverlapErrorInternal
InEnvironmentInternal

Something (usually a goal), along with an environment.

MismatchedProjectionTypesInternal
NormalizedInternal
ObligationInternal

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).

ObligationCauseInternal

The reason why we incurred this obligation; used for error reporting.

OnUnimplementedDirectiveInternal
OnUnimplementedNoteInternal
OverflowErrorInternal

Indicates that trait evaluation caused overflow.

OverlapErrorInternal

Information pertinent to an overlapping impl error.

OverlapResultInternal
PendingPredicateObligationInternal
ProgramClauseInternal

A "program clause" has the form D :- G1, ..., Gn. It is saying that the domain goal D is true if G1...Gn are provable. This is equivalent to the implication G1..Gn => D; we usually write it with the reverse implication operator :- to emphasize the way that programs are actually solved (via backchaining, which starts with the goal to solve and proceeds from there).

ProjectionCacheInternal

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.

ProjectionCacheSnapshotInternal
SelectionCacheInternal
SelectionContextInternal
SupertraitDefIdsInternal
TraitAliasExpanderInternal

"Trait alias expansion" is the process of expanding a sequence of trait references into another sequence by transitively following all trait aliases. e.g. If you have bounds like Foo + Send, a trait alias trait Foo = Bar + Sync;, and another trait alias trait Bar = Read + Write, then the bounds would expand to Read + Write + Sync + Send. Expansion is done via a DFS (depth-first search), and the visited field is used to avoid cycles.

VtableAutoImplDataInternal
VtableBuiltinDataInternal
VtableClosureDataInternal
VtableFnPointerDataInternal
VtableGeneratorDataInternal
VtableImplDataInternal

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.

VtableObjectDataInternal

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

VtableTraitAliasDataInternal

Enums

ClauseInternal

This matches the definition from Page 7 of "A Proof Procedure for the Logic of Hereditary Harrop Formulas".

DomainGoalInternal
EvaluationResultInternal

The result of trait evaluation. The order is important here as the evaluation of a list is the maximum of the evaluations.

FromEnvInternal
FulfillmentErrorCodeInternal
FutureCompatOverlapErrorKindInternal
GoalKindInternal
IntercrateAmbiguityCauseInternal
IntercrateModeInternal

Whether to enable bug compatibility with issue #43355.

MethodViolationCodeInternal

Reasons a method might not be object-safe.

ObjectSafetyViolationInternal
ObligationCauseCodeInternal
OrphanCheckErrInternal
ProgramClauseCategoryInternal
QuantifierKindInternal
RevealInternal

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

SelectionErrorInternal
TraitQueryModeInternal

The mode that trait queries run in.

VtableInternal

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.

WellFormedInternal
WhereClauseInternal

The following types:

Traits

ChalkContextLiftInternal
ExClauseFoldInternal
TraitEngineInternal
TraitEngineExtInternal

Functions

add_placeholder_noteInternal
do_normalize_predicatesInternal
elaborate_predicatesInternal
elaborate_trait_refInternal
elaborate_trait_refsInternal
expand_trait_aliasesInternal
find_associated_itemInternal

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

fully_normalizeInternal
normalizeInternal

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_predicatesInternal

Normalizes the predicates and checks whether they hold in an empty environment. 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_errorInternal

Normalizes the parameter environment, reporting errors if they occur.

normalize_projection_typeInternal

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_checkInternal

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

overlapping_implsInternal

If there are types that satisfy both impls, invokes on_overlap with a suitably-freshened ImplHeader with those types substituted. Otherwise, invokes no_overlap.

poly_project_and_unify_typeInternal

Evaluates constraints of the form:

predicates_for_genericsInternal

Creates predicate obligations from the generic bounds.

provideInternal
substitute_normalize_and_test_predicatesInternal
supertrait_def_idsInternal
supertraitsInternal
transitive_boundsInternal
translate_substsInternal

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).

type_known_to_meet_bound_modulo_regionsInternal

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).

vtable_methodsInternal

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

Type Definitions

ChalkCanonicalGoalInternal
ClausesInternal

Multiple clauses.

GoalInternal
GoalsInternal
ObligationsInternal
PolyDomainGoalInternal
PredicateObligationInternal
PredicateObligationsInternal
SelectionInternal
SelectionResultInternal

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

SupertraitsInternal
TraitObligationInternal
TraitObligationsInternal