Struct rustc_trait_selection::infer::InferCtxt
source · pub struct InferCtxt<'tcx> {Show 15 fields
pub tcx: TyCtxt<'tcx>,
pub defining_use_anchor: DefiningAnchor,
pub considering_regions: bool,
pub inner: RefCell<InferCtxtInner<'tcx>>,
skip_leak_check: Cell<bool>,
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<HashMap<Span, Vec<Predicate<'tcx>, Global>, BuildHasherDefault<FxHasher>>>,
pub reported_closure_mismatch: RefCell<HashSet<(Span, Option<Span>), BuildHasherDefault<FxHasher>>>,
tainted_by_errors: Cell<Option<ErrorGuaranteed>>,
err_count_on_creation: usize,
in_snapshot: Cell<bool>,
universe: Cell<UniverseIndex>,
normalize_fn_sig_for_diagnostic: Option<Rc<dyn Fn(&InferCtxt<'tcx>, Binder<'tcx, FnSig<'tcx>>) + 'static>>,
}Fields
tcx: TyCtxt<'tcx>defining_use_anchor: DefiningAnchorThe 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.
It is default value is DefiningAnchor::Error, this way it is easier to catch errors that
might come up during inference or typeck.
considering_regions: boolWhether 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.
inner: RefCell<InferCtxtInner<'tcx>>skip_leak_check: Cell<bool>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<HashMap<Span, Vec<Predicate<'tcx>, Global>, BuildHasherDefault<FxHasher>>>the set of predicates on which errors have been reported, to avoid reporting the same error twice.
reported_closure_mismatch: RefCell<HashSet<(Span, Option<Span>), BuildHasherDefault<FxHasher>>>tainted_by_errors: Cell<Option<ErrorGuaranteed>>err_count_on_creation: usizein_snapshot: Cell<bool>universe: Cell<UniverseIndex>normalize_fn_sig_for_diagnostic: Option<Rc<dyn Fn(&InferCtxt<'tcx>, Binder<'tcx, FnSig<'tcx>>) + 'static>>Trait Implementations
sourceimpl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx>
impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx>
sourcefn implied_outlives_bounds(
&self,
param_env: ParamEnv<'tcx>,
body_id: HirId,
ty: Ty<'tcx>
) -> Vec<OutlivesBound<'tcx>>
fn implied_outlives_bounds(
&self,
param_env: ParamEnv<'tcx>,
body_id: HirId,
ty: Ty<'tcx>
) -> Vec<OutlivesBound<'tcx>>
Implied bounds are region relationships that we deduce automatically. The idea is that (e.g.) a caller must check that a function’s argument types are well-formed immediately before calling that fn, and hence the callee can assume that its argument types are well-formed. This may imply certain relationships between generic parameters. For example:
fn foo<'a,T>(x: &'a T) {}can only be called with a 'a and T such that &'a T is WF.
For &'a T to be WF, T: 'a must hold. So we can assume T: 'a.
Parameters
param_env, the where-clauses in scopebody_id, the body-id to use when normalizing assoc types. Note that this may cause outlives obligations to be injected into the inference context with this body-id.ty, the type that we are supposed to assume is WF.
fn implied_bounds_tys(
&'a self,
param_env: ParamEnv<'tcx>,
body_id: HirId,
tys: FxHashSet<Ty<'tcx>>
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'a
sourceimpl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx>
impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx>
sourcefn partially_normalize_associated_types_in<T>(
&self,
cause: ObligationCause<'tcx>,
param_env: ParamEnv<'tcx>,
value: T
) -> InferOk<'tcx, T>where
T: TypeFoldable<'tcx>,
fn partially_normalize_associated_types_in<T>(
&self,
cause: ObligationCause<'tcx>,
param_env: ParamEnv<'tcx>,
value: T
) -> InferOk<'tcx, T>where
T: TypeFoldable<'tcx>,
Normalizes associated types in value, potentially returning
new obligations that must further be processed.
fn type_is_copy_modulo_regions(
&self,
param_env: ParamEnv<'tcx>,
ty: Ty<'tcx>,
span: Span
) -> bool
fn type_is_sized_modulo_regions(
&self,
param_env: ParamEnv<'tcx>,
ty: Ty<'tcx>,
span: Span
) -> bool
sourcefn type_implements_trait(
&self,
trait_def_id: DefId,
ty: Ty<'tcx>,
params: SubstsRef<'tcx>,
param_env: ParamEnv<'tcx>
) -> EvaluationResult
fn type_implements_trait(
&self,
trait_def_id: DefId,
ty: Ty<'tcx>,
params: SubstsRef<'tcx>,
param_env: ParamEnv<'tcx>
) -> EvaluationResult
ty implements given trait(trait_def_id).
The inputs are: Read moresourceimpl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx>
impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx>
sourcefn get_fn_like_arguments(&self, node: Node<'_>) -> Option<(Span, Vec<ArgKind>)>
fn get_fn_like_arguments(&self, node: Node<'_>) -> 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.
sourcefn report_arg_count_mismatch(
&self,
span: Span,
found_span: Option<Span>,
expected_args: Vec<ArgKind>,
found_args: Vec<ArgKind>,
is_closure: bool
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>
fn report_arg_count_mismatch(
&self,
span: Span,
found_span: Option<Span>,
expected_args: Vec<ArgKind>,
found_args: Vec<ArgKind>,
is_closure: bool
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>
Reports an error when the number of arguments needed by a trait match doesn’t match the number that the expression provides.
sourcefn type_implements_fn_trait(
&self,
param_env: ParamEnv<'tcx>,
ty: Binder<'tcx, Ty<'tcx>>,
constness: BoundConstness,
polarity: ImplPolarity
) -> Result<(ClosureKind, Binder<'tcx, Ty<'tcx>>), ()>
fn type_implements_fn_trait(
&self,
param_env: ParamEnv<'tcx>,
ty: Binder<'tcx, Ty<'tcx>>,
constness: BoundConstness,
polarity: ImplPolarity
) -> Result<(ClosureKind, Binder<'tcx, Ty<'tcx>>), ()>
Fn, FnMut, or FnOnce
in that order, and returns the generic type corresponding to the
argument of that trait (corresponding to the closure arguments). Read moresourceimpl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx>
impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx>
sourcefn predicate_may_hold(&self, obligation: &PredicateObligation<'tcx>) -> bool
fn predicate_may_hold(&self, obligation: &PredicateObligation<'tcx>) -> bool
Evaluates whether the predicate can be satisfied (by any means)
in the given ParamEnv.
sourcefn predicate_must_hold_considering_regions(
&self,
obligation: &PredicateObligation<'tcx>
) -> bool
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.
sourcefn predicate_must_hold_modulo_regions(
&self,
obligation: &PredicateObligation<'tcx>
) -> bool
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.
sourcefn evaluate_obligation(
&self,
obligation: &PredicateObligation<'tcx>
) -> Result<EvaluationResult, OverflowError>
fn evaluate_obligation(
&self,
obligation: &PredicateObligation<'tcx>
) -> Result<EvaluationResult, OverflowError>
Evaluate a given predicate, capturing overflow and propagating it back.
fn evaluate_obligation_no_overflow(
&self,
obligation: &PredicateObligation<'tcx>
) -> EvaluationResult
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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: 728 bytes