Skip to main content

Module traits

Module traits 

Source
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ยง

BoundVarReplacer
DerivedCause
DerivedHostCause
FulfillmentError
ImplDerivedCause
ImplDerivedHostCause
ImplSourceUserDefinedData
Identifies a particular impl in the source, along with a set of generic parameters from the implโ€™s type/lifetime parameters. The nested vector corresponds to the nested obligations attached to the implโ€™s type parameters.
MatchExpressionArmCause
MismatchedProjectionTypes
Normalized
Obligation
An Obligation represents 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โ€ the Obligation. This process consists of either identifying an impl (e.g., impl Eq for i32) that satisfies the obligation, or else finding a bound that is in scope. The eventual result is usually a Selection (defined below).
ObligationCause
The reason why we incurred this obligation; used for error reporting.
ObligationCauseCodeHandle
A compact form of ObligationCauseCode.
PatternOriginExpr
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.
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.
ProjectionCacheKey
ProjectionCacheStorage
SignatureMismatchData
UncoveredTyParams

Enumsยง

AssocConstViolation
Reasons an associated const might not be dyn compatible.
BuiltinImplSource
CodegenObligationError
These are the error cases for codegen_select_candidate.
DynCompatibilityViolation
DynCompatibilityViolationSolution
EvaluateConstErr
EvaluationResult
The result of trait evaluation. The order is important here as the evaluation of a list is the maximum of the evaluations.
FulfillmentErrorCode
ImplSource
Given the successful resolution of an obligation, the ImplSource indicates 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.
IsFirstInputType
MethodViolation
Reasons a method might not be dyn-compatible.
ObligationCauseCode
OrphanCheckErr
OrphanCheckMode
OverflowError
Indicates that trait evaluation caused overflow and in which pass.
ProjectionCacheEntry
ReplaceRegions ๐Ÿ”’
ScrubbedTraitError
A trait error with most of its information removed. This is the error returned by an ObligationCtxt by 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
SkipLeakCheck
Whether to skip the leak check, as part of a future compatibility warning step.
TraitErrors
TraitQueryMode
The mode that trait queries run in.
WellFormedLoc
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. Foo in Option<Foo>).

Traitsยง

FromSolverError
TraitEngine

Functionsยง

do_normalize_clauses ๐Ÿ”’
elaborate
evaluate_const
Evaluates a type system constant returning a ConstKind::Error in 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 elaborate that only elaborates trait references that may define the given associated item with the name assoc_name. It uses the explicit_supertraits_containing_assoc_item query to avoid enumerating super-predicates that arenโ€™t related to assoc_item. This is used when resolving types like Self::Item or T::Item and 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 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 Aliasesยง

EvaluationCache
NormalizedTerm
ObligationInspector
A callback that can be provided to inspect_typeck. Invoked on evaluation of root obligations.
PolyTraitObligation
PredicateObligation
PredicateObligations
Selection
SelectionCache
SelectionResult
When performing resolution, it is typically the case that there can be one of three outcomes:
TraitObligation