Skip to main content

SolverContext

Struct SolverContext 

Source
#[repr(transparent)]
pub(crate) struct SolverContext<'db>(pub(crate) InferCtxt<'db>);

Tuple Fields§

§0: InferCtxt<'db>

Methods from Deref<Target = InferCtxt<'db>>§

Source

pub fn at<'a>( &'a self, cause: &'a ObligationCause, param_env: ParamEnv<'db>, ) -> At<'a, 'db>

Source

pub fn fork(&self) -> Self

Forks the inference context, creating a new inference context with the same inference variables in the same state. This can be used to “branch off” many tests from the same common state.

Source

pub fn fork_with_typing_mode( &self, typing_mode: TypingMode<DbInterner<'db>>, ) -> Self

Forks the inference context, creating a new inference context with the same inference variables in the same state, except possibly changing the intercrate mode. This can be used to “branch off” many tests from the same common state. Used in negative coherence.

Source

pub fn canonicalize_query<V>( &self, value: V, query_state: &mut OriginalQueryValues<'db>, ) -> Canonical<'db, V>
where V: TypeFoldable<DbInterner<'db>>,

Canonicalizes a query value V. When we canonicalize a query, we not only canonicalize unbound inference variables, but we also replace all free regions whatsoever. So for example a query like T: Trait<'static> would be canonicalized to

T: Trait<'?0>

with a mapping M that maps '?0 to 'static.

To get a good understanding of what is happening here, check out the chapter in the rustc dev guide.

Source

pub fn canonicalize_response<V>(&self, value: V) -> Canonical<'db, V>
where V: TypeFoldable<DbInterner<'db>>,

Canonicalizes a query response V. When we canonicalize a query response, we only canonicalize unbound inference variables, and we leave other free regions alone. So, continuing with the example from canonicalize_query, if there was an input query T: Trait<'static>, it would have been canonicalized to

T: Trait<'?0>

with a mapping M that maps '?0 to 'static. But if we found that there exists only one possible impl of Trait, and it looks like

impl<T> Trait<'static> for T { .. }

then we would prepare a query result R that (among other things) includes a mapping to '?0 := 'static. When canonicalizing this query result R, we would leave this reference to 'static alone.

To get a good understanding of what is happening here, check out the chapter in the rustc dev guide.

Source

pub fn canonicalize_user_type_annotation<V>( &self, value: V, ) -> Canonical<'db, V>
where V: TypeFoldable<DbInterner<'db>>,

Source

pub fn make_query_response_ignoring_pending_obligations<T>( &self, inference_vars: CanonicalVarValues<'db>, answer: T, prev_entries: OpaqueTypeStorageEntries, ) -> Canonical<'db, QueryResponse<'db, T>>
where T: TypeFoldable<DbInterner<'db>>,

A version of make_canonicalized_query_response that does not pack in obligations, for contexts that want to drop pending obligations instead of treating them as an ambiguity (e.g. typeck “probing” contexts).

If you DO want to keep track of pending obligations (which include all region obligations, so this includes all cases that care about regions) with this function, you have to do it yourself, by e.g., having them be a part of the answer.

Source

pub fn instantiate_query_response_and_region_obligations<R>( &self, cause: &ObligationCause, param_env: ParamEnv<'db>, original_values: &OriginalQueryValues<'db>, query_response: &Canonical<'db, QueryResponse<'db, R>>, ) -> InferResult<'db, R>
where R: TypeFoldable<DbInterner<'db>>,

Given the (canonicalized) result to a canonical query, instantiates the result so it can be used, plugging in the values from the canonical query. (Note that the result may have been ambiguous; you should check the certainty level of the query before applying this function.)

To get a good understanding of what is happening here, check out the chapter in the rustc dev guide.

Source

fn query_response_instantiation<R>( &self, cause: &ObligationCause, param_env: ParamEnv<'db>, original_values: &OriginalQueryValues<'db>, query_response: &Canonical<'db, QueryResponse<'db, R>>, ) -> InferResult<'db, CanonicalVarValues<'db>>
where R: Debug + TypeFoldable<DbInterner<'db>>,

Given the original values and the (canonicalized) result from computing a query, returns an instantiation that can be applied to the query result to convert the result back into the original namespace.

The instantiation also comes accompanied with subobligations that arose from unification; these might occur if (for example) we are doing lazy normalization and the value assigned to a type variable is unified with an unnormalized projection.

Source

fn query_response_instantiation_guess<R>( &self, cause: &ObligationCause, param_env: ParamEnv<'db>, original_values: &OriginalQueryValues<'db>, query_response: &Canonical<'db, QueryResponse<'db, R>>, ) -> InferResult<'db, CanonicalVarValues<'db>>
where R: Debug + TypeFoldable<DbInterner<'db>>,

Given the original values and the (canonicalized) result from computing a query, returns a guess at an instantiation that can be applied to the query result to convert the result back into the original namespace. This is called a guess because it uses a quick heuristic to find the values for each canonical variable; if that quick heuristic fails, then we will instantiate fresh inference variables for each canonical variable instead. Therefore, the result of this method must be properly unified

Source

fn unify_query_response_instantiation_guess<R>( &self, cause: &ObligationCause, param_env: ParamEnv<'db>, original_values: &OriginalQueryValues<'db>, result_args: &CanonicalVarValues<'db>, query_response: &Canonical<'db, QueryResponse<'db, R>>, ) -> InferResult<'db, ()>
where R: Debug + TypeFoldable<DbInterner<'db>>,

Given a “guess” at the values for the canonical variables in the input, try to unify with the actual values found in the query result. Often, but not always, this is a no-op, because we already found the mapping in the “guessing” step.

See also: Self::query_response_instantiation_guess

Source

fn unify_canonical_vars( &self, cause: &ObligationCause, param_env: ParamEnv<'db>, variables1: &OriginalQueryValues<'db>, variables2: impl Fn(BoundVar) -> GenericArg<'db>, ) -> InferResult<'db, ()>

Given two sets of values for the same set of canonical variables, unify them. The second set is produced lazily by supplying indices from the first set.

Source

pub fn instantiate_canonical<T>( &self, span: Span, canonical: &Canonical<'db, T>, ) -> (T, CanonicalVarValues<'db>)
where T: TypeFoldable<DbInterner<'db>>,

Creates an instantiation S for the canonical value with fresh inference variables and placeholders then applies it to the canonical value. Returns both the instantiated result and the instantiation S.

This can be invoked as part of constructing an inference context at the start of a query (see InferCtxtBuilder::build_with_canonical). It basically brings the canonical value “into scope” within your new infcx.

At the end of processing, the instantiation S (once canonicalized) then represents the values that you computed for each of the canonical inputs to your query.

Source

pub fn instantiate_canonical_var( &self, span: Span, cv_info: CanonicalVarKind<DbInterner<'db>>, previous_var_values: &[GenericArg<'db>], universe_map: impl Fn(UniverseIndex) -> UniverseIndex, ) -> GenericArg<'db>

Given the “info” about a canonical variable, creates a fresh variable for it. If this is an existentially quantified variable, then you’ll get a new inference variable; if it is a universally quantified variable, you get a placeholder.

FIXME(-Znext-solver): This is public because it’s used by the new trait solver which has a different canonicalization routine. We should somehow deduplicate all of this.

Source

pub fn register_hidden_type_in_storage( &self, opaque_type_key: OpaqueTypeKey<'db>, hidden_ty: OpaqueHiddenType<'db>, ) -> Option<Ty<'db>>

Insert a hidden type into the opaque type storage, making sure it hasn’t previously been defined. This does not emit any constraints and it’s the responsibility of the caller to make sure that the item bounds of the opaque are checked.

Source

pub fn register_outlives_constraint( &self, OutlivesPredicate: ArgOutlivesPredicate<'db>, )

Source

pub fn register_region_outlives_constraint( &self, OutlivesPredicate: RegionOutlivesPredicate<'db>, )

Source

pub fn register_type_outlives_constraint_inner( &self, obligation: TypeOutlivesConstraint<'db>, )

Registers that the given region obligation must be resolved from within the scope of body_id. These regions are enqueued and later processed by regionck, when full type information is available (see region_obligations field for more information).

Source

pub fn register_type_outlives_constraint( &self, sup_type: Ty<'db>, sub_region: Region<'db>, )

Source

pub fn register_region_assumption(&self, assumption: ArgOutlivesPredicate<'db>)

Source

pub fn instantiate_ty_var<R: PredicateEmittingRelation<InferCtxt<'db>>>( &self, relation: &mut R, target_is_expected: bool, target_vid: TyVid, instantiation_variance: Variance, source_ty: Ty<'db>, ) -> RelateResult<'db, ()>

The idea is that we should ensure that the type variable target_vid is equal to, a subtype of, or a supertype of source_ty.

For this, we will instantiate target_vid with a generalized version of source_ty. Generalization introduces other inference variables wherever subtyping could occur. This also does the occurs checks, detecting whether instantiating target_vid would result in a cyclic type. We eagerly error in this case.

This is not expected to be used anywhere except for an implementation of TypeRelation. Do not use this, and instead please use At::eq, for all other usecases (i.e. setting the value of a type var).

Source

pub(crate) fn instantiate_const_var<R: PredicateEmittingRelation<InferCtxt<'db>>>( &self, relation: &mut R, target_is_expected: bool, target_vid: ConstVid, source_ct: Const<'db>, ) -> RelateResult<'db, ()>

Instantiates the const variable target_vid with the given constant.

This also tests if the given const ct contains an inference variable which was previously unioned with target_vid. If this is the case, inferring target_vid to ct would result in an infinite type as we continuously replace an inference variable in ct with ct itself.

This is especially important as unevaluated consts use their parents generics. They therefore often contain unused args, making these errors far more likely.

A good example of this is the following:

#![feature(generic_const_exprs)]

fn bind<const N: usize>(value: [u8; N]) -> [u8; 3 + 4] {
    todo!()
}

fn main() {
    let mut arr = Default::default();
    arr = bind(arr);
}

Here 3 + 4 ends up as ConstKind::Unevaluated which uses the generics of fn bind (meaning that its args contain N).

bind(arr) now infers that the type of arr must be [u8; N]. The assignment arr = bind(arr) now tries to equate N with 3 + 4.

As 3 + 4 contains N in its args, this must not succeed.

See tests/ui/const-generics/occurs-check/ for more examples where this is relevant.

Source

fn generalize<T: Into<Term<'db>> + Relate<DbInterner<'db>>>( &self, span: Span, structurally_relate_aliases: StructurallyRelateAliases, target_vid: impl Into<TermVid>, ambient_variance: Variance, source_term: T, ) -> RelateResult<'db, Generalization<T>>

Attempts to generalize source_term for the type variable target_vid. This checks for cycles – that is, whether source_term references target_vid.

Source

pub fn enter_forall_and_leak_universe<T>(&self, binder: Binder<'db, T>) -> T
where T: TypeFoldable<DbInterner<'db>> + Clone,

Replaces all bound variables (lifetimes, types, and constants) bound by binder with placeholder variables in a new universe. This means that the new placeholders can only be named by inference variables created after this method has been called.

This is the first step of checking subtyping when higher-ranked things are involved. For more details visit the relevant sections of the rustc dev guide.

fn enter_forall should be preferred over this method.

Source

pub fn enter_forall<T, U>( &self, forall: Binder<'db, T>, f: impl FnOnce(T) -> U, ) -> U
where T: TypeFoldable<DbInterner<'db>> + Clone,

Replaces all bound variables (lifetimes, types, and constants) bound by binder with placeholder variables in a new universe and then calls the closure f with the instantiated value. The new placeholders can only be named by inference variables created inside of the closure f or afterwards.

This is the first step of checking subtyping when higher-ranked things are involved. For more details visit the relevant sections of the rustc dev guide.

This method should be preferred over fn enter_forall_and_leak_universe.

Source

pub(crate) fn select( &self, obligation: &Obligation<'db, TraitPredicate<'db>>, ) -> Result<Option<ImplSource<'db, Obligation<'db, Predicate<'db>>>>, SelectionError<'db>>

Source

pub fn fudge_inference_if_ok<T, E, F>(&self, f: F) -> Result<T, E>
where F: FnOnce() -> Result<T, E>, T: TypeFoldable<DbInterner<'db>>,

This rather funky routine is used while processing expected types. What happens here is that we want to propagate a coercion through the return type of a fn to its argument. Consider the type of Option::Some, which is basically for<T> fn(T) -> Option<T>. So if we have an expression Some(&[1, 2, 3]), and that has the expected type Option<&[u32]>, we would like to type check &[1, 2, 3] with the expectation of &[u32]. This will cause us to coerce from &[u32; 3] to &[u32] and make the users life more pleasant.

The way we do this is using fudge_inference_if_ok. What the routine actually does is to start a snapshot and execute the closure f. In our example above, what this closure will do is to unify the expectation (Option<&[u32]>) with the actual return type (Option<?T>, where ?T represents the variable instantiated for T). This will cause ?T to be unified with &?a [u32], where ?a is a fresh lifetime variable. The input type (?T) is then returned by f().

At this point, fudge_inference_if_ok will normalize all type variables, converting ?T to &?a [u32] and end the snapshot. The problem is that we can’t just return this type out, because it references the region variable ?a, and that region variable was popped when we popped the snapshot.

So what we do is to keep a list (region_vars, in the code below) of region variables created during the snapshot (here, ?a). We fold the return value and replace any such regions with a new region variable (e.g., ?b) and return the result (&?b [u32]). This can then be used as the expectation for the fn argument.

The important point here is that, for soundness purposes, the regions in question are not particularly important. We will use the expected types to guide coercions, but we will still type-check the resulting types from those coercions against the actual types (?T, Option<?T>) – and remember that after the snapshot is popped, the variable ?T is no longer unified.

Source

fn fudge_inference<T: TypeFoldable<DbInterner<'db>>>( &self, snapshot_vars: SnapshotVarData, value: T, ) -> T

Source

fn variable_lengths(&self) -> VariableLengths

Source

pub fn in_snapshot(&self) -> bool

Source

pub fn num_open_snapshots(&self) -> usize

Source

pub fn start_snapshot(&self) -> CombinedSnapshot

Source

pub fn rollback_to(&self, snapshot: CombinedSnapshot)

Source

pub fn commit_from(&self, snapshot: CombinedSnapshot)

Source

pub fn commit_if_ok<T, E, F>(&self, f: F) -> Result<T, E>
where F: FnOnce(&CombinedSnapshot) -> Result<T, E>,

Execute f and commit the bindings if closure f returns Ok(_).

Source

pub fn probe<R, F>(&self, f: F) -> R
where F: FnOnce(&CombinedSnapshot) -> R,

Execute f then unroll any bindings it creates.

Source

pub fn region_constraints_added_in_snapshot( &self, snapshot: &CombinedSnapshot, ) -> bool

Scan the constraints produced since snapshot and check whether we added any region constraints.

Source

pub fn opaque_types_added_in_snapshot( &self, snapshot: &CombinedSnapshot, ) -> bool

Source

pub fn typing_mode_raw(&self) -> TypingMode<'db>

Source

pub fn typing_mode_unchecked(&self) -> TypingMode<'db>

Source

pub fn predicate_may_hold( &self, obligation: &Obligation<'db, Predicate<'db>>, ) -> bool

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

Source

pub fn predicate_may_hold_opaque_types_jank( &self, obligation: &Obligation<'db, Predicate<'db>>, ) -> bool

See the comment on GeneralAutoderef::overloaded_deref_ty for more details.

Source

pub(crate) fn insert_type_vars<T>(&self, ty: T) -> T
where T: TypeFoldable<DbInterner<'db>>,

Source

pub fn predicate_must_hold_considering_regions( &self, obligation: &Obligation<'db, Predicate<'db>>, ) -> 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

pub fn predicate_must_hold_modulo_regions( &self, obligation: &Obligation<'db, Predicate<'db>>, ) -> 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

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

Check whether a ty implements given trait(trait_def_id) without side-effects.

The inputs are:

  • the def-id of the trait
  • the type parameters of the trait, including the self-type
  • the parameter environment

Invokes evaluate_obligation, so in the event that evaluating Ty: Trait causes overflow, EvaluatedToAmbigStackDependent will be returned.

type_implements_trait is a convenience function for simple cases like

let copy_trait = infcx.tcx.require_lang_item(LangItem::Copy, span);
let implements_copy = infcx.type_implements_trait(copy_trait, [ty], param_env)
.must_apply_modulo_regions();

In most cases you should instead create an Obligation and check whether it holds via evaluate_obligation or one of its helper functions like predicate_must_hold_modulo_regions, because it properly handles higher ranked traits and it is more convenient and safer when your params are inside a Binder.

Source

fn evaluate_obligation( &self, obligation: &Obligation<'db, Predicate<'db>>, ) -> EvaluationResult

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

Source

pub fn can_eq<T: ToTrace<'db>>( &self, param_env: ParamEnv<'db>, a: T, b: T, ) -> bool

Source

pub fn goal_may_hold_opaque_types_jank( &self, goal: Goal<'db, Predicate<'db>>, ) -> bool

See the comment on GeneralAutoderef::overloaded_deref_ty for more details.

Source

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

Source

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

Source

pub fn type_is_use_cloned_modulo_regions( &self, param_env: ParamEnv<'db>, ty: Ty<'db>, ) -> bool

Source

pub fn unresolved_variables(&self) -> Vec<Ty<'db>>

Source

pub fn sub_regions(&self, a: Region<'db>, b: Region<'db>)

Source

pub fn coerce_predicate( &self, cause: &ObligationCause, param_env: ParamEnv<'db>, predicate: PolyCoercePredicate<'db>, ) -> Result<InferResult<'db, ()>, (TyVid, TyVid)>

Processes a Coerce predicate from the fulfillment context. This is NOT the preferred way to handle coercion, which is to invoke FnCtxt::coerce or a similar method (see coercion.rs).

This method here is actually a fallback that winds up being invoked when FnCtxt::coerce encounters unresolved type variables and records a coercion predicate. Presently, this method is equivalent to subtype_predicate – that is, “coercing” a to b winds up actually requiring a <: b. This is of course a valid coercion, but it’s not as flexible as FnCtxt::coerce would be.

(We may refactor this in the future, but there are a number of practical obstacles. Among other things, FnCtxt::coerce presently records adjustments that are required on the HIR in order to perform the coercion, and we don’t currently have a way to manage that.)

Source

pub fn subtype_predicate( &self, cause: &ObligationCause, param_env: ParamEnv<'db>, predicate: PolySubtypePredicate<'db>, ) -> Result<InferResult<'db, ()>, (TyVid, TyVid)>

Source

pub fn region_outlives_predicate( &self, _cause: &ObligationCause, predicate: PolyRegionOutlivesPredicate<'db>, )

Source

pub fn num_ty_vars(&self) -> usize

Number of type variables created so far.

Source

pub fn next_ty_var(&self, span: Span) -> Ty<'db>

Source

pub fn next_ty_vid(&self, span: Span) -> TyVid

Source

pub fn next_ty_var_id_in_universe( &self, universe: UniverseIndex, span: Span, ) -> TyVid

Source

pub fn next_ty_var_in_universe( &self, universe: UniverseIndex, span: Span, ) -> Ty<'db>

Source

pub fn next_const_var(&self, span: Span) -> Const<'db>

Source

pub fn next_const_vid(&self, span: Span) -> ConstVid

Source

pub fn next_const_vid_in_universe( &self, universe: UniverseIndex, span: Span, ) -> ConstVid

Source

pub fn next_const_var_in_universe( &self, universe: UniverseIndex, span: Span, ) -> Const<'db>

Source

pub fn next_int_var(&self) -> Ty<'db>

Source

pub fn next_int_vid(&self) -> IntVid

Source

pub fn next_float_var(&self) -> Ty<'db>

Source

pub fn next_float_vid(&self) -> FloatVid

Source

pub fn next_region_var(&self, span: Span) -> Region<'db>

Creates a fresh region variable with the next available index. The variable will be created in the maximum universe created thus far, allowing it to name any region created thus far.

Source

pub fn next_region_vid(&self, span: Span) -> RegionVid

Source

pub fn next_region_var_in_universe( &self, universe: UniverseIndex, span: Span, ) -> Region<'db>

Creates a fresh region variable with the next available index in the given universe; typically, you can use next_region_var and just use the maximal universe.

Source

pub fn next_term_var_of_kind(&self, term: Term<'db>, span: Span) -> Term<'db>

Source

pub fn universe_of_region(&self, r: Region<'db>) -> UniverseIndex

Return the universe that the region r was created in. For most regions (e.g., 'static, named regions from the user, etc) this is the root universe U0. For inference variables or placeholders, however, it will return the universe which they are associated.

Source

pub fn num_region_vars(&self) -> usize

Number of region variables created so far.

Source

pub fn var_for_def(&self, id: GenericParamId, span: Span) -> GenericArg<'db>

Source

pub fn fresh_args_for_item( &self, span: Span, def_id: SolverDefId<'db>, ) -> GenericArgs<'db>

Given a set of generics defined on a type or impl, returns the generic parameters mapping each type/region parameter to a fresh inference variable.

Source

pub fn fill_rest_fresh_args( &self, span: Span, def_id: SolverDefId<'db>, first: impl IntoIterator<Item = GenericArg<'db>>, ) -> GenericArgs<'db>

Like Self::fresh_args_for_item, but first uses the args from first.

Source

pub fn tainted_by_errors(&self) -> Option<ErrorGuaranteed>

Returns true if errors have been reported since this infcx was created. This is sometimes used as a heuristic to skip reporting errors that often occur as a result of earlier errors, but where it’s hard to be 100% sure (e.g., unresolved inference variables, regionck errors).

Source

pub fn set_tainted_by_errors(&self, e: ErrorGuaranteed)

Set the “tainted by errors” flag to true. We call this when we observe an error from a prior pass.

Source

pub fn take_opaque_types( &self, ) -> impl IntoIterator<Item = (OpaqueTypeKey<'db>, OpaqueHiddenType<'db>)> + use<'db>

Source

pub fn clone_opaque_types( &self, ) -> Vec<(OpaqueTypeKey<'db>, OpaqueHiddenType<'db>)>

Source

pub fn has_opaques_with_sub_unified_hidden_type(&self, ty_vid: TyVid) -> bool

Source

pub fn can_define_opaque_ty(&self, id: impl Into<SolverDefId<'db>>) -> bool

Source

pub fn probe_ty_var(&self, vid: TyVid) -> Result<Ty<'db>, UniverseIndex>

If TyVar(vid) resolves to a type, return that type. Else, return the universe index of TyVar(vid).

Source

pub fn shallow_resolve(&self, ty: Ty<'db>) -> Ty<'db>

Source

pub fn shallow_resolve_const(&self, ct: Const<'db>) -> Const<'db>

Source

pub fn shallow_resolve_term(&self, term: Term<'db>) -> Term<'db>

Source

pub fn root_var(&self, var: TyVid) -> TyVid

Source

pub fn root_const_var(&self, var: ConstVid) -> ConstVid

Source

pub fn opportunistic_resolve_int_var(&self, vid: IntVid) -> Ty<'db>

Resolves an int var to a rigid int type, if it was constrained to one, or else the root int var in the unification table.

Source

pub fn resolve_int_var(&self, vid: IntVid) -> Option<Ty<'db>>

Source

pub fn opportunistic_resolve_float_var(&self, vid: FloatVid) -> Ty<'db>

Resolves a float var to a rigid int type, if it was constrained to one, or else the root float var in the unification table.

Source

pub fn resolve_float_var(&self, vid: FloatVid) -> Option<Ty<'db>>

Source

pub fn resolve_vars_if_possible<T>(&self, value: T) -> T
where T: TypeFoldable<DbInterner<'db>>,

Where possible, replaces type/const variables in value with their final value. Note that region variables are unaffected. If a type/const variable has not been unified, it is left as is. This is an idempotent operation that does not affect inference state in any way and so you can do it at will.

Source

pub fn probe_const_var( &self, vid: ConstVid, ) -> Result<Const<'db>, UniverseIndex>

Source

pub fn type_var_span(&self, vid: TyVid) -> Span

Returns the span of the type variable identified by vid.

No attempt is made to resolve vid to its root variable.

Source

pub fn const_var_span(&self, vid: ConstVid) -> Option<Span>

Returns the span of the const variable identified by vid

Source

pub fn instantiate_binder_with_fresh_vars<T>( &self, span: Span, _lbrct: BoundRegionConversionTime<'db>, value: Binder<'db, T>, ) -> T
where T: TypeFoldable<DbInterner<'db>> + Clone,

Source

pub fn closure_kind(&self, closure_ty: Ty<'db>) -> Option<ClosureKind>

Obtains the latest type of the given closure; this may be a closure in the current function, in which case its ClosureKind may not yet be known.

Source

pub fn universe(&self) -> UniverseIndex

Source

pub fn create_next_universe(&self) -> UniverseIndex

Creates and return a fresh universe that extends all previous universes. Updates self.universe to that new universe.

Source

pub fn is_ty_infer_var_definitely_unchanged<'a>( &'a self, ) -> impl Fn(TyOrConstInferVar) -> bool + use<'a, 'db>

The returned function is used in a fast path. If it returns true the variable is unchanged, false indicates that the status is unknown.

Source

pub fn ty_or_const_infer_var_changed( &self, infer_var: TyOrConstInferVar, ) -> bool

ty_or_const_infer_var_changed is equivalent to one of these two:

  • shallow_resolve(ty) != ty (where ty.kind = Infer(_))
  • shallow_resolve(ct) != ct (where ct.kind = ConstKind::Infer(_))

However, ty_or_const_infer_var_changed is more efficient. It’s always inlined, despite being large, because it has only two call sites that are extremely hot (both in traits::fulfill’s checking of stalled_on inference variables), and it handles both Ty and Const without having to resort to storing full GenericArgs in stalled_on.

Source

fn sub_unification_table_root_var(&self, var: TyVid) -> TyVid

Source

fn sub_unify_ty_vids_raw(&self, a: TyVid, b: TyVid)

Source

pub fn attach_obligation_inspector(&self, inspector: ObligationInspector<'db>)

Attach a callback to be invoked on each root obligation evaluated in the new trait solver.

Source

pub fn inspect_evaluated_obligation( &self, obligation: &Obligation<'db, Predicate<'db>>, result: &Result<GoalEvaluation<DbInterner<'db>>, NoSolution>, get_proof_tree: impl FnOnce() -> Option<GoalEvaluation<DbInterner<'db>>>, )

Source

pub(crate) fn visit_proof_tree<V: ProofTreeVisitor<'db>>( &self, goal: Goal<'db, Predicate<'db>>, visitor: &mut V, ) -> V::Result

Source

pub(crate) fn visit_proof_tree_at_depth<V: ProofTreeVisitor<'db>>( &self, goal: Goal<'db, Predicate<'db>>, depth: usize, visitor: &mut V, ) -> V::Result

Trait Implementations§

Source§

impl<'db> Deref for SolverContext<'db>

Source§

type Target = InferCtxt<'db>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a, 'db> From<&'a InferCtxt<'db>> for &'a SolverContext<'db>

Source§

fn from(infcx: &'a InferCtxt<'db>) -> Self

Converts to this type from the input type.
Source§

impl<'db> SolverDelegate for SolverContext<'db>

Source§

type Interner = DbInterner<'db>

Source§

type Infcx = InferCtxt<'db>

Source§

fn cx(&self) -> Self::Interner

Source§

fn build_with_canonical<V>( cx: Self::Interner, canonical: &CanonicalQueryInput<Self::Interner, V>, ) -> (Self, V, CanonicalVarValues<Self::Interner>)
where V: TypeFoldable<Self::Interner>,

Source§

fn fresh_var_for_kind_with_span( &self, arg: GenericArg<'db>, span: Span, ) -> GenericArg<'db>

Source§

fn leak_check( &self, _max_input_universe: UniverseIndex, ) -> Result<(), NoSolution>

Source§

fn well_formed_goals( &self, _param_env: ParamEnv<'db>, _arg: <Self::Interner as Interner>::Term, ) -> Option<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>>

Source§

fn make_deduplicated_region_constraints( &self, ) -> Vec<(RegionConstraint<'db>, VisibleForLeakCheck)>

Source§

fn instantiate_canonical<V>( &self, canonical: Canonical<Self::Interner, V>, values: CanonicalVarValues<Self::Interner>, ) -> V
where V: TypeFoldable<Self::Interner>,

Source§

fn instantiate_canonical_var( &self, kind: CanonicalVarKind<'db>, span: Span, var_values: &[GenericArg<'db>], universe_map: impl Fn(UniverseIndex) -> UniverseIndex, ) -> GenericArg<'db>

Source§

fn add_item_bounds_for_hidden_type( &self, opaque_id: OpaqueTyIdWrapper<'_>, args: GenericArgs<'db>, param_env: ParamEnv<'db>, hidden_ty: Ty<'db>, goals: &mut Vec<Goal<'db, Predicate<'db>>>, )

Source§

fn fetch_eligible_assoc_item( &self, _goal_trait_ref: TraitRef<Self::Interner>, trait_assoc_def_id: TraitAssocTermId, impl_id: AnyImplId, ) -> FetchEligibleAssocItemResponse<Self::Interner>

Source§

fn is_transmutable( &self, _src: Ty<'db>, _dst: Ty<'db>, _assume: <Self::Interner as Interner>::Const, ) -> Result<Certainty, NoSolution>

Source§

fn evaluate_const( &self, param_env: ParamEnv<'db>, uv: UnevaluatedConst<'db>, ) -> Option<Const<'db>>

Source§

fn compute_goal_fast_path( &self, goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>, _span: <Self::Interner as Interner>::Span, ) -> Option<Certainty>

Auto Trait Implementations§

§

impl<'db> !Freeze for SolverContext<'db>

§

impl<'db> !RefUnwindSafe for SolverContext<'db>

§

impl<'db> Send for SolverContext<'db>

§

impl<'db> !Sync for SolverContext<'db>

§

impl<'db> Unpin for SolverContext<'db>

§

impl<'db> UnsafeUnpin for SolverContext<'db>

§

impl<'db> !UnwindSafe for SolverContext<'db>

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
§

impl<T, R> CollectAndApply<T, R> for T

§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> IntoBox<dyn Any> for T
where T: Any,

§

fn into_box(self) -> Box<dyn Any>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn Any + Send> for T
where T: Any + Send,

§

fn into_box(self) -> Box<dyn Any + Send>

Convert self into the appropriate boxed form.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Lookup<T> for T

§

fn into_owned(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
§

impl<D, I> SolverDelegateEvalExt for D
where D: SolverDelegate<Interner = I>, I: Interner,

§

fn evaluate_root_goal( &self, goal: Goal<I, <I as Interner>::Predicate>, span: <I as Interner>::Span, stalled_on: Option<GoalStalledOn<I>>, ) -> Result<GoalEvaluation<I>, NoSolution>

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

fn root_goal_may_hold_opaque_types_jank( &self, goal: Goal<<D as SolverDelegate>::Interner, <<D as SolverDelegate>::Interner as Interner>::Predicate>, ) -> bool

Checks whether evaluating goal may hold while treating not-yet-defined opaque types as being kind of rigid. Read more
§

fn root_goal_may_hold_with_depth( &self, root_depth: usize, goal: Goal<<D as SolverDelegate>::Interner, <<D as SolverDelegate>::Interner as Interner>::Predicate>, ) -> bool

Check whether evaluating goal with a depth of root_depth may succeed. This only returns false if the goal is guaranteed to not hold. In case evaluation overflows and fails with ambiguity this returns true. Read more
§

fn evaluate_root_goal_for_proof_tree( &self, goal: Goal<I, <I as Interner>::Predicate>, span: <I as Interner>::Span, ) -> (Result<NestedNormalizationGoals<I>, NoSolution>, GoalEvaluation<I>)

Source§

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

Source§

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

Source§

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

impl<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

§

fn upcast(self, interner: I) -> U

§

impl<I, T> UpcastFrom<I, T> for T

§

fn upcast_from(from: T, _tcx: I) -> T

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more