Skip to main content

rustc_next_trait_solver/solve/eval_ctxt/
mod.rs

1use std::mem;
2use std::ops::ControlFlow;
3
4#[cfg(feature = "nightly")]
5use rustc_macros::StableHash;
6use rustc_type_ir::data_structures::{HashMap, HashSet};
7use rustc_type_ir::inherent::*;
8use rustc_type_ir::region_constraint::RegionConstraint;
9use rustc_type_ir::relate::Relate;
10use rustc_type_ir::relate::solver_relating::RelateExt;
11use rustc_type_ir::search_graph::{CandidateHeadUsages, PathKind};
12use rustc_type_ir::solve::{
13    AccessedOpaques, ExternalRegionConstraints, FetchEligibleAssocItemResponse, MaybeInfo,
14    NoSolutionOrRerunNonErased, OpaqueTypesJank, QueryResultOrRerunNonErased, RerunCondition,
15    RerunNonErased, RerunReason, RerunResultExt, SmallCopyList,
16};
17use rustc_type_ir::{
18    self as ty, CanonicalVarValues, ClauseKind, InferCtxtLike, Interner, MayBeErased,
19    OpaqueTypeKey, PredicateKind, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeSuperVisitable,
20    TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode,
21};
22use tracing::{Level, debug, instrument, trace, warn};
23
24use super::has_only_region_constraints;
25use crate::canonical::{
26    canonicalize_goal, canonicalize_response, instantiate_and_apply_query_response,
27    response_no_constraints_raw,
28};
29use crate::coherence;
30use crate::delegate::SolverDelegate;
31use crate::placeholder::BoundVarReplacer;
32use crate::resolve::eager_resolve_vars;
33use crate::solve::search_graph::SearchGraph;
34use crate::solve::ty::may_use_unstable_feature;
35use crate::solve::{
36    CanonicalInput, CanonicalResponse, Certainty, ExternalConstraintsData, FIXPOINT_STEP_LIMIT,
37    Goal, GoalEvaluation, GoalSource, GoalStalledOn, HasChanged, MaybeCause,
38    NestedNormalizationGoals, NoSolution, QueryInput, QueryResult, Response, SucceededInErased,
39    VisibleForLeakCheck, inspect,
40};
41
42mod probe;
43mod solver_region_constraints;
44
45/// The kind of goal we're currently proving.
46///
47/// This has effects on cycle handling handling and on how we compute
48/// query responses, see the variant descriptions for more info.
49#[derive(#[automatically_derived]
impl ::core::fmt::Debug for CurrentGoalKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                CurrentGoalKind::Misc => "Misc",
                CurrentGoalKind::CoinductiveTrait => "CoinductiveTrait",
                CurrentGoalKind::ProjectionComputeAssocTermCandidate =>
                    "ProjectionComputeAssocTermCandidate",
            })
    }
}Debug, #[automatically_derived]
impl ::core::marker::Copy for CurrentGoalKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for CurrentGoalKind {
    #[inline]
    fn clone(&self) -> CurrentGoalKind { *self }
}Clone)]
50enum CurrentGoalKind {
51    Misc,
52    /// We're proving an trait goal for a coinductive trait, either an auto trait or `Sized`.
53    ///
54    /// These are currently the only goals whose impl where-clauses are considered to be
55    /// productive steps.
56    CoinductiveTrait,
57    // FIXME: Consider renaming `PredicateKind::NormalizesTo` to match with this
58    /// Unlike other goals, `NormalizesTo` goals aren't independent goals but just implementation
59    /// details for handling projections of associated terms. When we encounter a `Projection` goal
60    /// whose `projection_term` is an associated term, we create a `NormalizesTo` goal whose
61    /// expected term is fully unconstrained and evaluate it.
62    ///
63    /// This would weaken inference however, as the nested goals of normalizes-to never get the
64    /// inference constraints from the actual expected term. We just gather candidates from the
65    /// normalizes-to goal and return any ambiguous nested goals of it to the caller (`Projection
66    /// goal`). The caller handle and evaluate them as if they were its own nested goals.
67    ///
68    /// Because of this, evaluating a normalizes-to goal is computing candidates for projection of
69    /// an associated term and it never leaks out of the solver.
70    ProjectionComputeAssocTermCandidate,
71}
72
73impl CurrentGoalKind {
74    fn from_query_input<I: Interner>(cx: I, input: QueryInput<I, I::Predicate>) -> CurrentGoalKind {
75        match input.goal.predicate.kind().skip_binder() {
76            ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
77                if cx.trait_is_coinductive(pred.trait_ref.def_id) {
78                    CurrentGoalKind::CoinductiveTrait
79                } else {
80                    CurrentGoalKind::Misc
81                }
82            }
83            ty::PredicateKind::NormalizesTo(_) => {
84                CurrentGoalKind::ProjectionComputeAssocTermCandidate
85            }
86            _ => CurrentGoalKind::Misc,
87        }
88    }
89}
90
91#[derive(#[automatically_derived]
impl ::core::fmt::Debug for RerunDecision {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                RerunDecision::Yes => "Yes",
                RerunDecision::No => "No",
                RerunDecision::EagerlyPropagateToParent =>
                    "EagerlyPropagateToParent",
            })
    }
}Debug)]
92enum RerunDecision {
93    Yes,
94    No,
95    EagerlyPropagateToParent,
96}
97pub struct EvalCtxt<'a, D, I = <D as SolverDelegate>::Interner>
98where
99    D: SolverDelegate<Interner = I>,
100    I: Interner,
101{
102    /// The inference context that backs (mostly) inference and placeholder terms
103    /// instantiated while solving goals.
104    ///
105    /// NOTE: The `InferCtxt` that backs the `EvalCtxt` is intentionally private,
106    /// because the `InferCtxt` is much more general than `EvalCtxt`. Methods such
107    /// as  `take_registered_region_obligations` can mess up query responses,
108    /// using `At::normalize` is totally wrong, calling `evaluate_root_goal` can
109    /// cause coinductive unsoundness, etc.
110    ///
111    /// Methods that are generally of use for trait solving are *intentionally*
112    /// re-declared through the `EvalCtxt` below, often with cleaner signatures
113    /// since we don't care about things like `ObligationCause`s and `Span`s here.
114    /// If some `InferCtxt` method is missing, please first think defensively about
115    /// the method's compatibility with this solver, or if an existing one does
116    /// the job already.
117    delegate: &'a D,
118
119    /// The variable info for the `var_values`, only used to make an ambiguous response
120    /// with no constraints.
121    var_kinds: I::CanonicalVarKinds,
122
123    /// What kind of goal we're currently computing, see the enum definition
124    /// for more info.
125    current_goal_kind: CurrentGoalKind,
126    pub(super) var_values: CanonicalVarValues<I>,
127
128    /// The highest universe index nameable by the caller.
129    ///
130    /// When we enter a new binder inside of the query we create new universes
131    /// which the caller cannot name. We have to be careful with variables from
132    /// these new universes when creating the query response.
133    ///
134    /// Both because these new universes can prevent us from reaching a fixpoint
135    /// if we have a coinductive cycle and because that's the only way we can return
136    /// new placeholders to the caller.
137    pub(super) max_input_universe: ty::UniverseIndex,
138    /// The opaque types from the canonical input. We only need to return opaque types
139    /// which have been added to the storage while evaluating this goal.
140    pub(super) initial_opaque_types_storage_num_entries:
141        <D::Infcx as InferCtxtLike>::OpaqueTypeStorageEntries,
142
143    pub(super) search_graph: &'a mut SearchGraph<D>,
144
145    nested_goals: Vec<(GoalSource, Goal<I, I::Predicate>, Option<GoalStalledOn<I>>)>,
146
147    pub(super) origin_span: I::Span,
148
149    // Has this `EvalCtxt` errored out with `NoSolution` in `try_evaluate_added_goals`?
150    //
151    // If so, then it can no longer be used to make a canonical query response,
152    // since subsequent calls to `try_evaluate_added_goals` have possibly dropped
153    // ambiguous goals. Instead, a probe needs to be introduced somewhere in the
154    // evaluation code.
155    tainted: Result<(), NoSolution>,
156
157    /// Tracks accesses of opaque types while in [`TypingMode::ErasedNotCoherence`].
158    pub(super) opaque_accesses: AccessedOpaques<I>,
159
160    pub(super) inspect: inspect::EvaluationStepBuilder<D>,
161}
162
163#[derive(#[automatically_derived]
impl ::core::cmp::PartialEq for GenerateProofTree {
    #[inline]
    fn eq(&self, other: &GenerateProofTree) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for GenerateProofTree {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for GenerateProofTree {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                GenerateProofTree::Yes => "Yes",
                GenerateProofTree::No => "No",
            })
    }
}Debug, #[automatically_derived]
impl ::core::hash::Hash for GenerateProofTree {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state)
    }
}Hash, #[automatically_derived]
impl ::core::clone::Clone for GenerateProofTree {
    #[inline]
    fn clone(&self) -> GenerateProofTree { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for GenerateProofTree { }Copy)]
164#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            GenerateProofTree {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    GenerateProofTree::Yes => {}
                    GenerateProofTree::No => {}
                }
            }
        }
    };StableHash))]
165pub enum GenerateProofTree {
166    Yes,
167    No,
168}
169
170pub trait SolverDelegateEvalExt: SolverDelegate {
171    /// Evaluates a goal from **outside** of the trait solver.
172    ///
173    /// Using this while inside of the solver is wrong as it uses a new
174    /// search graph which would break cycle detection.
175    fn evaluate_root_goal(
176        &self,
177        goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
178        span: <Self::Interner as Interner>::Span,
179        stalled_on: Option<GoalStalledOn<Self::Interner>>,
180    ) -> Result<GoalEvaluation<Self::Interner>, NoSolution>;
181
182    /// Checks whether evaluating `goal` may hold while treating not-yet-defined
183    /// opaque types as being kind of rigid.
184    ///
185    /// See the comment on [OpaqueTypesJank] for more details.
186    fn root_goal_may_hold_opaque_types_jank(
187        &self,
188        goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
189    ) -> bool;
190
191    /// Check whether evaluating `goal` with a depth of `root_depth` may
192    /// succeed. This only returns `false` if the goal is guaranteed to
193    /// not hold. In case evaluation overflows and fails with ambiguity this
194    /// returns `true`.
195    ///
196    /// This is only intended to be used as a performance optimization
197    /// in coherence checking.
198    fn root_goal_may_hold_with_depth(
199        &self,
200        root_depth: usize,
201        goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
202    ) -> bool;
203
204    // FIXME: This is only exposed because we need to use it in `analyse.rs`
205    // which is not yet uplifted. Once that's done, we should remove this.
206    fn evaluate_root_goal_for_proof_tree(
207        &self,
208        goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
209        span: <Self::Interner as Interner>::Span,
210    ) -> (
211        Result<NestedNormalizationGoals<Self::Interner>, NoSolution>,
212        inspect::GoalEvaluation<Self::Interner>,
213    );
214}
215
216impl<D, I> SolverDelegateEvalExt for D
217where
218    D: SolverDelegate<Interner = I>,
219    I: Interner,
220{
221    x;#[instrument(level = "debug", skip(self), ret)]
222    fn evaluate_root_goal(
223        &self,
224        goal: Goal<I, I::Predicate>,
225        span: I::Span,
226        stalled_on: Option<GoalStalledOn<I>>,
227    ) -> Result<GoalEvaluation<I>, NoSolution> {
228        let result = EvalCtxt::enter_root(self, self.cx().recursion_limit(), span, |ecx| {
229            ecx.evaluate_goal(GoalSource::Misc, goal, stalled_on)
230        });
231
232        match result {
233            Ok(i) => Ok(i),
234            Err(NoSolutionOrRerunNonErased::NoSolution(NoSolution)) => Err(NoSolution),
235            Err(NoSolutionOrRerunNonErased::RerunNonErased(_)) => {
236                unreachable!("this never happens at the root, we're never in erased mode here");
237            }
238        }
239    }
240
241    x;#[instrument(level = "debug", skip(self), ret)]
242    fn root_goal_may_hold_opaque_types_jank(
243        &self,
244        goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
245    ) -> bool {
246        self.probe(|| {
247            EvalCtxt::enter_root(self, self.cx().recursion_limit(), I::Span::dummy(), |ecx| {
248                ecx.evaluate_goal(GoalSource::Misc, goal, None)
249            })
250            .is_ok_and(|r| match r.certainty {
251                Certainty::Yes => true,
252                Certainty::Maybe(MaybeInfo {
253                    cause: _,
254                    opaque_types_jank,
255                    stalled_on_coroutines: _,
256                }) => match opaque_types_jank {
257                    OpaqueTypesJank::AllGood => true,
258                    OpaqueTypesJank::ErrorIfRigidSelfTy => false,
259                },
260            })
261        })
262    }
263
264    fn root_goal_may_hold_with_depth(
265        &self,
266        root_depth: usize,
267        goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
268    ) -> bool {
269        self.probe(|| {
270            EvalCtxt::enter_root(self, root_depth, I::Span::dummy(), |ecx| {
271                ecx.evaluate_goal(GoalSource::Misc, goal, None)
272            })
273        })
274        .is_ok()
275    }
276
277    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("evaluate_root_goal_for_proof_tree",
                                    "rustc_next_trait_solver::solve::eval_ctxt",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(277u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                                    ::tracing_core::field::FieldSet::new(&["goal", "span"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&goal)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return:
                    (Result<NestedNormalizationGoals<I>, NoSolution>,
                    inspect::GoalEvaluation<I>) = loop {};
            return __tracing_attr_fake_return;
        }
        { evaluate_root_goal_for_proof_tree(self, goal, span) }
    }
}#[instrument(level = "debug", skip(self))]
278    fn evaluate_root_goal_for_proof_tree(
279        &self,
280        goal: Goal<I, I::Predicate>,
281        span: I::Span,
282    ) -> (Result<NestedNormalizationGoals<I>, NoSolution>, inspect::GoalEvaluation<I>) {
283        evaluate_root_goal_for_proof_tree(self, goal, span)
284    }
285}
286
287#[derive(#[automatically_derived]
impl ::core::fmt::Debug for RerunStalled {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            RerunStalled::WontMakeProgress(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "WontMakeProgress", &__self_0),
            RerunStalled::MayMakeProgress =>
                ::core::fmt::Formatter::write_str(f, "MayMakeProgress"),
        }
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for RerunStalled {
    #[inline]
    fn clone(&self) -> RerunStalled {
        let _: ::core::clone::AssertParamIsClone<Certainty>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for RerunStalled { }Copy)]
288enum RerunStalled {
289    WontMakeProgress(Certainty),
290    MayMakeProgress,
291}
292
293impl<'a, D, I> EvalCtxt<'a, D>
294where
295    D: SolverDelegate<Interner = I>,
296    I: Interner,
297{
298    pub(super) fn typing_mode(&self) -> TypingMode<I> {
299        self.delegate.typing_mode_raw()
300    }
301
302    /// Computes the `PathKind` for the step from the current goal to the
303    /// nested goal required due to `source`.
304    ///
305    /// See #136824 for a more detailed reasoning for this behavior. We
306    /// consider cycles to be coinductive if they 'step into' a where-clause
307    /// of a coinductive trait. We will likely extend this function in the future
308    /// and will need to clearly document it in the rustc-dev-guide before
309    /// stabilization.
310    pub(super) fn step_kind_for_source(&self, source: GoalSource) -> PathKind {
311        match source {
312            // We treat these goals as unknown for now. It is likely that most miscellaneous
313            // nested goals will be converted to an inductive variant in the future.
314            //
315            // Having unknown cycles is always the safer option, as changing that to either
316            // succeed or hard error is backwards compatible. If we incorrectly treat a cycle
317            // as inductive even though it should not be, it may be unsound during coherence and
318            // fixing it may cause inference breakage or introduce ambiguity.
319            GoalSource::Misc => PathKind::Unknown,
320            GoalSource::NormalizeGoal(path_kind) => path_kind,
321            GoalSource::ImplWhereBound => match self.current_goal_kind {
322                // We currently only consider a cycle coinductive if it steps
323                // into a where-clause of a coinductive trait.
324                CurrentGoalKind::CoinductiveTrait => PathKind::Coinductive,
325                // While normalizing via an impl does step into a where-clause of
326                // an impl, accessing the associated item immediately steps out of
327                // it again. This means cycles/recursive calls are not guarded
328                // by impls used for normalization.
329                //
330                // See tests/ui/traits/next-solver/cycles/normalizes-to-is-not-productive.rs
331                // for how this can go wrong.
332                CurrentGoalKind::ProjectionComputeAssocTermCandidate => PathKind::Inductive,
333                // We probably want to make all traits coinductive in the future,
334                // so we treat cycles involving where-clauses of not-yet coinductive
335                // traits as ambiguous for now.
336                CurrentGoalKind::Misc => PathKind::Unknown,
337            },
338            // Relating types is always unproductive. If we were to map proof trees to
339            // corecursive functions as explained in #136824, relating types never
340            // introduces a constructor which could cause the recursion to be guarded.
341            GoalSource::TypeRelating => PathKind::Inductive,
342            // These goal sources are likely unproductive and can be changed to
343            // `PathKind::Inductive`. Keeping them as unknown until we're confident
344            // about this and have an example where it is necessary.
345            GoalSource::AliasBoundConstCondition | GoalSource::AliasWellFormed => PathKind::Unknown,
346        }
347    }
348
349    /// Creates a root evaluation context and search graph. This should only be
350    /// used from outside of any evaluation, and other methods should be preferred
351    /// over using this manually (such as [`SolverDelegateEvalExt::evaluate_root_goal`]).
352    pub(super) fn enter_root<R>(
353        delegate: &D,
354        root_depth: usize,
355        origin_span: I::Span,
356        f: impl FnOnce(&mut EvalCtxt<'_, D>) -> R,
357    ) -> R {
358        let mut search_graph = SearchGraph::new(root_depth);
359
360        let mut ecx = EvalCtxt {
361            delegate,
362            search_graph: &mut search_graph,
363            nested_goals: Default::default(),
364            inspect: inspect::EvaluationStepBuilder::new_noop(),
365
366            // Only relevant when canonicalizing the response,
367            // which we don't do within this evaluation context.
368            max_input_universe: ty::UniverseIndex::ROOT,
369            initial_opaque_types_storage_num_entries: Default::default(),
370            var_kinds: Default::default(),
371            var_values: CanonicalVarValues::dummy(),
372            current_goal_kind: CurrentGoalKind::Misc,
373            origin_span,
374            tainted: Ok(()),
375            opaque_accesses: AccessedOpaques::default(),
376        };
377        let result = f(&mut ecx);
378        if !ecx.nested_goals.is_empty() {
    {
        ::core::panicking::panic_fmt(format_args!("root `EvalCtxt` should not have any goals added to it"));
    }
};assert!(
379            ecx.nested_goals.is_empty(),
380            "root `EvalCtxt` should not have any goals added to it"
381        );
382        if !!ecx.opaque_accesses.might_rerun() {
    ::core::panicking::panic("assertion failed: !ecx.opaque_accesses.might_rerun()")
};assert!(!ecx.opaque_accesses.might_rerun());
383        if !search_graph.is_empty() {
    ::core::panicking::panic("assertion failed: search_graph.is_empty()")
};assert!(search_graph.is_empty());
384        result
385    }
386
387    /// Creates a nested evaluation context that shares the same search graph as the
388    /// one passed in. This is suitable for evaluation, granted that the search graph
389    /// has had the nested goal recorded on its stack. This method only be used by
390    /// `search_graph::Delegate::compute_goal`.
391    ///
392    /// This function takes care of setting up the inference context, setting the anchor,
393    /// and registering opaques from the canonicalized input.
394    pub(super) fn enter_canonical<T>(
395        cx: I,
396        search_graph: &'a mut SearchGraph<D>,
397        canonical_input: CanonicalInput<I>,
398        proof_tree_builder: &mut inspect::ProofTreeBuilder<D>,
399        f: impl FnOnce(
400            &mut EvalCtxt<'_, D>,
401            Goal<I, I::Predicate>,
402        ) -> Result<T, NoSolutionOrRerunNonErased>,
403    ) -> (Result<T, NoSolution>, AccessedOpaques<I>) {
404        let (ref delegate, input, var_values) = D::build_with_canonical(cx, &canonical_input);
405        for (key, ty) in input.predefined_opaques_in_body.iter() {
406            let prev = delegate.register_hidden_type_in_storage(key, ty, I::Span::dummy());
407            // It may be possible that two entries in the opaque type storage end up
408            // with the same key after resolving contained inference variables.
409            //
410            // We could put them in the duplicate list but don't have to. The opaques we
411            // encounter here are already tracked in the caller, so there's no need to
412            // also store them here. We'd take them out when computing the query response
413            // and then discard them, as they're already present in the input.
414            //
415            // Ideally we'd drop duplicate opaque type definitions when computing
416            // the canonical input. This is more annoying to implement and may cause a
417            // perf regression, so we do it inside of the query for now.
418            if let Some(prev) = prev {
419                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:419",
                        "rustc_next_trait_solver::solve::eval_ctxt",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(419u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                        ::tracing_core::field::FieldSet::new(&["message", "key",
                                        "ty", "prev"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("ignore duplicate in `opaque_types_storage`")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&key) as
                                            &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&ty) as
                                            &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&prev) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?key, ?ty, ?prev, "ignore duplicate in `opaque_types_storage`");
420            }
421        }
422
423        let initial_opaque_types_storage_num_entries = delegate.opaque_types_storage_num_entries();
424        if truecfg!(debug_assertions) && delegate.typing_mode_raw().is_erased_not_coherence() {
425            if !delegate.clone_opaque_types_lookup_table().is_empty() {
    ::core::panicking::panic("assertion failed: delegate.clone_opaque_types_lookup_table().is_empty()")
};assert!(delegate.clone_opaque_types_lookup_table().is_empty());
426        }
427
428        let mut ecx = EvalCtxt {
429            delegate,
430            var_kinds: canonical_input.canonical.var_kinds,
431            var_values,
432            current_goal_kind: CurrentGoalKind::from_query_input(cx, input),
433            max_input_universe: canonical_input.canonical.max_universe,
434            initial_opaque_types_storage_num_entries,
435            search_graph,
436            nested_goals: Default::default(),
437            origin_span: I::Span::dummy(),
438            tainted: Ok(()),
439            inspect: proof_tree_builder.new_evaluation_step(var_values),
440            opaque_accesses: AccessedOpaques::default(),
441        };
442
443        let result = f(&mut ecx, input.goal);
444        ecx.inspect.probe_final_state(ecx.delegate, ecx.max_input_universe);
445        proof_tree_builder.finish_evaluation_step(ecx.inspect);
446
447        if canonical_input.typing_mode.0.is_erased_not_coherence() {
448            if true {
    if !delegate.clone_opaque_types_lookup_table().is_empty() {
        ::core::panicking::panic("assertion failed: delegate.clone_opaque_types_lookup_table().is_empty()")
    };
};debug_assert!(delegate.clone_opaque_types_lookup_table().is_empty());
449        }
450
451        // When creating a query response we clone the opaque type constraints
452        // instead of taking them. This would cause an ICE here, since we have
453        // assertions against dropping an `InferCtxt` without taking opaques.
454        // FIXME: Once we remove support for the old impl we can remove this.
455        // FIXME: Could we make `build_with_canonical` into `enter_with_canonical` and call this at the end?
456        delegate.reset_opaque_types();
457
458        let opaque_accesses = ecx.opaque_accesses;
459        (
460            match result {
461                Ok(i) => Ok(i),
462                Err(NoSolutionOrRerunNonErased::NoSolution(NoSolution)) => Err(NoSolution),
463                Err(NoSolutionOrRerunNonErased::RerunNonErased(_)) => {
464                    // check th t the opaque_accesses state mirrors the result we got.
465                    if !opaque_accesses.should_bail().is_err() {
    ::core::panicking::panic("assertion failed: opaque_accesses.should_bail().is_err()")
};assert!(opaque_accesses.should_bail().is_err());
466                    Err(NoSolution)
467                }
468            },
469            opaque_accesses,
470        )
471    }
472
473    pub(super) fn ignore_candidate_head_usages(&mut self, usages: CandidateHeadUsages) {
474        self.search_graph.ignore_candidate_head_usages(usages);
475    }
476
477    /// Recursively evaluates `goal`, returning whether any inference vars have
478    /// been constrained and the certainty of the result.
479    fn evaluate_goal(
480        &mut self,
481        source: GoalSource,
482        goal: Goal<I, I::Predicate>,
483        stalled_on: Option<GoalStalledOn<I>>,
484    ) -> Result<GoalEvaluation<I>, NoSolutionOrRerunNonErased> {
485        let (normalization_nested_goals, goal_evaluation) =
486            self.evaluate_goal_raw(source, goal, stalled_on)?;
487        if !normalization_nested_goals.is_empty() {
    ::core::panicking::panic("assertion failed: normalization_nested_goals.is_empty()")
};assert!(normalization_nested_goals.is_empty());
488        Ok(goal_evaluation)
489    }
490
491    /// This is a fast path optimization:
492    /// If we have run this goal before, and it was stalled, check that any of the goal's
493    /// args have changed. This is a cheap way to determine that if we were to rerun this goal now,
494    /// it will remain stalled since it'll canonicalize the same way and evaluation is pure.
495    /// Therefore, we can skip this rerun
496    fn rerunning_stalled_goal_may_make_progress(
497        &self,
498        stalled_on: Option<&GoalStalledOn<I>>,
499    ) -> RerunStalled {
500        use RerunStalled::*;
501
502        // If fast paths are turned off, then we assume all goals can always make progress
503        if self.delegate.disable_trait_solver_fast_paths() {
504            return MayMakeProgress;
505        }
506
507        // If the goal isn't stalled, we should definitely run it.
508        let Some(&GoalStalledOn {
509            num_opaques,
510            ref stalled_vars,
511            ref sub_roots,
512            stalled_certainty,
513            ref previously_succeeded_in_erased,
514        }) = stalled_on
515        else {
516            return MayMakeProgress;
517        };
518
519        // If any of the stalled goal's generic arguments changed,
520        // rerunning might make progress so we should rerun.
521        if stalled_vars.iter().any(|value| self.delegate.is_changed_arg(*value)) {
522            return MayMakeProgress;
523        }
524
525        // If some inference took place in any of the sub roots,
526        // rerunning might make progress so we should rerun.
527        if sub_roots.iter().any(|&vid| self.delegate.sub_unification_table_root_var(vid) != vid) {
528            return MayMakeProgress;
529        }
530
531        // If any opaques changed in the opaque type storage,
532        // rerunning might make progress so we should rerun.
533        if self.delegate.opaque_types_storage_num_entries().needs_reevaluation(num_opaques) {
534            // Unless this goal previously succeeded in erased mode.
535            // If the stalled goal successfully evaluated while erasing opaque types,
536            // and the current state of the opaque type storage is not different in a way that is
537            // relevant, this stalled goal cannot make any progress and we set this variable to true.
538            let mut previous_erased_run_is_still_valid = false;
539
540            if let &SucceededInErased::Yes { accessed_opaques } = previously_succeeded_in_erased {
541                match self.should_rerun_after_erased_canonicalization(
542                    accessed_opaques,
543                    self.typing_mode(),
544                    &self.delegate.clone_opaque_types_lookup_table(),
545                ) {
546                    RerunDecision::Yes => {}
547                    RerunDecision::EagerlyPropagateToParent => {
548                        {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("we never retry stalled queries if the parent was erased")));
}unreachable!("we never retry stalled queries if the parent was erased")
549                    }
550                    RerunDecision::No => {
551                        previous_erased_run_is_still_valid = true;
552                    }
553                }
554            }
555
556            if !previous_erased_run_is_still_valid {
557                return MayMakeProgress;
558            }
559        }
560
561        // Otherwise, we can be sure that this stalled goal cannot make any progress
562        // and we can exit early.
563        WontMakeProgress(stalled_certainty)
564    }
565
566    /// Recursively evaluates `goal`, returning the nested goals in case
567    /// the nested goal is a `NormalizesTo` goal.
568    ///
569    /// As all other goal kinds do not return any nested goals and
570    /// `NormalizesTo` is only used by `Projection`, all other callsites
571    /// should use [`EvalCtxt::evaluate_goal`] which discards that empty
572    /// storage.
573    pub(super) fn evaluate_goal_raw(
574        &mut self,
575        source: GoalSource,
576        goal: Goal<I, I::Predicate>,
577        stalled_on: Option<GoalStalledOn<I>>,
578    ) -> Result<(NestedNormalizationGoals<I>, GoalEvaluation<I>), NoSolutionOrRerunNonErased> {
579        if let RerunStalled::WontMakeProgress(stalled_certainty) =
580            self.rerunning_stalled_goal_may_make_progress(stalled_on.as_ref())
581        {
582            return Ok((
583                NestedNormalizationGoals::empty(),
584                GoalEvaluation {
585                    goal,
586                    certainty: stalled_certainty,
587                    has_changed: HasChanged::No,
588                    stalled_on,
589                },
590            ));
591        }
592
593        self.evaluate_goal_cold(source, goal)
594    }
595
596    #[cold]
597    #[inline(never)]
598    pub(super) fn evaluate_goal_cold(
599        &mut self,
600        source: GoalSource,
601        goal: Goal<I, I::Predicate>,
602    ) -> Result<(NestedNormalizationGoals<I>, GoalEvaluation<I>), NoSolutionOrRerunNonErased> {
603        // We only care about one entry per `OpaqueTypeKey` here,
604        // so we only canonicalize the lookup table and ignore
605        // duplicate entries.
606        let opaque_types = self.delegate.clone_opaque_types_lookup_table();
607        let (goal, opaque_types) = eager_resolve_vars(self.delegate, (goal, opaque_types));
608        let typing_mode = self.typing_mode();
609        let step_kind = self.step_kind_for_source(source);
610
611        let tracing_span = {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("evaluate_goal_raw in typing mode",
                        "rustc_next_trait_solver::solve::eval_ctxt", Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(611u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::SPAN)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let mut interest = ::tracing::subscriber::Interest::never();
    if Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
                    Level::DEBUG <=
                        ::tracing::level_filters::LevelFilter::current() &&
                { interest = __CALLSITE.interest(); !interest.is_never() } &&
            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                interest) {
        let meta = __CALLSITE.metadata();
        ::tracing::Span::new(meta,
            &{
                    #[allow(unused_imports)]
                    use ::tracing::field::{debug, display, Value};
                    let mut iter = meta.fields().iter();
                    meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                        ::tracing::__macro_support::Option::Some(&format_args!("{0:?} opaques={1:?}",
                                                        typing_mode, opaque_types) as &dyn Value))])
                })
    } else {
        let span =
            ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
        {};
        span
    }
}tracing::span!(
612            Level::DEBUG,
613            "evaluate_goal_raw in typing mode",
614            "{:?} opaques={:?}",
615            typing_mode,
616            opaque_types
617        )
618        .entered();
619
620        let (result, orig_values, canonical_goal, succeeded_in_erased) = 'retry_canonicalize: {
621            let skip_erased_attempt = if typing_mode.is_coherence() {
622                true
623            } else {
624                let mut skip = false;
625                if opaque_types.iter().any(|(_, ty)| ty.is_ty_var())
626                    && let PredicateKind::Clause(ClauseKind::Trait(..)) =
627                        goal.predicate.kind().skip_binder()
628                {
629                    skip = true;
630                }
631
632                if let PredicateKind::Clause(ClauseKind::Trait(tr)) =
633                    goal.predicate.kind().skip_binder()
634                    && tr.self_ty().has_coroutines()
635                    && self.cx().trait_is_auto(tr.trait_ref.def_id)
636                {
637                    // FIXME(#155443): this doesn't make a difference now, but with eager normalization
638                    // it likely will.
639                    // skip_erased_attempt = true;
640                }
641
642                skip
643            };
644
645            if skip_erased_attempt {
646                if typing_mode.is_erased_not_coherence() {
647                    match self.opaque_accesses.rerun_always(RerunReason::SkipErasedAttempt)? {}
648                } else {
649                    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:649",
                        "rustc_next_trait_solver::solve::eval_ctxt",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(649u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("running in original typing mode")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("running in original typing mode");
650                }
651            } else {
652                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:652",
                        "rustc_next_trait_solver::solve::eval_ctxt",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(652u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("trying without opaques: {0:?}",
                                                    goal) as &dyn Value))])
            });
    } else { ; }
};debug!("trying without opaques: {goal:?}");
653
654                let (orig_values, canonical_goal) = canonicalize_goal(
655                    self.delegate,
656                    goal,
657                    &[],
658                    TypingMode::ErasedNotCoherence(MayBeErased),
659                );
660
661                let (canonical_result, accessed_opaques) = self.search_graph.evaluate_goal(
662                    self.cx(),
663                    canonical_goal,
664                    step_kind,
665                    &mut inspect::ProofTreeBuilder::new_noop(),
666                );
667
668                let should_rerun = self.should_rerun_after_erased_canonicalization(
669                    accessed_opaques,
670                    self.typing_mode(),
671                    &opaque_types,
672                );
673                match should_rerun {
674                    RerunDecision::Yes => {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:674",
                        "rustc_next_trait_solver::solve::eval_ctxt",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(674u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("rerunning in original typing mode")
                                            as &dyn Value))])
            });
    } else { ; }
}debug!("rerunning in original typing mode"),
675                    RerunDecision::No => {
676                        break 'retry_canonicalize (
677                            canonical_result,
678                            orig_values,
679                            canonical_goal,
680                            SucceededInErased::Yes { accessed_opaques },
681                        );
682                    }
683                    RerunDecision::EagerlyPropagateToParent => {
684                        self.opaque_accesses.update(accessed_opaques)?;
685                        break 'retry_canonicalize (
686                            canonical_result,
687                            orig_values,
688                            canonical_goal,
689                            // If we're propagating up, we should never retry the goal.
690                            // That means `No` is fine to return, it doesn't really matter.
691                            SucceededInErased::No,
692                        );
693                    }
694                }
695            }
696
697            let (orig_values, canonical_goal) =
698                canonicalize_goal(self.delegate, goal, &opaque_types, typing_mode);
699
700            let (canonical_result, accessed_opaques) = self.search_graph.evaluate_goal(
701                self.cx(),
702                canonical_goal,
703                step_kind,
704                &mut inspect::ProofTreeBuilder::new_noop(),
705            );
706            if !!accessed_opaques.might_rerun() {
    {
        ::core::panicking::panic_fmt(format_args!("we run without TypingMode::ErasedNotCoherence, so opaques are available, and we don\'t retry if the outer typing mode is ErasedNotCoherence: {0:?} after {1:?}",
                accessed_opaques, goal));
    }
};assert!(
707                !accessed_opaques.might_rerun(),
708                "we run without TypingMode::ErasedNotCoherence, so opaques are available, and we don't retry if the outer typing mode is ErasedNotCoherence: {accessed_opaques:?} after {goal:?}"
709            );
710
711            (canonical_result, orig_values, canonical_goal, SucceededInErased::No)
712        };
713
714        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:714",
                        "rustc_next_trait_solver::solve::eval_ctxt",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(714u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                        ::tracing_core::field::FieldSet::new(&["result"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&result) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?result);
715        let response = match result {
716            Ok(response) => {
717                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:717",
                        "rustc_next_trait_solver::solve::eval_ctxt",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(717u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("success")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("success");
718                response
719            }
720            Err(NoSolution) => {
721                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:721",
                        "rustc_next_trait_solver::solve::eval_ctxt",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(721u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("normal failure")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("normal failure");
722                return Err(NoSolution.into());
723            }
724        };
725
726        drop(tracing_span);
727
728        let has_changed =
729            if !has_only_region_constraints(response) { HasChanged::Yes } else { HasChanged::No };
730
731        // FIXME: We should revisit and consider removing this after
732        // *assumptions on binders* is available, like once we had done in the
733        // stabilization of `-Znext-solver=coherence`(#121848).
734        // We ignore constraints from the nested goals in leak check. This is to match
735        // with the old solver's behavior, which has separated evaluation and fulfillment,
736        // and the former doesn't consider outlives obligations from the later.
737        let vis = match goal.predicate.kind().skip_binder() {
738            ty::PredicateKind::Clause(_)
739            | ty::PredicateKind::DynCompatible(_)
740            | ty::PredicateKind::Subtype(_)
741            | ty::PredicateKind::Coerce(_)
742            | ty::PredicateKind::ConstEquate(_, _)
743            | ty::PredicateKind::Ambiguous
744            | ty::PredicateKind::NormalizesTo(_) => VisibleForLeakCheck::No,
745            ty::PredicateKind::AliasRelate(_, _, _) => VisibleForLeakCheck::Yes,
746        };
747
748        let (normalization_nested_goals, certainty) = instantiate_and_apply_query_response(
749            self.delegate,
750            goal.param_env,
751            &orig_values,
752            response,
753            vis,
754            self.origin_span,
755        );
756
757        // FIXME: We previously had an assert here that checked that recomputing
758        // a goal after applying its constraints did not change its response.
759        //
760        // This assert was removed as it did not hold for goals constraining
761        // an inference variable to a recursive alias, e.g. in
762        // tests/ui/traits/next-solver/overflow/recursive-self-normalization.rs.
763        //
764        // Once we have decided on how to handle trait-system-refactor-initiative#75,
765        // we should re-add an assert here.
766
767        let stalled_on = match certainty {
768            Certainty::Yes => None,
769            Certainty::Maybe { .. } => match has_changed {
770                // FIXME: We could recompute a *new* set of stalled variables by walking
771                // through the orig values, resolving, and computing the root vars of anything
772                // that is not resolved. Only when *these* have changed is it meaningful
773                // to recompute this goal.
774                HasChanged::Yes => None,
775                HasChanged::No => {
776                    // Remove the canonicalized universal vars, since we only care about stalled existentials.
777                    let mut sub_roots = Vec::new();
778                    let mut stalled_vars = orig_values;
779                    stalled_vars.retain(|arg| match arg.kind() {
780                        // Lifetimes can never stall goals.
781                        ty::GenericArgKind::Lifetime(_) => false,
782                        ty::GenericArgKind::Type(ty) => match ty.kind() {
783                            ty::Infer(ty::TyVar(vid)) => {
784                                sub_roots.push(self.delegate.sub_unification_table_root_var(vid));
785                                true
786                            }
787                            ty::Infer(_) => true,
788                            ty::Param(_) | ty::Placeholder(_) => false,
789                            _ => {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("unexpected orig_value: {0:?}", ty)));
}unreachable!("unexpected orig_value: {ty:?}"),
790                        },
791                        ty::GenericArgKind::Const(ct) => match ct.kind() {
792                            ty::ConstKind::Infer(_) => true,
793                            ty::ConstKind::Param(_) | ty::ConstKind::Placeholder(_) => false,
794                            _ => {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("unexpected orig_value: {0:?}", ct)));
}unreachable!("unexpected orig_value: {ct:?}"),
795                        },
796                    });
797
798                    Some(GoalStalledOn {
799                        num_opaques: canonical_goal
800                            .canonical
801                            .value
802                            .predefined_opaques_in_body
803                            .len(),
804                        stalled_vars,
805                        sub_roots,
806                        stalled_certainty: certainty,
807                        previously_succeeded_in_erased: succeeded_in_erased,
808                    })
809                }
810            },
811        };
812
813        Ok((
814            normalization_nested_goals,
815            GoalEvaluation { goal, certainty, has_changed, stalled_on },
816        ))
817    }
818
819    fn should_rerun_after_erased_canonicalization(
820        &self,
821        AccessedOpaques { reason: _, rerun }: AccessedOpaques<I>,
822        original_typing_mode: TypingMode<I>,
823        parent_opaque_types: &[(OpaqueTypeKey<I>, I::Ty)],
824    ) -> RerunDecision {
825        let parent_opaque_defids = parent_opaque_types.iter().map(|(key, _)| key.def_id.into());
826        let opaque_in_storage = |opaques: I::LocalDefIds, defids: SmallCopyList<_>| {
827            if defids.as_ref().is_empty() {
828                RerunDecision::No
829            } else if opaques
830                .iter()
831                .chain(parent_opaque_defids)
832                .any(|opaque| defids.as_ref().contains(&opaque))
833            {
834                RerunDecision::Yes
835            } else {
836                RerunDecision::No
837            }
838        };
839        let any_opaque_has_infer_as_hidden = || {
840            if parent_opaque_types.iter().any(|(_, ty)| ty.is_ty_var()) {
841                RerunDecision::Yes
842            } else {
843                RerunDecision::No
844            }
845        };
846
847        let res = match (rerun, original_typing_mode) {
848            // =============================
849            (RerunCondition::Never, _) => RerunDecision::No,
850            // =============================
851            (_, TypingMode::ErasedNotCoherence(MayBeErased)) => {
852                RerunDecision::EagerlyPropagateToParent
853            }
854            // =============================
855            // In coherence, we never switch to erased mode, so we will never register anything
856            // in the rerun state, so we should've taken the first branch of this match
857            (_, TypingMode::Coherence) => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
858            // =============================
859            (RerunCondition::Always, _) => RerunDecision::Yes,
860            // =============================
861            (
862                RerunCondition::OpaqueInStorage(..),
863                TypingMode::PostAnalysis | TypingMode::Codegen,
864            ) => RerunDecision::Yes,
865            (
866                RerunCondition::OpaqueInStorage(defids),
867                TypingMode::PostBorrowck { defined_opaque_types: opaques }
868                | TypingMode::Typeck { defining_opaque_types_and_generators: opaques }
869                | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: opaques },
870            ) => opaque_in_storage(opaques, defids),
871            // =============================
872            (RerunCondition::AnyOpaqueHasInferAsHidden, TypingMode::Typeck { .. }) => {
873                any_opaque_has_infer_as_hidden()
874            }
875            (
876                RerunCondition::AnyOpaqueHasInferAsHidden,
877                TypingMode::PostBorrowck { .. }
878                | TypingMode::PostAnalysis
879                | TypingMode::Codegen
880                | TypingMode::PostTypeckUntilBorrowck { .. },
881            ) => RerunDecision::No,
882            // =============================
883            (
884                RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(_),
885                TypingMode::PostAnalysis | TypingMode::Codegen,
886            ) => RerunDecision::No,
887            (
888                RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(defids),
889                TypingMode::Typeck { defining_opaque_types_and_generators: opaques },
890            ) => {
891                if let RerunDecision::Yes = any_opaque_has_infer_as_hidden() {
892                    RerunDecision::Yes
893                } else if let RerunDecision::Yes = opaque_in_storage(opaques, defids) {
894                    RerunDecision::Yes
895                } else {
896                    RerunDecision::No
897                }
898            }
899            (
900                RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(defids),
901                TypingMode::PostBorrowck { defined_opaque_types: opaques }
902                | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: opaques },
903            ) => opaque_in_storage(opaques, defids),
904        };
905
906        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:906",
                        "rustc_next_trait_solver::solve::eval_ctxt",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(906u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("checking whether to rerun {0:?} in outer typing mode {1:?} and opaques {2:?}: {3:?}",
                                                    rerun, original_typing_mode, parent_opaque_types, res) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(
907            "checking whether to rerun {rerun:?} in outer typing mode {original_typing_mode:?} and opaques {parent_opaque_types:?}: {res:?}"
908        );
909
910        res
911    }
912
913    pub(super) fn compute_goal(
914        &mut self,
915        goal: Goal<I, I::Predicate>,
916    ) -> QueryResultOrRerunNonErased<I> {
917        let Goal { param_env, predicate } = goal;
918        let kind = predicate.kind();
919        self.enter_forall_with_assumptions(kind, param_env, |ecx, kind| {
920            Ok(match kind {
921                ty::PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => {
922                    ecx.compute_trait_goal(Goal { param_env, predicate }).map(|(r, _via)| r)?
923                }
924                ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(predicate)) => {
925                    ecx.compute_host_effect_goal(Goal { param_env, predicate })?
926                }
927                ty::PredicateKind::Clause(ty::ClauseKind::Projection(predicate)) => {
928                    ecx.compute_projection_goal(Goal { param_env, predicate })?
929                }
930                ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(predicate)) => {
931                    ecx.compute_type_outlives_goal(Goal { param_env, predicate })?
932                }
933                ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(predicate)) => {
934                    ecx.compute_region_outlives_goal(Goal { param_env, predicate })?
935                }
936                ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
937                    ecx.compute_const_arg_has_type_goal(Goal { param_env, predicate: (ct, ty) })?
938                }
939                ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
940                    ecx.compute_unstable_feature_goal(param_env, symbol)?
941                }
942                ty::PredicateKind::Subtype(predicate) => {
943                    ecx.compute_subtype_goal(Goal { param_env, predicate })?
944                }
945                ty::PredicateKind::Coerce(predicate) => {
946                    ecx.compute_coerce_goal(Goal { param_env, predicate })?
947                }
948                ty::PredicateKind::DynCompatible(trait_def_id) => {
949                    ecx.compute_dyn_compatible_goal(trait_def_id)?
950                }
951                ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => {
952                    ecx.compute_well_formed_goal(Goal { param_env, predicate: term })?
953                }
954                ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(ct)) => {
955                    ecx.compute_const_evaluatable_goal(Goal { param_env, predicate: ct })?
956                }
957                ty::PredicateKind::ConstEquate(_, _) => {
958                    {
    ::core::panicking::panic_fmt(format_args!("ConstEquate should not be emitted when `-Znext-solver` is active"));
}panic!("ConstEquate should not be emitted when `-Znext-solver` is active")
959                }
960                ty::PredicateKind::NormalizesTo(predicate) => {
961                    ecx.compute_normalizes_to_goal(Goal { param_env, predicate })?
962                }
963                ty::PredicateKind::AliasRelate(lhs, rhs, direction) => ecx
964                    .compute_alias_relate_goal(Goal {
965                        param_env,
966                        predicate: (lhs, rhs, direction),
967                    })?,
968                ty::PredicateKind::Ambiguous => {
969                    ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)?
970                }
971            })
972        })
973    }
974
975    // Recursively evaluates all the goals added to this `EvalCtxt` to completion, returning
976    // the certainty of all the goals.
977    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("try_evaluate_added_goals",
                                    "rustc_next_trait_solver::solve::eval_ctxt",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(977u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{ meta.fields().value_set(&[]) })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return:
                    Result<Certainty, NoSolutionOrRerunNonErased> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            for _ in 0..FIXPOINT_STEP_LIMIT {
                match self.evaluate_added_goals_step().map_err_to_rerun()? {
                    Ok(None) => {}
                    Ok(Some(cert)) => return Ok(cert),
                    Err(NoSolution) => {
                        self.tainted = Err(NoSolution);
                        return Err(NoSolution.into());
                    }
                }
            }
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:992",
                                    "rustc_next_trait_solver::solve::eval_ctxt",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(992u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&format_args!("try_evaluate_added_goals: encountered overflow")
                                                        as &dyn Value))])
                        });
                } else { ; }
            };
            Ok(Certainty::overflow(false))
        }
    }
}#[instrument(level = "trace", skip(self))]
978    pub(super) fn try_evaluate_added_goals(
979        &mut self,
980    ) -> Result<Certainty, NoSolutionOrRerunNonErased> {
981        for _ in 0..FIXPOINT_STEP_LIMIT {
982            match self.evaluate_added_goals_step().map_err_to_rerun()? {
983                Ok(None) => {}
984                Ok(Some(cert)) => return Ok(cert),
985                Err(NoSolution) => {
986                    self.tainted = Err(NoSolution);
987                    return Err(NoSolution.into());
988                }
989            }
990        }
991
992        debug!("try_evaluate_added_goals: encountered overflow");
993        Ok(Certainty::overflow(false))
994    }
995
996    /// Iterate over all added goals: returning `Ok(Some(_))` in case we can stop rerunning.
997    ///
998    /// Goals for the next step get directly added to the nested goals of the `EvalCtxt`.
999    fn evaluate_added_goals_step(
1000        &mut self,
1001    ) -> Result<Option<Certainty>, NoSolutionOrRerunNonErased> {
1002        // If this loop did not result in any progress, what's our final certainty.
1003        let mut unchanged_certainty = Some(Certainty::Yes);
1004        for (source, goal, stalled_on) in mem::take(&mut self.nested_goals) {
1005            // We never handle `NormalizesTo` as a nested goal
1006            if true {
    if !!#[allow(non_exhaustive_omitted_patterns)] match goal.predicate.kind().skip_binder()
                    {
                    PredicateKind::NormalizesTo(_) => true,
                    _ => false,
                } {
        ::core::panicking::panic("assertion failed: !matches!(goal.predicate.kind().skip_binder(), PredicateKind::NormalizesTo(_))")
    };
};debug_assert!(!matches!(
1007                goal.predicate.kind().skip_binder(),
1008                PredicateKind::NormalizesTo(_)
1009            ));
1010
1011            if !self.delegate.disable_trait_solver_fast_paths()
1012                && let Some(certainty) =
1013                    self.delegate.compute_goal_fast_path(goal, self.origin_span)
1014            {
1015                match certainty {
1016                    Certainty::Yes => {}
1017                    Certainty::Maybe { .. } => {
1018                        self.nested_goals.push((source, goal, None));
1019                        unchanged_certainty = unchanged_certainty.map(|c| c.and(certainty));
1020                    }
1021                }
1022                continue;
1023            }
1024
1025            let GoalEvaluation { goal, certainty, has_changed, stalled_on } =
1026                self.evaluate_goal(source, goal, stalled_on)?;
1027            if has_changed == HasChanged::Yes {
1028                unchanged_certainty = None;
1029            }
1030
1031            match certainty {
1032                Certainty::Yes => {}
1033                Certainty::Maybe { .. } => {
1034                    self.nested_goals.push((source, goal, stalled_on));
1035                    unchanged_certainty = unchanged_certainty.map(|c| c.and(certainty));
1036                }
1037            }
1038        }
1039
1040        Ok(unchanged_certainty)
1041    }
1042
1043    /// Record impl args in the proof tree for later access by `InspectCandidate`.
1044    pub(crate) fn record_impl_args(&mut self, impl_args: I::GenericArgs) {
1045        self.inspect.record_impl_args(self.delegate, self.max_input_universe, impl_args)
1046    }
1047
1048    pub(super) fn cx(&self) -> I {
1049        self.delegate.cx()
1050    }
1051
1052    pub(super) fn add_goal(&mut self, source: GoalSource, mut goal: Goal<I, I::Predicate>) {
1053        goal.predicate = self.replace_alias_with_infer(goal.predicate, source, goal.param_env);
1054        self.add_goal_raw(source, goal);
1055    }
1056
1057    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("add_goal_raw",
                                    "rustc_next_trait_solver::solve::eval_ctxt",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1057u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                                    ::tracing_core::field::FieldSet::new(&["source", "goal"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&goal)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            self.inspect.add_goal(self.delegate, self.max_input_universe,
                source, goal);
            self.nested_goals.push((source, goal, None));
        }
    }
}#[instrument(level = "debug", skip(self))]
1058    fn add_goal_raw(&mut self, source: GoalSource, goal: Goal<I, I::Predicate>) {
1059        self.inspect.add_goal(self.delegate, self.max_input_universe, source, goal);
1060        self.nested_goals.push((source, goal, None));
1061    }
1062
1063    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("add_goals",
                                    "rustc_next_trait_solver::solve::eval_ctxt",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1063u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
                                    ::tracing_core::field::FieldSet::new(&["source"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        { for goal in goals { self.add_goal(source, goal); } }
    }
}#[instrument(level = "trace", skip(self, goals))]
1064    pub(super) fn add_goals(
1065        &mut self,
1066        source: GoalSource,
1067        goals: impl IntoIterator<Item = Goal<I, I::Predicate>>,
1068    ) {
1069        for goal in goals {
1070            self.add_goal(source, goal);
1071        }
1072    }
1073
1074    pub(super) fn replace_alias_with_infer<T: TypeFoldable<I>>(
1075        &mut self,
1076        value: T,
1077        source: GoalSource,
1078        param_env: I::ParamEnv,
1079    ) -> T {
1080        value.fold_with(&mut ReplaceAliasWithInfer::new(self, source, param_env))
1081    }
1082
1083    pub(super) fn next_region_var(&mut self) -> I::Region {
1084        let region = self.delegate.next_region_infer();
1085        self.inspect.add_var_value(region);
1086        region
1087    }
1088
1089    pub(super) fn next_ty_infer(&mut self) -> I::Ty {
1090        let ty = self.delegate.next_ty_infer();
1091        self.inspect.add_var_value(ty);
1092        ty
1093    }
1094
1095    pub(super) fn next_const_infer(&mut self) -> I::Const {
1096        let ct = self.delegate.next_const_infer();
1097        self.inspect.add_var_value(ct);
1098        ct
1099    }
1100
1101    /// Returns a ty infer or a const infer depending on whether `kind` is a `Ty` or `Const`.
1102    /// If `kind` is an integer inference variable this will still return a ty infer var.
1103    pub(super) fn next_term_infer_of_kind(&mut self, term: I::Term) -> I::Term {
1104        match term.kind() {
1105            ty::TermKind::Ty(_) => self.next_ty_infer().into(),
1106            ty::TermKind::Const(_) => self.next_const_infer().into(),
1107        }
1108    }
1109
1110    /// Is the projection predicate is of the form `exists<T> <Ty as Trait>::Assoc = T`.
1111    ///
1112    /// This is the case if the `term` does not occur in any other part of the predicate
1113    /// and is able to name all other placeholder and inference variables.
1114    x;#[instrument(level = "trace", skip(self), ret)]
1115    pub(super) fn term_is_fully_unconstrained(&self, goal: Goal<I, ty::NormalizesTo<I>>) -> bool {
1116        let universe_of_term = match goal.predicate.term.kind() {
1117            ty::TermKind::Ty(ty) => {
1118                if let ty::Infer(ty::TyVar(vid)) = ty.kind() {
1119                    self.delegate.universe_of_ty(vid).unwrap()
1120                } else {
1121                    return false;
1122                }
1123            }
1124            ty::TermKind::Const(ct) => {
1125                if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind() {
1126                    self.delegate.universe_of_ct(vid).unwrap()
1127                } else {
1128                    return false;
1129                }
1130            }
1131        };
1132
1133        struct ContainsTermOrNotNameable<'a, D: SolverDelegate<Interner = I>, I: Interner> {
1134            term: I::Term,
1135            universe_of_term: ty::UniverseIndex,
1136            delegate: &'a D,
1137            cache: HashSet<I::Ty>,
1138        }
1139
1140        impl<D: SolverDelegate<Interner = I>, I: Interner> ContainsTermOrNotNameable<'_, D, I> {
1141            fn check_nameable(&self, universe: ty::UniverseIndex) -> ControlFlow<()> {
1142                if self.universe_of_term.can_name(universe) {
1143                    ControlFlow::Continue(())
1144                } else {
1145                    ControlFlow::Break(())
1146                }
1147            }
1148        }
1149
1150        impl<D: SolverDelegate<Interner = I>, I: Interner> TypeVisitor<I>
1151            for ContainsTermOrNotNameable<'_, D, I>
1152        {
1153            type Result = ControlFlow<()>;
1154            fn visit_ty(&mut self, t: I::Ty) -> Self::Result {
1155                if self.cache.contains(&t) {
1156                    return ControlFlow::Continue(());
1157                }
1158
1159                match t.kind() {
1160                    ty::Infer(ty::TyVar(vid)) => {
1161                        if let ty::TermKind::Ty(term) = self.term.kind()
1162                            && let ty::Infer(ty::TyVar(term_vid)) = term.kind()
1163                            && self.delegate.root_ty_var(vid) == self.delegate.root_ty_var(term_vid)
1164                        {
1165                            return ControlFlow::Break(());
1166                        }
1167
1168                        self.check_nameable(self.delegate.universe_of_ty(vid).unwrap())?;
1169                    }
1170                    ty::Placeholder(p) => self.check_nameable(p.universe())?,
1171                    _ => {
1172                        if t.has_non_region_infer() || t.has_placeholders() {
1173                            t.super_visit_with(self)?
1174                        }
1175                    }
1176                }
1177
1178                assert!(self.cache.insert(t));
1179                ControlFlow::Continue(())
1180            }
1181
1182            fn visit_const(&mut self, c: I::Const) -> Self::Result {
1183                match c.kind() {
1184                    ty::ConstKind::Infer(ty::InferConst::Var(vid)) => {
1185                        if let ty::TermKind::Const(term) = self.term.kind()
1186                            && let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
1187                            && self.delegate.root_const_var(vid)
1188                                == self.delegate.root_const_var(term_vid)
1189                        {
1190                            return ControlFlow::Break(());
1191                        }
1192
1193                        self.check_nameable(self.delegate.universe_of_ct(vid).unwrap())
1194                    }
1195                    ty::ConstKind::Placeholder(p) => self.check_nameable(p.universe()),
1196                    _ => {
1197                        if c.has_non_region_infer() || c.has_placeholders() {
1198                            c.super_visit_with(self)
1199                        } else {
1200                            ControlFlow::Continue(())
1201                        }
1202                    }
1203                }
1204            }
1205
1206            fn visit_predicate(&mut self, p: I::Predicate) -> Self::Result {
1207                if p.has_non_region_infer() || p.has_placeholders() {
1208                    p.super_visit_with(self)
1209                } else {
1210                    ControlFlow::Continue(())
1211                }
1212            }
1213
1214            fn visit_clauses(&mut self, c: I::Clauses) -> Self::Result {
1215                if c.has_non_region_infer() || c.has_placeholders() {
1216                    c.super_visit_with(self)
1217                } else {
1218                    ControlFlow::Continue(())
1219                }
1220            }
1221        }
1222
1223        let mut visitor = ContainsTermOrNotNameable {
1224            delegate: self.delegate,
1225            universe_of_term,
1226            term: goal.predicate.term,
1227            cache: Default::default(),
1228        };
1229        goal.predicate.alias.visit_with(&mut visitor).is_continue()
1230            && goal.param_env.visit_with(&mut visitor).is_continue()
1231    }
1232
1233    pub(super) fn sub_unify_ty_vids_raw(&self, a: ty::TyVid, b: ty::TyVid) {
1234        self.delegate.sub_unify_ty_vids_raw(a, b)
1235    }
1236
1237    x;#[instrument(level = "trace", skip(self, param_env), ret)]
1238    pub(super) fn eq<T: Relate<I>>(
1239        &mut self,
1240        param_env: I::ParamEnv,
1241        lhs: T,
1242        rhs: T,
1243    ) -> Result<(), NoSolution> {
1244        self.relate(param_env, lhs, ty::Variance::Invariant, rhs)
1245    }
1246
1247    /// This should be used when relating a rigid alias with another type.
1248    ///
1249    /// Normally we emit a nested `AliasRelate` when equating an inference
1250    /// variable and an alias. This causes us to instead constrain the inference
1251    /// variable to the alias without emitting a nested alias relate goals.
1252    x;#[instrument(level = "trace", skip(self, param_env), ret)]
1253    pub(super) fn relate_rigid_alias_non_alias(
1254        &mut self,
1255        param_env: I::ParamEnv,
1256        alias: ty::AliasTerm<I>,
1257        variance: ty::Variance,
1258        term: I::Term,
1259    ) -> Result<(), NoSolution> {
1260        // NOTE: this check is purely an optimization, the structural eq would
1261        // always fail if the term is not an inference variable.
1262        if term.is_infer() {
1263            let cx = self.cx();
1264            // We need to relate `alias` to `term` treating only the outermost
1265            // constructor as rigid, relating any contained generic arguments as
1266            // normal. We do this by first structurally equating the `term`
1267            // with the alias constructor instantiated with unconstrained infer vars,
1268            // and then relate this with the whole `alias`.
1269            //
1270            // Alternatively we could modify `Equate` for this case by adding another
1271            // variant to `StructurallyRelateAliases`.
1272            let def_id = match alias.kind {
1273                ty::AliasTermKind::ProjectionTy { def_id } => def_id.into(),
1274                ty::AliasTermKind::InherentTy { def_id } => def_id.into(),
1275                ty::AliasTermKind::OpaqueTy { def_id } => def_id.into(),
1276                ty::AliasTermKind::FreeTy { def_id } => def_id.into(),
1277                ty::AliasTermKind::AnonConst { def_id } => def_id.into(),
1278                ty::AliasTermKind::ProjectionConst { def_id } => def_id.into(),
1279                ty::AliasTermKind::FreeConst { def_id } => def_id.into(),
1280                ty::AliasTermKind::InherentConst { def_id } => def_id.into(),
1281            };
1282            let identity_args = self.fresh_args_for_item(def_id);
1283            let rigid_ctor = alias.with_args(cx, identity_args);
1284            let ctor_term = rigid_ctor.to_term(cx);
1285            let obligations = self.delegate.eq_structurally_relating_aliases(
1286                param_env,
1287                term,
1288                ctor_term,
1289                self.origin_span,
1290            )?;
1291            debug_assert!(obligations.is_empty());
1292            self.relate(param_env, alias, variance, rigid_ctor)
1293        } else {
1294            Err(NoSolution)
1295        }
1296    }
1297
1298    /// This should only be used when we're either instantiating a previously
1299    /// unconstrained "return value" or when we're sure that all aliases in
1300    /// the types are rigid.
1301    x;#[instrument(level = "trace", skip(self, param_env), ret)]
1302    pub(super) fn eq_structurally_relating_aliases<T: Relate<I>>(
1303        &mut self,
1304        param_env: I::ParamEnv,
1305        lhs: T,
1306        rhs: T,
1307    ) -> Result<(), NoSolution> {
1308        let result = self.delegate.eq_structurally_relating_aliases(
1309            param_env,
1310            lhs,
1311            rhs,
1312            self.origin_span,
1313        )?;
1314        assert_eq!(result, vec![]);
1315        Ok(())
1316    }
1317
1318    x;#[instrument(level = "trace", skip(self, param_env), ret)]
1319    pub(super) fn sub<T: Relate<I>>(
1320        &mut self,
1321        param_env: I::ParamEnv,
1322        sub: T,
1323        sup: T,
1324    ) -> Result<(), NoSolution> {
1325        self.relate(param_env, sub, ty::Variance::Covariant, sup)
1326    }
1327
1328    x;#[instrument(level = "trace", skip(self, param_env), ret)]
1329    pub(super) fn relate<T: Relate<I>>(
1330        &mut self,
1331        param_env: I::ParamEnv,
1332        lhs: T,
1333        variance: ty::Variance,
1334        rhs: T,
1335    ) -> Result<(), NoSolution> {
1336        let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?;
1337        for &goal in goals.iter() {
1338            let source = match goal.predicate.kind().skip_binder() {
1339                ty::PredicateKind::Subtype { .. } | ty::PredicateKind::AliasRelate(..) => {
1340                    GoalSource::TypeRelating
1341                }
1342                // FIXME(-Znext-solver=coinductive): should these WF goals also be unproductive?
1343                ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => GoalSource::Misc,
1344                p => unreachable!("unexpected nested goal in `relate`: {p:?}"),
1345            };
1346            self.add_goal(source, goal);
1347        }
1348        Ok(())
1349    }
1350
1351    /// Equates two values returning the nested goals without adding them
1352    /// to the nested goals of the `EvalCtxt`.
1353    ///
1354    /// If possible, try using `eq` instead which automatically handles nested
1355    /// goals correctly.
1356    x;#[instrument(level = "trace", skip(self, param_env), ret)]
1357    pub(super) fn eq_and_get_goals<T: Relate<I>>(
1358        &self,
1359        param_env: I::ParamEnv,
1360        lhs: T,
1361        rhs: T,
1362    ) -> Result<Vec<Goal<I, I::Predicate>>, NoSolution> {
1363        Ok(self.delegate.relate(param_env, lhs, ty::Variance::Invariant, rhs, self.origin_span)?)
1364    }
1365
1366    pub(super) fn instantiate_binder_with_infer<T: TypeFoldable<I> + Copy>(
1367        &self,
1368        value: ty::Binder<I, T>,
1369    ) -> T {
1370        self.delegate.instantiate_binder_with_infer(value)
1371    }
1372
1373    /// `enter_forall_with_assumptions`, but takes `&mut self` and passes it back through
1374    /// the callback since it can't be aliased during the call.
1375    ///
1376    /// The `param_env` is used to *compute* the assumptions of the binder, not *as* the
1377    /// assumptions associated with the binder.
1378    ///
1379    /// FIXME(inherent_associated_types): fix this?
1380    pub(super) fn enter_forall_with_assumptions<T: TypeFoldable<I>, U>(
1381        &mut self,
1382        value: ty::Binder<I, T>,
1383        param_env: I::ParamEnv,
1384        f: impl FnOnce(&mut Self, T) -> U,
1385    ) -> U {
1386        self.delegate.enter_forall_without_assumptions(value, |value| {
1387            let u = self.delegate.universe();
1388            let assumptions = if self.cx().assumptions_on_binders() {
1389                self.region_assumptions_for_placeholders_in_universe(value.clone(), u, param_env)
1390            } else {
1391                None
1392            };
1393            self.delegate.insert_placeholder_assumptions(u, assumptions);
1394            f(self, value)
1395        })
1396    }
1397
1398    pub(super) fn resolve_vars_if_possible<T>(&self, value: T) -> T
1399    where
1400        T: TypeFoldable<I>,
1401    {
1402        self.delegate.resolve_vars_if_possible(value)
1403    }
1404
1405    pub(super) fn shallow_resolve(&self, ty: I::Ty) -> I::Ty {
1406        self.delegate.shallow_resolve(ty)
1407    }
1408
1409    pub(super) fn eager_resolve_region(&self, r: I::Region) -> I::Region {
1410        if let ty::ReVar(vid) = r.kind() {
1411            self.delegate.opportunistic_resolve_lt_var(vid)
1412        } else {
1413            r
1414        }
1415    }
1416
1417    pub(super) fn fresh_args_for_item(&mut self, def_id: I::DefId) -> I::GenericArgs {
1418        let args = self.delegate.fresh_args_for_item(def_id);
1419        for arg in args.iter() {
1420            self.inspect.add_var_value(arg);
1421        }
1422        args
1423    }
1424
1425    pub(super) fn register_solver_region_constraint(&self, c: RegionConstraint<I>) {
1426        self.delegate.register_solver_region_constraint(c);
1427    }
1428
1429    pub(super) fn register_ty_outlives(&self, ty: I::Ty, lt: I::Region) {
1430        self.delegate.register_ty_outlives(ty, lt, self.origin_span);
1431    }
1432
1433    pub(super) fn register_region_outlives(
1434        &self,
1435        a: I::Region,
1436        b: I::Region,
1437        vis: VisibleForLeakCheck,
1438    ) {
1439        // `'a: 'b` ==> `'b <= 'a`
1440        self.delegate.sub_regions(b, a, vis, self.origin_span);
1441    }
1442
1443    /// Computes the list of goals required for `arg` to be well-formed
1444    pub(super) fn well_formed_goals(
1445        &self,
1446        param_env: I::ParamEnv,
1447        term: I::Term,
1448    ) -> Option<Vec<Goal<I, I::Predicate>>> {
1449        self.delegate.well_formed_goals(param_env, term)
1450    }
1451
1452    pub(super) fn trait_ref_is_knowable(
1453        &mut self,
1454        param_env: I::ParamEnv,
1455        trait_ref: ty::TraitRef<I>,
1456    ) -> Result<bool, NoSolutionOrRerunNonErased> {
1457        let delegate = self.delegate;
1458        let lazily_normalize_ty = |ty| self.structurally_normalize_ty(param_env, ty);
1459        coherence::trait_ref_is_knowable(&**delegate, trait_ref, lazily_normalize_ty)
1460            .map(|is_knowable| is_knowable.is_ok())
1461    }
1462
1463    pub(super) fn fetch_eligible_assoc_item(
1464        &self,
1465        goal_trait_ref: ty::TraitRef<I>,
1466        trait_assoc_def_id: I::TraitAssocTermId,
1467        impl_def_id: I::ImplId,
1468    ) -> FetchEligibleAssocItemResponse<I> {
1469        self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
1470    }
1471
1472    x;#[instrument(level = "debug", skip(self), ret)]
1473    pub(super) fn register_hidden_type_in_storage(
1474        &mut self,
1475        opaque_type_key: ty::OpaqueTypeKey<I>,
1476        hidden_ty: I::Ty,
1477    ) -> Option<I::Ty> {
1478        self.delegate.register_hidden_type_in_storage(opaque_type_key, hidden_ty, self.origin_span)
1479    }
1480
1481    pub(super) fn add_item_bounds_for_hidden_type(
1482        &mut self,
1483        opaque_def_id: I::OpaqueTyId,
1484        opaque_args: I::GenericArgs,
1485        param_env: I::ParamEnv,
1486        hidden_ty: I::Ty,
1487    ) {
1488        let mut goals = Vec::new();
1489        self.delegate.add_item_bounds_for_hidden_type(
1490            opaque_def_id,
1491            opaque_args,
1492            param_env,
1493            hidden_ty,
1494            &mut goals,
1495        );
1496        self.add_goals(GoalSource::AliasWellFormed, goals);
1497    }
1498
1499    // Try to evaluate a const, or return `None` if the const is too generic.
1500    // This doesn't mean the const isn't evaluatable, though, and should be treated
1501    // as an ambiguity rather than no-solution.
1502    pub(super) fn evaluate_const(
1503        &mut self,
1504        param_env: I::ParamEnv,
1505        uv: ty::UnevaluatedConst<I>,
1506    ) -> Result<Option<I::Const>, RerunNonErased> {
1507        if self.typing_mode().is_erased_not_coherence() {
1508            self.opaque_accesses.rerun_always(RerunReason::EvaluateConst)?;
1509        }
1510
1511        Ok(self.delegate.evaluate_const(param_env, uv))
1512    }
1513
1514    pub(super) fn evaluate_const_and_instantiate_projection_term(
1515        &mut self,
1516        param_env: I::ParamEnv,
1517        projection_term: ty::AliasTerm<I>,
1518        expected_term: I::Term,
1519        uv: ty::UnevaluatedConst<I>,
1520    ) -> QueryResultOrRerunNonErased<I> {
1521        match self.evaluate_const(param_env, uv)? {
1522            Some(evaluated) => {
1523                self.eq(param_env, expected_term, evaluated.into())?;
1524                self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
1525            }
1526            None if self.cx().features().generic_const_args() => {
1527                // HACK(khyperia): calling `resolve_vars_if_possible` here shouldn't be necessary,
1528                // `try_evaluate_const` calls `resolve_vars_if_possible` already. However, we want
1529                // to check `has_non_region_infer` against the type with vars resolved (i.e. check
1530                // if there are vars we failed to resolve), so we need to call it again here.
1531                // Perhaps we could split EvaluateConstErr::HasGenericsOrInfers into HasGenerics and
1532                // HasInfers or something, make evaluate_const return that, and make this branch be
1533                // based on that, rather than checking `has_non_region_infer`.
1534                if self.resolve_vars_if_possible(uv).has_non_region_infer() {
1535                    self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1536                } else {
1537                    // We do not instantiate to the `uv` passed in, but rather
1538                    // `goal.predicate.alias`. The `uv` passed in might correspond to the `impl`
1539                    // form of a constant (with generic arguments corresponding to the impl block),
1540                    // however, we want to structurally instantiate to the original, non-rebased,
1541                    // trait `Self` form of the constant (with generic arguments being the trait
1542                    // `Self` type).
1543                    self.relate_rigid_alias_non_alias(
1544                        param_env,
1545                        projection_term,
1546                        ty::Invariant,
1547                        expected_term,
1548                    )?;
1549                    self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
1550                }
1551            }
1552            None => {
1553                // Legacy behavior: always treat as ambiguous
1554                self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1555            }
1556        }
1557    }
1558
1559    pub(super) fn is_transmutable(
1560        &mut self,
1561        src: I::Ty,
1562        dst: I::Ty,
1563        assume: I::Const,
1564    ) -> Result<Certainty, NoSolution> {
1565        self.delegate.is_transmutable(dst, src, assume)
1566    }
1567
1568    pub(super) fn replace_bound_vars<T: TypeFoldable<I>>(
1569        &self,
1570        t: T,
1571        universes: &mut Vec<Option<ty::UniverseIndex>>,
1572    ) -> T {
1573        BoundVarReplacer::replace_bound_vars(&**self.delegate, universes, t).0
1574    }
1575
1576    pub(super) fn may_use_unstable_feature(
1577        &mut self,
1578        param_env: I::ParamEnv,
1579        symbol: I::Symbol,
1580    ) -> Result<bool, RerunNonErased> {
1581        if self.typing_mode().is_erased_not_coherence() {
1582            self.opaque_accesses.rerun_always(RerunReason::MayUseUnstableFeature)?;
1583        }
1584
1585        Ok(may_use_unstable_feature(&**self.delegate, param_env, symbol))
1586    }
1587
1588    pub(crate) fn opaques_with_sub_unified_hidden_type(
1589        &self,
1590        self_ty: I::Ty,
1591    ) -> Vec<ty::OpaqueAliasTy<I>> {
1592        if let ty::Infer(ty::TyVar(vid)) = self_ty.kind() {
1593            self.delegate.opaques_with_sub_unified_hidden_type(vid)
1594        } else {
1595            ::alloc::vec::Vec::new()vec![]
1596        }
1597    }
1598
1599    /// To return the constraints of a canonical query to the caller, we canonicalize:
1600    ///
1601    /// - `var_values`: a map from bound variables in the canonical goal to
1602    ///   the values inferred while solving the instantiated goal.
1603    /// - `external_constraints`: additional constraints which aren't expressible
1604    ///   using simple unification of inference variables.
1605    ///
1606    /// This takes the `shallow_certainty` which represents whether we're confident
1607    /// that the final result of the current goal only depends on the nested goals.
1608    ///
1609    /// In case this is `Certainty::Maybe`, there may still be additional nested goals
1610    /// or inference constraints required for this candidate to be hold. The candidate
1611    /// always requires all already added constraints and nested goals.
1612    x;#[instrument(level = "trace", skip(self), ret)]
1613    pub(in crate::solve) fn evaluate_added_goals_and_make_canonical_response(
1614        &mut self,
1615        shallow_certainty: Certainty,
1616    ) -> QueryResultOrRerunNonErased<I> {
1617        self.inspect.make_canonical_response(shallow_certainty);
1618
1619        let goals_certainty = self.try_evaluate_added_goals()?;
1620        assert_eq!(
1621            self.tainted,
1622            Ok(()),
1623            "EvalCtxt is tainted -- nested goals may have been dropped in a \
1624            previous call to `try_evaluate_added_goals!`"
1625        );
1626
1627        let goals_certainty = match self.delegate.cx().assumptions_on_binders() {
1628            true => {
1629                let certainty = self.eagerly_handle_placeholders()?;
1630                certainty.and(goals_certainty)
1631            }
1632            false => {
1633                // We only check for leaks from universes which were entered inside
1634                // of the query.
1635                self.delegate.leak_check(self.max_input_universe).map_err(|NoSolution| {
1636                    trace!("failed the leak check");
1637                    NoSolution
1638                })?;
1639
1640                goals_certainty
1641            }
1642        };
1643
1644        let (certainty, normalization_nested_goals) =
1645            match (self.current_goal_kind, shallow_certainty) {
1646                // When normalizing, we've replaced the expected term with an unconstrained
1647                // inference variable. This means that we dropped information which could
1648                // have been important. We handle this by instead returning the nested goals
1649                // to the caller, where they are then handled. We only do so if we do not
1650                // need to recompute the `NormalizesTo` goal afterwards to avoid repeatedly
1651                // uplifting its nested goals. This is the case if the `shallow_certainty` is
1652                // `Certainty::Yes`.
1653                (CurrentGoalKind::ProjectionComputeAssocTermCandidate, Certainty::Yes) => {
1654                    let goals = std::mem::take(&mut self.nested_goals);
1655                    // As we return all ambiguous nested goals, we can ignore the certainty
1656                    // returned by `self.try_evaluate_added_goals()`.
1657                    if goals.is_empty() {
1658                        assert!(matches!(goals_certainty, Certainty::Yes));
1659                    }
1660                    (
1661                        Certainty::Yes,
1662                        NestedNormalizationGoals(
1663                            goals.into_iter().map(|(s, g, _)| (s, g)).collect(),
1664                        ),
1665                    )
1666                }
1667                _ => {
1668                    let certainty = shallow_certainty.and(goals_certainty);
1669                    (certainty, NestedNormalizationGoals::empty())
1670                }
1671            };
1672
1673        if let Certainty::Maybe(
1674            maybe_info @ MaybeInfo {
1675                cause: MaybeCause::Overflow { keep_constraints: false, .. },
1676                opaque_types_jank: _,
1677                stalled_on_coroutines: _,
1678            },
1679        ) = certainty
1680        {
1681            // If we have overflow, it's probable that we're substituting a type
1682            // into itself infinitely and any partial substitutions in the query
1683            // response are probably not useful anyways, so just return an empty
1684            // query response.
1685            //
1686            // This may prevent us from potentially useful inference, e.g.
1687            // 2 candidates, one ambiguous and one overflow, which both
1688            // have the same inference constraints.
1689            //
1690            // Changing this to retain some constraints in the future
1691            // won't be a breaking change, so this is good enough for now.
1692            return Ok(self.make_ambiguous_response_no_constraints(maybe_info));
1693        }
1694
1695        let external_constraints =
1696            self.compute_external_query_constraints(certainty, normalization_nested_goals);
1697        let (var_values, mut external_constraints) =
1698            eager_resolve_vars(self.delegate, (self.var_values, external_constraints));
1699
1700        // Remove any trivial or duplicated region constraints once we've resolved regions
1701        let mut unique = HashSet::default();
1702        if let ExternalRegionConstraints::Old(r) = &mut external_constraints.region_constraints {
1703            r.retain(|(outlives, _)| !outlives.is_trivial() && unique.insert(*outlives));
1704        }
1705
1706        let canonical = canonicalize_response(
1707            self.delegate,
1708            self.max_input_universe,
1709            Response {
1710                var_values,
1711                certainty,
1712                external_constraints: self.cx().mk_external_constraints(external_constraints),
1713            },
1714        );
1715
1716        Ok(canonical)
1717    }
1718
1719    /// Constructs a totally unconstrained, ambiguous response to a goal.
1720    ///
1721    /// Take care when using this, since often it's useful to respond with
1722    /// ambiguity but return constrained variables to guide inference.
1723    pub(in crate::solve) fn make_ambiguous_response_no_constraints(
1724        &self,
1725        maybe: MaybeInfo,
1726    ) -> CanonicalResponse<I> {
1727        response_no_constraints_raw(
1728            self.cx(),
1729            self.max_input_universe,
1730            self.var_kinds,
1731            Certainty::Maybe(maybe),
1732        )
1733    }
1734
1735    /// Computes the region constraints and *new* opaque types registered when
1736    /// proving a goal.
1737    ///
1738    /// If an opaque was already constrained before proving this goal, then the
1739    /// external constraints do not need to record that opaque, since if it is
1740    /// further constrained by inference, that will be passed back in the var
1741    /// values.
1742    x;#[instrument(level = "trace", skip(self), ret)]
1743    fn compute_external_query_constraints(
1744        &self,
1745        certainty: Certainty,
1746        normalization_nested_goals: NestedNormalizationGoals<I>,
1747    ) -> ExternalConstraintsData<I> {
1748        // We only return region constraints once the certainty is `Yes`. This
1749        // is necessary as we may drop nested goals on ambiguity, which may result
1750        // in unconstrained inference variables in the region constraints. It also
1751        // prevents us from emitting duplicate region constraints, avoiding some
1752        // unnecessary work. This slightly weakens the leak check in case it uses
1753        // region constraints from an ambiguous nested goal. This is tested in both
1754        // `tests/ui/higher-ranked/leak-check/leak-check-in-selection-5-ambig.rs` and
1755        // `tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.rs`.
1756        let region_constraints = if self.cx().assumptions_on_binders() {
1757            ExternalRegionConstraints::NextGen(if let Certainty::Yes = certainty {
1758                self.delegate.get_solver_region_constraint()
1759            } else {
1760                RegionConstraint::new_true()
1761            })
1762        } else {
1763            ExternalRegionConstraints::Old(if let Certainty::Yes = certainty {
1764                self.delegate.make_deduplicated_region_constraints()
1765            } else {
1766                vec![]
1767            })
1768        };
1769
1770        // We only return *newly defined* opaque types from canonical queries.
1771        //
1772        // Constraints for any existing opaque types are already tracked by changes
1773        // to the `var_values`.
1774        let opaque_types = self
1775            .delegate
1776            .clone_opaque_types_added_since(self.initial_opaque_types_storage_num_entries);
1777
1778        if self.typing_mode().is_erased_not_coherence() {
1779            assert!(opaque_types.is_empty());
1780        }
1781
1782        ExternalConstraintsData { region_constraints, opaque_types, normalization_nested_goals }
1783    }
1784}
1785
1786// FIXME: This should be eventually removed in favor of proper normalization.
1787// cc #156742
1788/// Eagerly replace aliases with inference variables, emitting `AliasRelate`
1789/// goals, used when adding goals to the `EvalCtxt`. We compute the
1790/// `AliasRelate` goals before evaluating the actual goal to get all the
1791/// constraints we can.
1792///
1793/// This is a performance optimization to more eagerly detect cycles during trait
1794/// solving. See tests/ui/traits/next-solver/cycles/cycle-modulo-ambig-aliases.rs.
1795///
1796/// The emitted goals get evaluated in the context of the parent goal; by
1797/// replacing aliases in nested goals we essentially pull the normalization out of
1798/// the nested goal. We want to treat the goal as if the normalization still happens
1799/// inside of the nested goal by inheriting the `step_kind` of the nested goal and
1800/// storing it in the `GoalSource` of the emitted `AliasRelate` goals.
1801/// This is necessary for tests/ui/sized/coinductive-1.rs to compile.
1802struct ReplaceAliasWithInfer<'me, 'a, D, I>
1803where
1804    D: SolverDelegate<Interner = I>,
1805    I: Interner,
1806{
1807    ecx: &'me mut EvalCtxt<'a, D>,
1808    param_env: I::ParamEnv,
1809    normalization_goal_source: GoalSource,
1810    cache: HashMap<I::Ty, I::Ty>,
1811}
1812
1813impl<'me, 'a, D, I> ReplaceAliasWithInfer<'me, 'a, D, I>
1814where
1815    D: SolverDelegate<Interner = I>,
1816    I: Interner,
1817{
1818    fn new(
1819        ecx: &'me mut EvalCtxt<'a, D>,
1820        for_goal_source: GoalSource,
1821        param_env: I::ParamEnv,
1822    ) -> Self {
1823        let step_kind = ecx.step_kind_for_source(for_goal_source);
1824        ReplaceAliasWithInfer {
1825            ecx,
1826            param_env,
1827            normalization_goal_source: GoalSource::NormalizeGoal(step_kind),
1828            cache: Default::default(),
1829        }
1830    }
1831}
1832
1833impl<D, I> TypeFolder<I> for ReplaceAliasWithInfer<'_, '_, D, I>
1834where
1835    D: SolverDelegate<Interner = I>,
1836    I: Interner,
1837{
1838    fn cx(&self) -> I {
1839        self.ecx.cx()
1840    }
1841
1842    fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
1843        match ty.kind() {
1844            ty::Alias(alias) if !ty.has_escaping_bound_vars() => {
1845                let infer_ty = self.ecx.next_ty_infer();
1846                let projection = ty::ProjectionPredicate {
1847                    projection_term: alias.into(),
1848                    term: infer_ty.into(),
1849                };
1850                self.ecx.add_goal_raw(
1851                    self.normalization_goal_source,
1852                    Goal::new(self.cx(), self.param_env, projection),
1853                );
1854                infer_ty
1855            }
1856            _ => {
1857                if !ty.has_aliases() {
1858                    ty
1859                } else if let Some(&entry) = self.cache.get(&ty) {
1860                    return entry;
1861                } else {
1862                    let res = ty.super_fold_with(self);
1863                    if !self.cache.insert(ty, res).is_none() {
    ::core::panicking::panic("assertion failed: self.cache.insert(ty, res).is_none()")
};assert!(self.cache.insert(ty, res).is_none());
1864                    res
1865                }
1866            }
1867        }
1868    }
1869
1870    fn fold_const(&mut self, ct: I::Const) -> I::Const {
1871        match ct.kind() {
1872            ty::ConstKind::Unevaluated(uv) if !ct.has_escaping_bound_vars() => {
1873                let infer_ct = self.ecx.next_const_infer();
1874                let projection =
1875                    ty::ProjectionPredicate { projection_term: uv.into(), term: infer_ct.into() };
1876                self.ecx.add_goal_raw(
1877                    self.normalization_goal_source,
1878                    Goal::new(self.cx(), self.param_env, projection),
1879                );
1880                infer_ct
1881            }
1882            _ => ct.super_fold_with(self),
1883        }
1884    }
1885
1886    fn fold_predicate(&mut self, predicate: I::Predicate) -> I::Predicate {
1887        if predicate.allow_normalization() { predicate.super_fold_with(self) } else { predicate }
1888    }
1889}
1890
1891/// Do not call this directly, use the `tcx` query instead.
1892pub fn evaluate_root_goal_for_proof_tree_raw_provider<
1893    D: SolverDelegate<Interner = I>,
1894    I: Interner,
1895>(
1896    cx: I,
1897    canonical_goal: CanonicalInput<I>,
1898) -> (QueryResult<I>, I::Probe) {
1899    let mut inspect = inspect::ProofTreeBuilder::new();
1900    let (canonical_result, accessed_opaques) = SearchGraph::<D>::evaluate_root_goal_for_proof_tree(
1901        cx,
1902        cx.recursion_limit(),
1903        canonical_goal,
1904        &mut inspect,
1905    );
1906    let final_revision = inspect.unwrap();
1907
1908    if !!accessed_opaques.might_rerun() {
    ::core::panicking::panic("assertion failed: !accessed_opaques.might_rerun()")
};assert!(!accessed_opaques.might_rerun());
1909    (canonical_result, cx.mk_probe(final_revision))
1910}
1911
1912/// Evaluate a goal to build a proof tree.
1913///
1914/// This is a copy of [EvalCtxt::evaluate_goal_raw] which avoids relying on the
1915/// [EvalCtxt] and uses a separate cache.
1916pub(super) fn evaluate_root_goal_for_proof_tree<D: SolverDelegate<Interner = I>, I: Interner>(
1917    delegate: &D,
1918    goal: Goal<I, I::Predicate>,
1919    origin_span: I::Span,
1920) -> (Result<NestedNormalizationGoals<I>, NoSolution>, inspect::GoalEvaluation<I>) {
1921    let opaque_types = delegate.clone_opaque_types_lookup_table();
1922    let (goal, opaque_types) = eager_resolve_vars(delegate, (goal, opaque_types));
1923    let typing_mode = delegate.typing_mode_raw().assert_not_erased();
1924
1925    let (orig_values, canonical_goal) =
1926        canonicalize_goal(delegate, goal, &opaque_types, typing_mode.into());
1927
1928    let (canonical_result, final_revision) =
1929        delegate.cx().evaluate_root_goal_for_proof_tree_raw(canonical_goal);
1930
1931    let proof_tree = inspect::GoalEvaluation {
1932        uncanonicalized_goal: goal,
1933        orig_values,
1934        final_revision,
1935        result: canonical_result,
1936    };
1937
1938    let response = match canonical_result {
1939        Err(e) => return (Err(e), proof_tree),
1940        Ok(response) => response,
1941    };
1942
1943    let (normalization_nested_goals, _certainty) = instantiate_and_apply_query_response(
1944        delegate,
1945        goal.param_env,
1946        &proof_tree.orig_values,
1947        response,
1948        VisibleForLeakCheck::Yes,
1949        origin_span,
1950    );
1951
1952    (Ok(normalization_nested_goals), proof_tree)
1953}