pub struct InferCtxt<'tcx> {
Show 17 fields pub tcx: TyCtxt<'tcx>, pub defining_use_anchor: DefiningAnchor, pub considering_regions: bool, skip_leak_check: bool, pub inner: RefCell<InferCtxtInner<'tcx>>, lexical_region_resolutions: RefCell<Option<LexicalRegionResolutions<'tcx>>>, pub selection_cache: Cache<(ParamEnv<'tcx>, TraitPredicate<'tcx>), Result<Option<SelectionCandidate<'tcx>>, SelectionError<'tcx>>>, pub evaluation_cache: Cache<(ParamEnv<'tcx>, Binder<'tcx, TraitPredicate<'tcx>>), EvaluationResult>, pub reported_trait_errors: RefCell<IndexMap<Span, (Vec<Predicate<'tcx>>, ErrorGuaranteed), BuildHasherDefault<FxHasher>>>, pub reported_signature_mismatch: RefCell<HashSet<(Span, Option<Span>), BuildHasherDefault<FxHasher>>>, tainted_by_errors: Cell<Option<ErrorGuaranteed>>, err_count_on_creation: usize, stashed_err_count_on_creation: usize, universe: Cell<UniverseIndex>, pub intercrate: bool, next_trait_solver: bool, pub obligation_inspector: Cell<Option<fn(_: &InferCtxt<'tcx>, _: &Obligation<'tcx, Predicate<'tcx>>, _: Result<Certainty, NoSolution>)>>,
}

Fields§

§tcx: TyCtxt<'tcx>§defining_use_anchor: DefiningAnchor

The DefId of the item in whose context we are performing inference or typeck. It is used to check whether an opaque type use is a defining use.

If it is DefiningAnchor::Bubble, we can’t resolve opaque types here and need to bubble up the obligation. This frequently happens for short lived InferCtxt within queries. The opaque type obligations are forwarded to the outside until the end up in an InferCtxt for typeck or borrowck.

Its default value is DefiningAnchor::Error, this way it is easier to catch errors that might come up during inference or typeck.

§considering_regions: bool

Whether this inference context should care about region obligations in the root universe. Most notably, this is used during hir typeck as region solving is left to borrowck instead.

§skip_leak_check: bool§inner: RefCell<InferCtxtInner<'tcx>>§lexical_region_resolutions: RefCell<Option<LexicalRegionResolutions<'tcx>>>§selection_cache: Cache<(ParamEnv<'tcx>, TraitPredicate<'tcx>), Result<Option<SelectionCandidate<'tcx>>, SelectionError<'tcx>>>

Caches the results of trait selection. This cache is used for things that have to do with the parameters in scope.

§evaluation_cache: Cache<(ParamEnv<'tcx>, Binder<'tcx, TraitPredicate<'tcx>>), EvaluationResult>

Caches the results of trait evaluation.

§reported_trait_errors: RefCell<IndexMap<Span, (Vec<Predicate<'tcx>>, ErrorGuaranteed), BuildHasherDefault<FxHasher>>>

The set of predicates on which errors have been reported, to avoid reporting the same error twice.

§reported_signature_mismatch: RefCell<HashSet<(Span, Option<Span>), BuildHasherDefault<FxHasher>>>§tainted_by_errors: Cell<Option<ErrorGuaranteed>>§err_count_on_creation: usize§stashed_err_count_on_creation: usize§universe: Cell<UniverseIndex>§intercrate: bool

During coherence we have to assume that other crates may add additional impls which we currently don’t know about.

To deal with this evaluation, we should be conservative and consider the possibility of impls from outside this crate. This comes up primarily when resolving ambiguity. Imagine there is some trait reference $0: Bar where $0 is an inference variable. If intercrate is true, then we can never say for sure that this reference is not implemented, even if there are no impls at all for Bar, because $0 could be bound to some type that in a downstream crate that implements Bar.

Outside of coherence, we set this to false because we are only interested in types that the user could actually have written. In other words, we consider $0: Bar to be unimplemented if there is no type that the user could actually name that would satisfy it. This avoids crippling inference, basically.

§next_trait_solver: bool§obligation_inspector: Cell<Option<fn(_: &InferCtxt<'tcx>, _: &Obligation<'tcx, Predicate<'tcx>>, _: Result<Certainty, NoSolution>)>>

Trait Implementations§

source§

impl<'tcx> InferCtxtEvalExt<'tcx> for InferCtxt<'tcx>

source§

fn evaluate_root_goal( &self, goal: Goal<'tcx, Predicate<'tcx>>, generate_proof_tree: GenerateProofTree ) -> (Result<(bool, Certainty, Vec<Goal<'tcx, Predicate<'tcx>>>), NoSolution>, Option<GoalEvaluation<'tcx>>)

Evaluates a goal from outside of the trait solver. Read more
source§

impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx>

source§

fn implied_bounds_tys_compat( &'a self, param_env: ParamEnv<'tcx>, body_id: LocalDefId, tys: &'a FxIndexSet<Ty<'tcx>>, compat: bool ) -> BoundsCompat<'a, 'tcx>

Do NOT call this directly.
source§

fn implied_bounds_tys( &'a self, param_env: ParamEnv<'tcx>, body_id: LocalDefId, tys: &'a FxIndexSet<Ty<'tcx>> ) -> Bounds<'a, 'tcx>

If -Z no-implied-bounds-compat is set, calls implied_bounds_tys_compat with compat set to true, otherwise false.
source§

impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx>

source§

fn type_is_copy_modulo_regions( &self, param_env: ParamEnv<'tcx>, ty: Ty<'tcx> ) -> bool

source§

fn type_is_sized_modulo_regions( &self, param_env: ParamEnv<'tcx>, ty: Ty<'tcx> ) -> bool

source§

fn type_implements_trait( &self, trait_def_id: DefId, params: impl IntoIterator<Item: Into<GenericArg<'tcx>>>, param_env: ParamEnv<'tcx> ) -> EvaluationResult

Check whether a ty implements given trait(trait_def_id) without side-effects. Read more
source§

fn type_implements_trait_shallow( &self, trait_def_id: DefId, ty: Ty<'tcx>, param_env: ParamEnv<'tcx> ) -> Option<Vec<FulfillmentError<'tcx>>>

Returns Some if a type implements a trait shallowly, without side-effects, along with any errors that would have been reported upon further obligation processing. Read more
source§

impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx>

source§

fn predicate_may_hold(&self, obligation: &PredicateObligation<'tcx>) -> bool

Evaluates whether the predicate can be satisfied (by any means) in the given ParamEnv.

source§

fn predicate_must_hold_considering_regions( &self, obligation: &PredicateObligation<'tcx> ) -> bool

Evaluates whether the predicate can be satisfied in the given ParamEnv, and returns false if not certain. However, this is not entirely accurate if inference variables are involved.

This version may conservatively fail when outlives obligations are required. Therefore, this version should only be used for optimizations or diagnostics and be treated as if it can always return false.

§Example
trait Trait {}

fn check<T: Trait>() {}

fn foo<T: 'static>()
where
    &'static T: Trait,
{
    // Evaluating `&'?0 T: Trait` adds a `'?0: 'static` outlives obligation,
    // which means that `predicate_must_hold_considering_regions` will return
    // `false`.
    check::<&'_ T>();
}
source§

fn predicate_must_hold_modulo_regions( &self, obligation: &PredicateObligation<'tcx> ) -> bool

Evaluates whether the predicate can be satisfied in the given ParamEnv, and returns false if not certain. However, this is not entirely accurate if inference variables are involved.

This version ignores all outlives constraints.

source§

fn evaluate_obligation( &self, obligation: &PredicateObligation<'tcx> ) -> Result<EvaluationResult, OverflowError>

Evaluate a given predicate, capturing overflow and propagating it back.

source§

fn evaluate_obligation_no_overflow( &self, obligation: &PredicateObligation<'tcx> ) -> EvaluationResult

source§

impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx>

source§

fn get_fn_like_arguments( &self, node: Node<'_> ) -> Option<(Span, Option<Span>, Vec<ArgKind>)>

Given some node representing a fn-like thing in the HIR map, returns a span and ArgKind information that describes the arguments it expects. This can be supplied to report_arg_count_mismatch.

source§

fn report_arg_count_mismatch( &self, span: Span, found_span: Option<Span>, expected_args: Vec<ArgKind>, found_args: Vec<ArgKind>, is_closure: bool, closure_arg_span: Option<Span> ) -> DiagnosticBuilder<'tcx>

Reports an error when the number of arguments needed by a trait match doesn’t match the number that the expression provides.

source§

fn type_implements_fn_trait( &self, param_env: ParamEnv<'tcx>, ty: Binder<'tcx, Ty<'tcx>>, polarity: ImplPolarity ) -> Result<(ClosureKind, Binder<'tcx, Ty<'tcx>>), ()>

Checks if the type implements one of Fn, FnMut, or FnOnce in that order, and returns the generic type corresponding to the argument of that trait (corresponding to the closure arguments).
source§

impl<'tcx> InferCtxtRegionExt<'tcx> for InferCtxt<'tcx>

source§

fn resolve_regions( &self, outlives_env: &OutlivesEnvironment<'tcx> ) -> Vec<RegionResolutionError<'tcx>>

Resolve regions, using the deep normalizer to normalize any type-outlives obligations in the process. This is in rustc_trait_selection because we need to normalize. Read more
source§

impl<'tcx> InferCtxtSelectExt<'tcx> for InferCtxt<'tcx>

source§

impl<'tcx> ProofTreeInferCtxtExt<'tcx> for InferCtxt<'tcx>

source§

fn visit_proof_tree<V: ProofTreeVisitor<'tcx>>( &self, goal: Goal<'tcx, Predicate<'tcx>>, visitor: &mut V ) -> ControlFlow<V::BreakTy>

Auto Trait Implementations§

§

impl<'tcx> !RefUnwindSafe for InferCtxt<'tcx>

§

impl<'tcx> !Send for InferCtxt<'tcx>

§

impl<'tcx> !Sync for InferCtxt<'tcx>

§

impl<'tcx> Unpin for InferCtxt<'tcx>

§

impl<'tcx> !UnwindSafe for InferCtxt<'tcx>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 776 bytes