Struct rustc_trait_selection::solve::eval_ctxt::EvalCtxt
source · pub struct EvalCtxt<'a, 'tcx> {
infcx: &'a InferCtxt<'tcx>,
variables: CanonicalVarInfos<'tcx>,
pub(super) var_values: CanonicalVarValues<'tcx>,
predefined_opaques_in_body: PredefinedOpaques<'tcx>,
pub(super) max_input_universe: UniverseIndex,
pub(super) search_graph: &'a mut SearchGraph<'tcx>,
pub(super) nested_goals: NestedGoals<'tcx>,
tainted: Result<(), NoSolution>,
pub(super) inspect: ProofTreeBuilder<'tcx>,
}
Fields§
§infcx: &'a InferCtxt<'tcx>
The inference context that backs (mostly) inference and placeholder terms instantiated while solving goals.
NOTE: The InferCtxt
that backs the EvalCtxt
is intentionally private,
because the InferCtxt
is much more general than EvalCtxt
. Methods such
as take_registered_region_obligations
can mess up query responses,
using At::normalize
is totally wrong, calling evaluate_root_goal
can
cause coinductive unsoundness, etc.
Methods that are generally of use for trait solving are intentionally
re-declared through the EvalCtxt
below, often with cleaner signatures
since we don’t care about things like ObligationCause
s and Span
s here.
If some InferCtxt
method is missing, please first think defensively about
the method’s compatibility with this solver, or if an existing one does
the job already.
variables: CanonicalVarInfos<'tcx>
The variable info for the var_values
, only used to make an ambiguous response
with no constraints.
var_values: CanonicalVarValues<'tcx>
§predefined_opaques_in_body: PredefinedOpaques<'tcx>
§max_input_universe: UniverseIndex
The highest universe index nameable by the caller.
When we enter a new binder inside of the query we create new universes which the caller cannot name. We have to be careful with variables from these new universes when creating the query response.
Both because these new universes can prevent us from reaching a fixpoint if we have a coinductive cycle and because that’s the only way we can return new placeholders to the caller.
search_graph: &'a mut SearchGraph<'tcx>
§nested_goals: NestedGoals<'tcx>
§tainted: Result<(), NoSolution>
§inspect: ProofTreeBuilder<'tcx>
Implementations§
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
pub(super) fn compute_alias_relate_goal( &mut self, goal: Goal<'tcx, (Term<'tcx>, Term<'tcx>, AliasRelationDirection)> ) -> QueryResult<'tcx>
sourcefn relate_rigid_alias_non_alias(
&mut self,
param_env: ParamEnv<'tcx>,
alias: AliasTy<'tcx>,
variance: Variance,
term: Term<'tcx>
) -> QueryResult<'tcx>
fn relate_rigid_alias_non_alias( &mut self, param_env: ParamEnv<'tcx>, alias: AliasTy<'tcx>, variance: Variance, term: Term<'tcx> ) -> QueryResult<'tcx>
Relate a rigid alias with another type. This is the same as an ordinary relate except that we treat the outer most alias constructor as rigid.
sourcefn try_normalize_term(
&mut self,
param_env: ParamEnv<'tcx>,
term: Term<'tcx>
) -> Result<Option<Term<'tcx>>, NoSolution>
fn try_normalize_term( &mut self, param_env: ParamEnv<'tcx>, term: Term<'tcx> ) -> Result<Option<Term<'tcx>>, NoSolution>
Normalize the term
to equate it later.
fn try_normalize_ty_recur( &mut self, param_env: ParamEnv<'tcx>, depth: usize, ty: Ty<'tcx> ) -> Option<Ty<'tcx>>
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
pub(super) fn assemble_and_evaluate_candidates<G: GoalKind<'tcx>>( &mut self, goal: Goal<'tcx, G> ) -> Vec<Candidate<'tcx>>
fn forced_ambiguity(&mut self, cause: MaybeCause) -> Vec<Candidate<'tcx>>
fn assemble_non_blanket_impl_candidates<G: GoalKind<'tcx>>( &mut self, goal: Goal<'tcx, G>, candidates: &mut Vec<Candidate<'tcx>> )
fn assemble_blanket_impl_candidates<G: GoalKind<'tcx>>( &mut self, goal: Goal<'tcx, G>, candidates: &mut Vec<Candidate<'tcx>> )
fn assemble_builtin_impl_candidates<G: GoalKind<'tcx>>( &mut self, goal: Goal<'tcx, G>, candidates: &mut Vec<Candidate<'tcx>> )
fn assemble_param_env_candidates<G: GoalKind<'tcx>>( &mut self, goal: Goal<'tcx, G>, candidates: &mut Vec<Candidate<'tcx>> )
fn assemble_alias_bound_candidates<G: GoalKind<'tcx>>( &mut self, goal: Goal<'tcx, G>, candidates: &mut Vec<Candidate<'tcx>> )
sourcefn assemble_alias_bound_candidates_recur<G: GoalKind<'tcx>>(
&mut self,
self_ty: Ty<'tcx>,
goal: Goal<'tcx, G>,
candidates: &mut Vec<Candidate<'tcx>>
)
fn assemble_alias_bound_candidates_recur<G: GoalKind<'tcx>>( &mut self, self_ty: Ty<'tcx>, goal: Goal<'tcx, G>, candidates: &mut Vec<Candidate<'tcx>> )
For some deeply nested <T>::A::B::C::D
rigid associated type,
we should explore the item bounds for all levels, since the
associated_type_bounds
feature means that a parent associated
type may carry bounds for a nested associated type.
If we have a projection, check that its self type is a rigid projection. If so, continue searching by recursively calling after normalization.
fn assemble_object_bound_candidates<G: GoalKind<'tcx>>( &mut self, goal: Goal<'tcx, G>, candidates: &mut Vec<Candidate<'tcx>> )
sourcefn assemble_coherence_unknowable_candidates<G: GoalKind<'tcx>>(
&mut self,
goal: Goal<'tcx, G>,
candidates: &mut Vec<Candidate<'tcx>>
)
fn assemble_coherence_unknowable_candidates<G: GoalKind<'tcx>>( &mut self, goal: Goal<'tcx, G>, candidates: &mut Vec<Candidate<'tcx>> )
In coherence we have to not only care about all impls we know about, but also consider impls which may get added in a downstream or sibling crate or which an upstream impl may add in a minor release.
To do so we add an ambiguous candidate in case such an unknown impl could apply to the current goal.
sourcefn discard_impls_shadowed_by_env<G: GoalKind<'tcx>>(
&mut self,
goal: Goal<'tcx, G>,
candidates: &mut Vec<Candidate<'tcx>>
)
fn discard_impls_shadowed_by_env<G: GoalKind<'tcx>>( &mut self, goal: Goal<'tcx, G>, candidates: &mut Vec<Candidate<'tcx>> )
If there’s a where-bound for the current goal, do not use any impl candidates to prove the current goal. Most importantly, if there is a where-bound which does not specify any associated types, we do not allow normalizing the associated type by using an impl, even if it would apply.
https://github.com/rust-lang/trait-system-refactor-initiative/issues/76
sourcepub(super) fn merge_candidates(
&mut self,
candidates: Vec<Candidate<'tcx>>
) -> QueryResult<'tcx>
pub(super) fn merge_candidates( &mut self, candidates: Vec<Candidate<'tcx>> ) -> QueryResult<'tcx>
If there are multiple ways to prove a trait or projection goal, we have to somehow try to merge the candidates into one. If that fails, we return ambiguity.
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
sourcepub(super) fn canonicalize_goal<T: TypeFoldable<TyCtxt<'tcx>>>(
&self,
goal: Goal<'tcx, T>
) -> (Vec<GenericArg<'tcx>>, CanonicalInput<'tcx, T>)
pub(super) fn canonicalize_goal<T: TypeFoldable<TyCtxt<'tcx>>>( &self, goal: Goal<'tcx, T> ) -> (Vec<GenericArg<'tcx>>, CanonicalInput<'tcx, T>)
Canonicalizes the goal remembering the original values for each bound variable.
sourcepub(in solve) fn evaluate_added_goals_and_make_canonical_response(
&mut self,
certainty: Certainty
) -> QueryResult<'tcx>
pub(in solve) fn evaluate_added_goals_and_make_canonical_response( &mut self, certainty: Certainty ) -> QueryResult<'tcx>
To return the constraints of a canonical query to the caller, we canonicalize:
var_values
: a map from bound variables in the canonical goal to the values inferred while solving the instantiated goal.external_constraints
: additional constraints which aren’t expressible using simple unification of inference variables.
sourcepub(in solve) fn make_ambiguous_response_no_constraints(
&self,
maybe_cause: MaybeCause
) -> CanonicalResponse<'tcx>
pub(in solve) fn make_ambiguous_response_no_constraints( &self, maybe_cause: MaybeCause ) -> CanonicalResponse<'tcx>
Constructs a totally unconstrained, ambiguous response to a goal.
Take care when using this, since often it’s useful to respond with ambiguity but return constrained variables to guide inference.
sourcefn compute_external_query_constraints(
&self
) -> Result<ExternalConstraintsData<'tcx>, NoSolution>
fn compute_external_query_constraints( &self ) -> Result<ExternalConstraintsData<'tcx>, NoSolution>
Computes the region constraints and new opaque types registered when proving a goal.
If an opaque was already constrained before proving this goal, then the external constraints do not need to record that opaque, since if it is further constrained by inference, that will be passed back in the var values.
sourcepub(super) fn instantiate_and_apply_query_response(
&mut self,
param_env: ParamEnv<'tcx>,
original_values: Vec<GenericArg<'tcx>>,
response: CanonicalResponse<'tcx>
) -> Certainty
pub(super) fn instantiate_and_apply_query_response( &mut self, param_env: ParamEnv<'tcx>, original_values: Vec<GenericArg<'tcx>>, response: CanonicalResponse<'tcx> ) -> Certainty
After calling a canonical query, we apply the constraints returned by the query using this function.
This happens in three steps:
- we instantiate the bound variables of the query response
- we unify the
var_values
of the response with theoriginal_values
- we apply the
external_constraints
returned by the query
sourcefn compute_query_response_instantiation_values<T: ResponseT<'tcx>>(
infcx: &InferCtxt<'tcx>,
original_values: &[GenericArg<'tcx>],
response: &Canonical<'tcx, T>
) -> CanonicalVarValues<'tcx>
fn compute_query_response_instantiation_values<T: ResponseT<'tcx>>( infcx: &InferCtxt<'tcx>, original_values: &[GenericArg<'tcx>], response: &Canonical<'tcx, T> ) -> CanonicalVarValues<'tcx>
This returns the canoncial variable values to instantiate the bound variables of
the canonical response. This depends on the original_values
for the
bound variables.
sourcefn unify_query_var_values(
infcx: &InferCtxt<'tcx>,
param_env: ParamEnv<'tcx>,
original_values: &[GenericArg<'tcx>],
var_values: CanonicalVarValues<'tcx>
)
fn unify_query_var_values( infcx: &InferCtxt<'tcx>, param_env: ParamEnv<'tcx>, original_values: &[GenericArg<'tcx>], var_values: CanonicalVarValues<'tcx> )
Unify the original_values
with the var_values
returned by the canonical query..
This assumes that this unification will always succeed. This is the case when applying a query response right away. However, calling a canonical query, doing any other kind of trait solving, and only then instantiating the result of the query can cause the instantiation to fail. This is not supported and we ICE in this case.
We always structurally instantiate aliases. Relating aliases needs to be different depending on whether the alias is rigid or not. We’re only really able to tell whether an alias is rigid by using the trait solver. When instantiating a response from the solver we assume that the solver correctly handled aliases and therefore always relate them structurally here.
fn register_region_constraints( &mut self, region_constraints: &QueryRegionConstraints<'tcx> )
fn register_new_opaque_types( &mut self, param_env: ParamEnv<'tcx>, opaque_types: &[(OpaqueTypeKey<'tcx>, Ty<'tcx>)] )
source§impl<'a, 'tcx> EvalCtxt<'a, 'tcx>
impl<'a, 'tcx> EvalCtxt<'a, 'tcx>
pub(in solve) fn commit_if_ok<T>( &mut self, f: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> Result<T, NoSolution> ) -> Result<T, NoSolution>
source§impl<'a, 'tcx> EvalCtxt<'a, 'tcx>
impl<'a, 'tcx> EvalCtxt<'a, 'tcx>
sourcepub(in solve) fn probe<F, T>(
&mut self,
probe_kind: F
) -> ProbeCtxt<'_, 'a, 'tcx, F, T>
pub(in solve) fn probe<F, T>( &mut self, probe_kind: F ) -> ProbeCtxt<'_, 'a, 'tcx, F, T>
probe_kind
is only called when proof tree building is enabled so it can be
as expensive as necessary to output the desired information.
pub(in solve) fn probe_misc_candidate( &mut self, name: &'static str ) -> ProbeCtxt<'_, 'a, 'tcx, impl FnOnce(&QueryResult<'tcx>) -> ProbeKind<'tcx>, QueryResult<'tcx>>
pub(in solve) fn probe_trait_candidate( &mut self, source: CandidateSource ) -> TraitProbeCtxt<'_, 'a, 'tcx, impl FnOnce(&QueryResult<'tcx>) -> ProbeKind<'tcx>>
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
fn compute_canonical_trait_candidates( &mut self, canonical_input: CanonicalInput<'tcx> ) -> Vec<Candidate<'tcx>>
source§impl<'a, 'tcx> EvalCtxt<'a, 'tcx>
impl<'a, 'tcx> EvalCtxt<'a, 'tcx>
pub(super) fn solver_mode(&self) -> SolverMode
sourcefn enter_root<R>(
infcx: &InferCtxt<'tcx>,
generate_proof_tree: GenerateProofTree,
f: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> R
) -> (R, Option<GoalEvaluation<'tcx>>)
fn enter_root<R>( infcx: &InferCtxt<'tcx>, generate_proof_tree: GenerateProofTree, f: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> R ) -> (R, Option<GoalEvaluation<'tcx>>)
Creates a root evaluation context and search graph. This should only be
used from outside of any evaluation, and other methods should be preferred
over using this manually (such as InferCtxtEvalExt::evaluate_root_goal
).
sourcefn enter_canonical<R>(
tcx: TyCtxt<'tcx>,
search_graph: &'a mut SearchGraph<'tcx>,
canonical_input: CanonicalInput<'tcx>,
canonical_goal_evaluation: &mut ProofTreeBuilder<'tcx>,
f: impl FnOnce(&mut EvalCtxt<'_, 'tcx>, Goal<'tcx, Predicate<'tcx>>) -> R
) -> R
fn enter_canonical<R>( tcx: TyCtxt<'tcx>, search_graph: &'a mut SearchGraph<'tcx>, canonical_input: CanonicalInput<'tcx>, canonical_goal_evaluation: &mut ProofTreeBuilder<'tcx>, f: impl FnOnce(&mut EvalCtxt<'_, 'tcx>, Goal<'tcx, Predicate<'tcx>>) -> R ) -> R
Creates a nested evaluation context that shares the same search graph as the
one passed in. This is suitable for evaluation, granted that the search graph
has had the nested goal recorded on its stack (SearchGraph::with_new_goal
),
but it’s preferable to use other methods that call this one rather than this
method directly.
This function takes care of setting up the inference context, setting the anchor, and registering opaques from the canonicalized input.
sourcefn evaluate_canonical_goal(
tcx: TyCtxt<'tcx>,
search_graph: &'a mut SearchGraph<'tcx>,
canonical_input: CanonicalInput<'tcx>,
goal_evaluation: &mut ProofTreeBuilder<'tcx>
) -> QueryResult<'tcx>
fn evaluate_canonical_goal( tcx: TyCtxt<'tcx>, search_graph: &'a mut SearchGraph<'tcx>, canonical_input: CanonicalInput<'tcx>, goal_evaluation: &mut ProofTreeBuilder<'tcx> ) -> QueryResult<'tcx>
The entry point of the solver.
This function deals with (coinductive) cycles, overflow, and caching
and then calls EvalCtxt::compute_goal
which contains the actual
logic of the solver.
Instead of calling this function directly, use either EvalCtxt::evaluate_goal if you’re inside of the solver or InferCtxtEvalExt::evaluate_root_goal if you’re outside of it.
sourcefn evaluate_goal(
&mut self,
goal_evaluation_kind: GoalEvaluationKind,
source: GoalSource,
goal: Goal<'tcx, Predicate<'tcx>>
) -> Result<(bool, Certainty), NoSolution>
fn evaluate_goal( &mut self, goal_evaluation_kind: GoalEvaluationKind, source: GoalSource, goal: Goal<'tcx, Predicate<'tcx>> ) -> Result<(bool, Certainty), NoSolution>
Recursively evaluates goal
, returning whether any inference vars have
been constrained and the certainty of the result.
fn instantiate_response_discarding_overflow( &mut self, param_env: ParamEnv<'tcx>, source: GoalSource, original_values: Vec<GenericArg<'tcx>>, response: CanonicalResponse<'tcx> ) -> (Certainty, bool)
fn compute_goal( &mut self, goal: Goal<'tcx, Predicate<'tcx>> ) -> QueryResult<'tcx>
pub(super) fn try_evaluate_added_goals( &mut self ) -> Result<Certainty, NoSolution>
sourcefn evaluate_added_goals_step(&mut self) -> Result<Option<Certainty>, NoSolution>
fn evaluate_added_goals_step(&mut self) -> Result<Option<Certainty>, NoSolution>
Iterate over all added goals: returning Ok(Some(_))
in case we can stop rerunning.
Goals for the next step get directly added to the nested goals of the EvalCtxt
.
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
pub(super) fn tcx(&self) -> TyCtxt<'tcx>
pub(super) fn next_ty_infer(&self) -> Ty<'tcx>
pub(super) fn next_const_infer(&self, ty: Ty<'tcx>) -> Const<'tcx>
sourcepub(super) fn next_term_infer_of_kind(&self, kind: Term<'tcx>) -> Term<'tcx>
pub(super) fn next_term_infer_of_kind(&self, kind: Term<'tcx>) -> Term<'tcx>
Returns a ty infer or a const infer depending on whether kind
is a Ty
or Const
.
If kind
is an integer inference variable this will still return a ty infer var.
sourcepub(super) fn term_is_fully_unconstrained(
&self,
goal: Goal<'tcx, NormalizesTo<'tcx>>
) -> bool
pub(super) fn term_is_fully_unconstrained( &self, goal: Goal<'tcx, NormalizesTo<'tcx>> ) -> bool
Is the projection predicate is of the form exists<T> <Ty as Trait>::Assoc = T
.
This is the case if the term
does not occur in any other part of the predicate
and is able to name all other placeholder and inference variables.
pub(super) fn eq<T: ToTrace<'tcx>>( &mut self, param_env: ParamEnv<'tcx>, lhs: T, rhs: T ) -> Result<(), NoSolution>
sourcepub(super) fn eq_structurally_relating_aliases<T: ToTrace<'tcx>>(
&mut self,
param_env: ParamEnv<'tcx>,
lhs: T,
rhs: T
) -> Result<(), NoSolution>
pub(super) fn eq_structurally_relating_aliases<T: ToTrace<'tcx>>( &mut self, param_env: ParamEnv<'tcx>, lhs: T, rhs: T ) -> Result<(), NoSolution>
This sohuld only be used when we’re either instantiating a previously unconstrained “return value” or when we’re sure that all aliases in the types are rigid.
pub(super) fn sub<T: ToTrace<'tcx>>( &mut self, param_env: ParamEnv<'tcx>, sub: T, sup: T ) -> Result<(), NoSolution>
pub(super) fn relate<T: ToTrace<'tcx>>( &mut self, param_env: ParamEnv<'tcx>, lhs: T, variance: Variance, rhs: T ) -> Result<(), NoSolution>
sourcepub(super) fn eq_and_get_goals<T: ToTrace<'tcx>>(
&self,
param_env: ParamEnv<'tcx>,
lhs: T,
rhs: T
) -> Result<Vec<Goal<'tcx, Predicate<'tcx>>>, NoSolution>
pub(super) fn eq_and_get_goals<T: ToTrace<'tcx>>( &self, param_env: ParamEnv<'tcx>, lhs: T, rhs: T ) -> Result<Vec<Goal<'tcx, Predicate<'tcx>>>, NoSolution>
Equates two values returning the nested goals without adding them
to the nested goals of the EvalCtxt
.
If possible, try using eq
instead which automatically handles nested
goals correctly.
pub(super) fn instantiate_binder_with_infer<T: TypeFoldable<TyCtxt<'tcx>> + Copy>( &self, value: Binder<'tcx, T> ) -> T
pub(super) fn enter_forall<T: TypeFoldable<TyCtxt<'tcx>> + Copy, U>( &self, value: Binder<'tcx, T>, f: impl FnOnce(T) -> U ) -> U
pub(super) fn resolve_vars_if_possible<T>(&self, value: T) -> Twhere
T: TypeFoldable<TyCtxt<'tcx>>,
pub(super) fn fresh_args_for_item(&self, def_id: DefId) -> GenericArgsRef<'tcx>
pub(super) fn translate_args( &self, param_env: ParamEnv<'tcx>, source_impl: DefId, source_args: GenericArgsRef<'tcx>, target_node: Node ) -> GenericArgsRef<'tcx>
pub(super) fn register_ty_outlives(&self, ty: Ty<'tcx>, lt: Region<'tcx>)
pub(super) fn register_region_outlives(&self, a: Region<'tcx>, b: Region<'tcx>)
sourcepub(super) fn well_formed_goals(
&self,
param_env: ParamEnv<'tcx>,
arg: GenericArg<'tcx>
) -> Option<impl Iterator<Item = Goal<'tcx, Predicate<'tcx>>>>
pub(super) fn well_formed_goals( &self, param_env: ParamEnv<'tcx>, arg: GenericArg<'tcx> ) -> Option<impl Iterator<Item = Goal<'tcx, Predicate<'tcx>>>>
Computes the list of goals required for arg
to be well-formed
pub(super) fn is_transmutable( &self, src_and_dst: Types<'tcx>, assume: Assume ) -> Result<Certainty, NoSolution>
pub(super) fn can_define_opaque_ty(&self, def_id: LocalDefId) -> bool
pub(super) fn unify_existing_opaque_tys( &mut self, param_env: ParamEnv<'tcx>, key: OpaqueTypeKey<'tcx>, ty: Ty<'tcx> ) -> Vec<CanonicalResponse<'tcx>>
pub(super) fn try_const_eval_resolve( &self, param_env: ParamEnv<'tcx>, unevaluated: UnevaluatedConst<'tcx>, ty: Ty<'tcx> ) -> Option<Const<'tcx>>
sourcepub(super) fn walk_vtable(
&mut self,
principal: PolyTraitRef<'tcx>,
supertrait_visitor: impl FnMut(&mut Self, PolyTraitRef<'tcx>, usize, Option<usize>)
)
pub(super) fn walk_vtable( &mut self, principal: PolyTraitRef<'tcx>, supertrait_visitor: impl FnMut(&mut Self, PolyTraitRef<'tcx>, usize, Option<usize>) )
Walk through the vtable of a principal trait ref, executing a supertrait_visitor
for every trait ref encountered (including the principal). Passes both the vtable
base and the (optional) vptr slot.
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
pub(super) fn normalize_anon_const( &mut self, goal: Goal<'tcx, NormalizesTo<'tcx>> ) -> QueryResult<'tcx>
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
pub(super) fn normalize_inherent_associated_type( &mut self, goal: Goal<'tcx, NormalizesTo<'tcx>> ) -> QueryResult<'tcx>
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
pub(super) fn normalize_opaque_type( &mut self, goal: Goal<'tcx, NormalizesTo<'tcx>> ) -> QueryResult<'tcx>
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
pub(super) fn normalize_weak_type( &mut self, goal: Goal<'tcx, NormalizesTo<'tcx>> ) -> QueryResult<'tcx>
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
pub(super) fn compute_normalizes_to_goal( &mut self, goal: Goal<'tcx, NormalizesTo<'tcx>> ) -> QueryResult<'tcx>
sourcepub fn instantiate_normalizes_to_term(
&mut self,
goal: Goal<'tcx, NormalizesTo<'tcx>>,
term: Term<'tcx>
)
pub fn instantiate_normalizes_to_term( &mut self, goal: Goal<'tcx, NormalizesTo<'tcx>>, term: Term<'tcx> )
When normalizing an associated item, constrain the result to term
.
While NormalizesTo
goals have the normalized-to term as an argument,
this argument is always fully unconstrained for associated items.
It is therefore appropriate to instead think of these NormalizesTo
goals
as function returning a term after normalizing.
When equating an inference variable and an alias, we tend to emit alias-relate
goals and only actually instantiate the inference variable with an alias if the
alias is rigid. However, this means that constraining the expected term of
such goals ends up fully structurally normalizing the resulting type instead of
only by one step. To avoid this we instead use structural equality here, resulting
in each NormalizesTo
only projects by a single step.
Not doing so, currently causes issues because trying to normalize an opaque type
during alias-relate doesn’t actually constrain the opaque if the concrete type
is an inference variable. This means that NormalizesTo
for associated types
normalizing to an opaque type always resulted in ambiguity, breaking tests e.g.
tests/ui/type-alias-impl-trait/issue-78450.rs.
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
pub(super) fn compute_projection_goal( &mut self, goal: Goal<'tcx, ProjectionPredicate<'tcx>> ) -> QueryResult<'tcx>
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
sourcefn consider_builtin_dyn_upcast_candidates(
&mut self,
goal: Goal<'tcx, (Ty<'tcx>, Ty<'tcx>)>,
a_data: &'tcx List<PolyExistentialPredicate<'tcx>>,
a_region: Region<'tcx>,
b_data: &'tcx List<PolyExistentialPredicate<'tcx>>,
b_region: Region<'tcx>
) -> Vec<(CanonicalResponse<'tcx>, BuiltinImplSource)>
fn consider_builtin_dyn_upcast_candidates( &mut self, goal: Goal<'tcx, (Ty<'tcx>, Ty<'tcx>)>, a_data: &'tcx List<PolyExistentialPredicate<'tcx>>, a_region: Region<'tcx>, b_data: &'tcx List<PolyExistentialPredicate<'tcx>>, b_region: Region<'tcx> ) -> Vec<(CanonicalResponse<'tcx>, BuiltinImplSource)>
Trait upcasting allows for coercions between trait objects:
trait Super {}
trait Trait: Super {}
// results in builtin impls upcasting to a super trait
impl<'a, 'b: 'a> Unsize<dyn Super + 'a> for dyn Trait + 'b {}
// and impls removing auto trait bounds.
impl<'a, 'b: 'a> Unsize<dyn Trait + 'a> for dyn Trait + Send + 'b {}
fn consider_builtin_unsize_to_dyn_candidate( &mut self, goal: Goal<'tcx, (Ty<'tcx>, Ty<'tcx>)>, b_data: &'tcx List<PolyExistentialPredicate<'tcx>>, b_region: Region<'tcx> ) -> QueryResult<'tcx>
fn consider_builtin_upcast_to_principal( &mut self, goal: Goal<'tcx, (Ty<'tcx>, Ty<'tcx>)>, a_data: &'tcx List<PolyExistentialPredicate<'tcx>>, a_region: Region<'tcx>, b_data: &'tcx List<PolyExistentialPredicate<'tcx>>, b_region: Region<'tcx>, upcast_principal: Option<PolyExistentialTraitRef<'tcx>> ) -> QueryResult<'tcx>
sourcefn consider_builtin_array_unsize(
&mut self,
goal: Goal<'tcx, (Ty<'tcx>, Ty<'tcx>)>,
a_elem_ty: Ty<'tcx>,
b_elem_ty: Ty<'tcx>
) -> QueryResult<'tcx>
fn consider_builtin_array_unsize( &mut self, goal: Goal<'tcx, (Ty<'tcx>, Ty<'tcx>)>, a_elem_ty: Ty<'tcx>, b_elem_ty: Ty<'tcx> ) -> QueryResult<'tcx>
We have the following builtin impls for arrays:
impl<T: ?Sized, const N: usize> Unsize<[T]> for [T; N] {}
While the impl itself could theoretically not be builtin,
the actual unsizing behavior is builtin. Its also easier to
make all impls of Unsize
builtin as we’re able to use
#[rustc_deny_explicit_impl]
in this case.
sourcefn consider_builtin_struct_unsize(
&mut self,
goal: Goal<'tcx, (Ty<'tcx>, Ty<'tcx>)>,
def: AdtDef<'tcx>,
a_args: GenericArgsRef<'tcx>,
b_args: GenericArgsRef<'tcx>
) -> QueryResult<'tcx>
fn consider_builtin_struct_unsize( &mut self, goal: Goal<'tcx, (Ty<'tcx>, Ty<'tcx>)>, def: AdtDef<'tcx>, a_args: GenericArgsRef<'tcx>, b_args: GenericArgsRef<'tcx> ) -> QueryResult<'tcx>
We generate a builtin Unsize
impls for structs with generic parameters only
mentioned by the last field.
struct Foo<T, U: ?Sized> {
sized_field: Vec<T>,
unsizable: Box<U>,
}
// results in the following builtin impl
impl<T: ?Sized, U: ?Sized, V: ?Sized> Unsize<Foo<T, V>> for Foo<T, U>
where
Box<U>: Unsize<Box<V>>,
{}
sourcefn consider_builtin_tuple_unsize(
&mut self,
goal: Goal<'tcx, (Ty<'tcx>, Ty<'tcx>)>,
a_tys: &'tcx List<Ty<'tcx>>,
b_tys: &'tcx List<Ty<'tcx>>
) -> QueryResult<'tcx>
fn consider_builtin_tuple_unsize( &mut self, goal: Goal<'tcx, (Ty<'tcx>, Ty<'tcx>)>, a_tys: &'tcx List<Ty<'tcx>>, b_tys: &'tcx List<Ty<'tcx>> ) -> QueryResult<'tcx>
We generate the following builtin impl for tuples of all sizes.
This impl is still unstable and we emit a feature error when it when it is used by a coercion.
impl<T: ?Sized, U: ?Sized, V: ?Sized> Unsize<(T, V)> for (T, U)
where
U: Unsize<V>,
{}
fn disqualify_auto_trait_candidate_due_to_possible_impl( &mut self, goal: Goal<'tcx, TraitPredicate<'tcx>> ) -> Option<QueryResult<'tcx>>
sourcefn probe_and_evaluate_goal_for_constituent_tys(
&mut self,
goal: Goal<'tcx, TraitPredicate<'tcx>>,
constituent_tys: impl Fn(&EvalCtxt<'_, 'tcx>, Ty<'tcx>) -> Result<Vec<Binder<'tcx, Ty<'tcx>>>, NoSolution>
) -> QueryResult<'tcx>
fn probe_and_evaluate_goal_for_constituent_tys( &mut self, goal: Goal<'tcx, TraitPredicate<'tcx>>, constituent_tys: impl Fn(&EvalCtxt<'_, 'tcx>, Ty<'tcx>) -> Result<Vec<Binder<'tcx, Ty<'tcx>>>, NoSolution> ) -> QueryResult<'tcx>
Convenience function for traits that are structural, i.e. that only have nested subgoals that only change the self type. Unlike other evaluate-like helpers, this does a probe, so it doesn’t need to be wrapped in one.
pub(super) fn compute_trait_goal( &mut self, goal: Goal<'tcx, TraitPredicate<'tcx>> ) -> QueryResult<'tcx>
source§impl<'a, 'tcx> EvalCtxt<'a, 'tcx>
impl<'a, 'tcx> EvalCtxt<'a, 'tcx>
fn compute_type_outlives_goal( &mut self, goal: Goal<'tcx, TypeOutlivesPredicate<'tcx>> ) -> QueryResult<'tcx>
fn compute_region_outlives_goal( &mut self, goal: Goal<'tcx, RegionOutlivesPredicate<'tcx>> ) -> QueryResult<'tcx>
fn compute_coerce_goal( &mut self, goal: Goal<'tcx, CoercePredicate<'tcx>> ) -> QueryResult<'tcx>
fn compute_subtype_goal( &mut self, goal: Goal<'tcx, SubtypePredicate<'tcx>> ) -> QueryResult<'tcx>
fn compute_object_safe_goal(&mut self, trait_def_id: DefId) -> QueryResult<'tcx>
fn compute_well_formed_goal( &mut self, goal: Goal<'tcx, GenericArg<'tcx>> ) -> QueryResult<'tcx>
fn compute_const_evaluatable_goal( &mut self, _: Goal<'tcx, Const<'tcx>> ) -> QueryResult<'tcx>
fn compute_const_arg_has_type_goal( &mut self, goal: Goal<'tcx, (Const<'tcx>, Ty<'tcx>)> ) -> QueryResult<'tcx>
source§impl<'tcx> EvalCtxt<'_, 'tcx>
impl<'tcx> EvalCtxt<'_, 'tcx>
fn set_normalizes_to_hack_goal(&mut self, goal: Goal<'tcx, NormalizesTo<'tcx>>)
fn add_goal(&mut self, source: GoalSource, goal: Goal<'tcx, Predicate<'tcx>>)
fn add_goals( &mut self, source: GoalSource, goals: impl IntoIterator<Item = Goal<'tcx, Predicate<'tcx>>> )
sourcefn try_merge_responses(
&mut self,
responses: &[CanonicalResponse<'tcx>]
) -> Option<CanonicalResponse<'tcx>>
fn try_merge_responses( &mut self, responses: &[CanonicalResponse<'tcx>] ) -> Option<CanonicalResponse<'tcx>>
Try to merge multiple possible ways to prove a goal, if that is not possible returns None
.
In this case we tend to flounder and return ambiguity by calling [EvalCtxt::flounder]
.
sourcefn flounder(
&mut self,
responses: &[CanonicalResponse<'tcx>]
) -> QueryResult<'tcx>
fn flounder( &mut self, responses: &[CanonicalResponse<'tcx>] ) -> QueryResult<'tcx>
If we fail to merge responses we flounder and return overflow or ambiguity.
sourcefn structurally_normalize_ty(
&mut self,
param_env: ParamEnv<'tcx>,
ty: Ty<'tcx>
) -> Result<Ty<'tcx>, NoSolution>
fn structurally_normalize_ty( &mut self, param_env: ParamEnv<'tcx>, ty: Ty<'tcx> ) -> Result<Ty<'tcx>, NoSolution>
Normalize a type for when it is structurally matched on.
This function is necessary in nearly all cases before matching on a type. Not doing so is likely to be incomplete and therefore unsound during coherence.
Auto Trait Implementations§
impl<'a, 'tcx> !DynSend for EvalCtxt<'a, 'tcx>
impl<'a, 'tcx> !DynSync for EvalCtxt<'a, 'tcx>
impl<'a, 'tcx> Freeze for EvalCtxt<'a, 'tcx>
impl<'a, 'tcx> !RefUnwindSafe for EvalCtxt<'a, 'tcx>
impl<'a, 'tcx> !Send for EvalCtxt<'a, 'tcx>
impl<'a, 'tcx> !Sync for EvalCtxt<'a, 'tcx>
impl<'a, 'tcx> Unpin for EvalCtxt<'a, 'tcx>
impl<'a, 'tcx> !UnwindSafe for EvalCtxt<'a, 'tcx>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
§impl<T> Filterable for T
impl<T> Filterable for T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<'tcx, T> ToPredicate<'tcx, T> for T
impl<'tcx, T> ToPredicate<'tcx, T> for T
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T
source§impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed ) -> T
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> ErasedDestructor for Twhere
T: 'static,
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: 112 bytes