Skip to main content

rustc_trait_selection/traits/
fulfill.rs

1use std::marker::PhantomData;
2use std::ops::ControlFlow;
3
4use rustc_data_structures::obligation_forest::{
5    Error, ForestObligation, ObligationForest, ObligationProcessor, Outcome, ProcessResult,
6};
7use rustc_hir::def_id::LocalDefId;
8use rustc_infer::infer::DefineOpaqueTypes;
9use rustc_infer::traits::{
10    FromSolverError, PolyTraitObligation, PredicateObligations, ProjectionCacheKey, SelectionError,
11    TraitEngine,
12};
13use rustc_middle::bug;
14use rustc_middle::ty::abstract_const::NotConstEvaluatable;
15use rustc_middle::ty::error::{ExpectedFound, TypeError};
16use rustc_middle::ty::{
17    self, Binder, Const, DelayedSet, GenericArgsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
18    TypeVisitableExt, TypeVisitor, TypingMode, may_use_unstable_feature,
19};
20use thin_vec::{ThinVec, thin_vec};
21use tracing::{debug, debug_span, instrument};
22
23use super::effects::{self, HostEffectObligation};
24use super::project::{self, ProjectAndUnifyResult};
25use super::select::SelectionContext;
26use super::{
27    EvaluationResult, FulfillmentError, FulfillmentErrorCode, PredicateObligation,
28    ScrubbedTraitError, const_evaluatable, wf,
29};
30use crate::error_reporting::InferCtxtErrorExt;
31use crate::infer::{InferCtxt, TyOrConstInferVar};
32use crate::traits::normalize::normalize_with_depth_to;
33use crate::traits::project::{PolyProjectionObligation, ProjectionCacheKeyExt as _};
34use crate::traits::query::evaluate_obligation::InferCtxtExt;
35use crate::traits::{EvaluateConstErr, sizedness_fast_path};
36
37pub(crate) type PendingPredicateObligations<'tcx> = ThinVec<PendingPredicateObligation<'tcx>>;
38
39impl<'tcx> ForestObligation for PendingPredicateObligation<'tcx> {
40    /// Note that we include both the `ParamEnv` and the `Predicate`,
41    /// as the `ParamEnv` can influence whether fulfillment succeeds
42    /// or fails.
43    type CacheKey = ty::ParamEnvAnd<'tcx, ty::Predicate<'tcx>>;
44
45    fn as_cache_key(&self) -> Self::CacheKey {
46        self.obligation.param_env.and(self.obligation.predicate)
47    }
48}
49
50/// The fulfillment context is used to drive trait resolution. It
51/// consists of a list of obligations that must be (eventually)
52/// satisfied. The job is to track which are satisfied, which yielded
53/// errors, and which are still pending. At any point, users can call
54/// `try_evaluate_obligations`, and the fulfillment context will try to do
55/// selection, retaining only those obligations that remain
56/// ambiguous. This may be helpful in pushing type inference
57/// along. Once all type inference constraints have been generated, the
58/// method `evaluate_obligations_error_on_ambiguity` can be used to report any remaining
59/// ambiguous cases as errors.
60pub struct FulfillmentContext<'tcx, E: 'tcx> {
61    /// A list of all obligations that have been registered with this
62    /// fulfillment context.
63    predicates: ObligationForest<PendingPredicateObligation<'tcx>>,
64
65    /// The snapshot in which this context was created. Using the context
66    /// outside of this snapshot leads to subtle bugs if the snapshot
67    /// gets rolled back. Because of this we explicitly check that we only
68    /// use the context in exactly this snapshot.
69    usable_in_snapshot: usize,
70
71    _errors: PhantomData<E>,
72}
73
74#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for PendingPredicateObligation<'tcx> {
    #[inline]
    fn clone(&self) -> PendingPredicateObligation<'tcx> {
        PendingPredicateObligation {
            obligation: ::core::clone::Clone::clone(&self.obligation),
            stalled_on: ::core::clone::Clone::clone(&self.stalled_on),
        }
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for PendingPredicateObligation<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "PendingPredicateObligation", "obligation", &self.obligation,
            "stalled_on", &&self.stalled_on)
    }
}Debug)]
75pub struct PendingPredicateObligation<'tcx> {
76    pub obligation: PredicateObligation<'tcx>,
77    // This is far more often read than modified, meaning that we
78    // should mostly optimize for reading speed, while modifying is not as relevant.
79    //
80    // For whatever reason using a boxed slice is slower than using a `Vec` here.
81    pub stalled_on: Vec<TyOrConstInferVar>,
82}
83
84// `PendingPredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
85#[cfg(target_pointer_width = "64")]
86const _: [(); 72] =
    [(); ::std::mem::size_of::<PendingPredicateObligation<'_>>()];rustc_data_structures::static_assert_size!(PendingPredicateObligation<'_>, 72);
87
88impl<'tcx, E> FulfillmentContext<'tcx, E>
89where
90    E: FromSolverError<'tcx, OldSolverError<'tcx>>,
91{
92    /// Creates a new fulfillment context.
93    pub(super) fn new(infcx: &InferCtxt<'tcx>) -> FulfillmentContext<'tcx, E> {
94        if !!infcx.next_trait_solver() {
    {
        ::core::panicking::panic_fmt(format_args!("old trait solver fulfillment context created when infcx is set up for new trait solver"));
    }
};assert!(
95            !infcx.next_trait_solver(),
96            "old trait solver fulfillment context created when \
97            infcx is set up for new trait solver"
98        );
99        FulfillmentContext {
100            predicates: ObligationForest::new(),
101            usable_in_snapshot: infcx.num_open_snapshots(),
102            _errors: PhantomData,
103        }
104    }
105
106    /// Attempts to select obligations using `selcx`.
107    fn select(&mut self, selcx: SelectionContext<'_, 'tcx>) -> Vec<E> {
108        let span = {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("select",
                        "rustc_trait_selection::traits::fulfill",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                        ::tracing_core::__macro_support::Option::Some(108u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                        ::tracing_core::field::FieldSet::new(&["obligation_forest_size"],
                            ::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(&debug(&self.predicates.len())
                                                as &dyn Value))])
                })
    } else {
        let span =
            ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
        {};
        span
    }
}debug_span!("select", obligation_forest_size = ?self.predicates.len());
109        let _enter = span.enter();
110        let infcx = selcx.infcx;
111
112        // Process pending obligations.
113        let outcome: Outcome<_, _> =
114            self.predicates.process_obligations(&mut FulfillProcessor { selcx });
115
116        // FIXME: if we kept the original cache key, we could mark projection
117        // obligations as complete for the projection cache here.
118
119        let errors: Vec<E> = outcome
120            .errors
121            .into_iter()
122            .map(|err| E::from_solver_error(infcx, OldSolverError(err)))
123            .collect();
124
125        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/fulfill.rs:125",
                        "rustc_trait_selection::traits::fulfill",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                        ::tracing_core::__macro_support::Option::Some(125u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                        ::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!("select({0} predicates remaining, {1} errors) done",
                                                    self.predicates.len(), errors.len()) as &dyn Value))])
            });
    } else { ; }
};debug!(
126            "select({} predicates remaining, {} errors) done",
127            self.predicates.len(),
128            errors.len()
129        );
130
131        errors
132    }
133}
134
135impl<'tcx, E> TraitEngine<'tcx, E> for FulfillmentContext<'tcx, E>
136where
137    E: FromSolverError<'tcx, OldSolverError<'tcx>>,
138{
139    #[inline]
140    fn register_predicate_obligation(
141        &mut self,
142        infcx: &InferCtxt<'tcx>,
143        mut obligation: PredicateObligation<'tcx>,
144    ) {
145        match (&self.usable_in_snapshot, &infcx.num_open_snapshots()) {
    (left_val, right_val) => {
        if !(*left_val == *right_val) {
            let kind = ::core::panicking::AssertKind::Eq;
            ::core::panicking::assert_failed(kind, &*left_val, &*right_val,
                ::core::option::Option::None);
        }
    }
};assert_eq!(self.usable_in_snapshot, infcx.num_open_snapshots());
146        // this helps to reduce duplicate errors, as well as making
147        // debug output much nicer to read and so on.
148        if true {
    if !!obligation.param_env.has_non_region_infer() {
        ::core::panicking::panic("assertion failed: !obligation.param_env.has_non_region_infer()")
    };
};debug_assert!(!obligation.param_env.has_non_region_infer());
149        obligation.predicate = infcx.resolve_vars_if_possible(obligation.predicate);
150
151        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/fulfill.rs:151",
                        "rustc_trait_selection::traits::fulfill",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                        ::tracing_core::__macro_support::Option::Some(151u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "obligation"],
                            ::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!("register_predicate_obligation")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligation)
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(?obligation, "register_predicate_obligation");
152
153        self.predicates
154            .register_obligation(PendingPredicateObligation { obligation, stalled_on: ::alloc::vec::Vec::new()vec![] });
155    }
156
157    fn collect_remaining_errors(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<E> {
158        self.predicates
159            .to_errors(FulfillmentErrorCode::Ambiguity { overflow: None })
160            .into_iter()
161            .map(|err| E::from_solver_error(infcx, OldSolverError(err)))
162            .collect()
163    }
164
165    fn try_evaluate_obligations(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<E> {
166        let selcx = SelectionContext::new(infcx);
167        self.select(selcx)
168    }
169
170    fn drain_stalled_obligations_for_coroutines(
171        &mut self,
172        infcx: &InferCtxt<'tcx>,
173    ) -> PredicateObligations<'tcx> {
174        let stalled_coroutines = match infcx.typing_mode() {
175            TypingMode::Analysis { defining_opaque_types_and_generators } => {
176                defining_opaque_types_and_generators
177            }
178            TypingMode::Coherence
179            | TypingMode::Borrowck { defining_opaque_types: _ }
180            | TypingMode::PostBorrowckAnalysis { defined_opaque_types: _ }
181            | TypingMode::PostAnalysis => return Default::default(),
182        };
183
184        if stalled_coroutines.is_empty() {
185            return Default::default();
186        }
187
188        let mut processor = DrainProcessor {
189            infcx,
190            removed_predicates: PredicateObligations::new(),
191            stalled_coroutines,
192        };
193        let outcome: Outcome<_, _> = self.predicates.process_obligations(&mut processor);
194        if !outcome.errors.is_empty() {
    ::core::panicking::panic("assertion failed: outcome.errors.is_empty()")
};assert!(outcome.errors.is_empty());
195        return processor.removed_predicates;
196
197        struct DrainProcessor<'a, 'tcx> {
198            infcx: &'a InferCtxt<'tcx>,
199            removed_predicates: PredicateObligations<'tcx>,
200            stalled_coroutines: &'tcx ty::List<LocalDefId>,
201        }
202
203        impl<'tcx> ObligationProcessor for DrainProcessor<'_, 'tcx> {
204            type Obligation = PendingPredicateObligation<'tcx>;
205            type Error = !;
206            type OUT = Outcome<Self::Obligation, Self::Error>;
207
208            fn needs_process_obligation(&self, pending_obligation: &Self::Obligation) -> bool {
209                struct StalledOnCoroutines<'tcx> {
210                    pub stalled_coroutines: &'tcx ty::List<LocalDefId>,
211                    pub cache: DelayedSet<Ty<'tcx>>,
212                }
213
214                impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for StalledOnCoroutines<'tcx> {
215                    type Result = ControlFlow<()>;
216
217                    fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
218                        if !self.cache.insert(ty) {
219                            return ControlFlow::Continue(());
220                        }
221
222                        if let ty::Coroutine(def_id, _) = ty.kind()
223                            && def_id
224                                .as_local()
225                                .is_some_and(|def_id| self.stalled_coroutines.contains(&def_id))
226                        {
227                            ControlFlow::Break(())
228                        } else if ty.has_coroutines() {
229                            ty.super_visit_with(self)
230                        } else {
231                            ControlFlow::Continue(())
232                        }
233                    }
234                }
235
236                self.infcx
237                    .resolve_vars_if_possible(pending_obligation.obligation.predicate)
238                    .visit_with(&mut StalledOnCoroutines {
239                        stalled_coroutines: self.stalled_coroutines,
240                        cache: Default::default(),
241                    })
242                    .is_break()
243            }
244
245            fn process_obligation(
246                &mut self,
247                pending_obligation: &mut PendingPredicateObligation<'tcx>,
248            ) -> ProcessResult<PendingPredicateObligation<'tcx>, !> {
249                if !self.needs_process_obligation(pending_obligation) {
    ::core::panicking::panic("assertion failed: self.needs_process_obligation(pending_obligation)")
};assert!(self.needs_process_obligation(pending_obligation));
250                self.removed_predicates.push(pending_obligation.obligation.clone());
251                ProcessResult::Changed(Default::default())
252            }
253
254            fn process_backedge<'c, I>(
255                &mut self,
256                cycle: I,
257                _marker: PhantomData<&'c PendingPredicateObligation<'tcx>>,
258            ) -> Result<(), !>
259            where
260                I: Clone + Iterator<Item = &'c PendingPredicateObligation<'tcx>>,
261            {
262                self.removed_predicates.extend(cycle.map(|c| c.obligation.clone()));
263                Ok(())
264            }
265        }
266    }
267
268    fn has_pending_obligations(&self) -> bool {
269        self.predicates.has_pending_obligations()
270    }
271
272    fn pending_obligations(&self) -> PredicateObligations<'tcx> {
273        self.predicates.map_pending_obligations(|o| o.obligation.clone())
274    }
275}
276
277struct FulfillProcessor<'a, 'tcx> {
278    selcx: SelectionContext<'a, 'tcx>,
279}
280
281fn mk_pending<'tcx>(
282    parent: &PredicateObligation<'tcx>,
283    os: PredicateObligations<'tcx>,
284) -> PendingPredicateObligations<'tcx> {
285    os.into_iter()
286        .map(|mut o| {
287            o.set_depth_from_parent(parent.recursion_depth);
288            PendingPredicateObligation { obligation: o, stalled_on: ::alloc::vec::Vec::new()vec![] }
289        })
290        .collect()
291}
292
293impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
294    type Obligation = PendingPredicateObligation<'tcx>;
295    type Error = FulfillmentErrorCode<'tcx>;
296    type OUT = Outcome<Self::Obligation, Self::Error>;
297
298    /// Compared to `needs_process_obligation` this and its callees
299    /// contain some optimizations that come at the price of false negatives.
300    ///
301    /// They
302    /// - reduce branching by covering only the most common case
303    /// - take a read-only view of the unification tables which allows skipping undo_log
304    ///   construction.
305    /// - bail out on value-cache misses in ena to avoid pointer chasing
306    /// - hoist RefCell locking out of the loop
307    #[inline]
308    fn skippable_obligations<'b>(
309        &'b self,
310        it: impl Iterator<Item = &'b Self::Obligation>,
311    ) -> usize {
312        let is_unchanged = self.selcx.infcx.is_ty_infer_var_definitely_unchanged();
313
314        it.take_while(|o| match o.stalled_on.as_slice() {
315            [o] => is_unchanged(*o),
316            _ => false,
317        })
318        .count()
319    }
320
321    /// Identifies whether a predicate obligation needs processing.
322    ///
323    /// This is always inlined because it has a single callsite and it is
324    /// called *very* frequently. Be careful modifying this code! Several
325    /// compile-time benchmarks are very sensitive to even small changes.
326    #[inline(always)]
327    fn needs_process_obligation(&self, pending_obligation: &Self::Obligation) -> bool {
328        // If we were stalled on some unresolved variables, first check whether
329        // any of them have been resolved; if not, don't bother doing more work
330        // yet.
331        let stalled_on = &pending_obligation.stalled_on;
332        match stalled_on.len() {
333            // This case is the hottest most of the time, being hit up to 99%
334            // of the time. `keccak` and `cranelift-codegen-0.82.1` are
335            // benchmarks that particularly stress this path.
336            1 => self.selcx.infcx.ty_or_const_infer_var_changed(stalled_on[0]),
337
338            // In this case we haven't changed, but wish to make a change. Note
339            // that this is a special case, and is not equivalent to the `_`
340            // case below, which would return `false` for an empty `stalled_on`
341            // vector.
342            //
343            // This case is usually hit only 1% of the time or less, though it
344            // reaches 20% in `wasmparser-0.101.0`.
345            0 => true,
346
347            // This case is usually hit only 1% of the time or less, though it
348            // reaches 95% in `mime-0.3.16`, 64% in `wast-54.0.0`, and 12% in
349            // `inflate-0.4.5`.
350            //
351            // The obvious way of writing this, with a call to `any()` and no
352            // closure, is currently slower than this version.
353            _ => (|| {
354                for &infer_var in stalled_on {
355                    if self.selcx.infcx.ty_or_const_infer_var_changed(infer_var) {
356                        return true;
357                    }
358                }
359                false
360            })(),
361        }
362    }
363
364    /// Processes a predicate obligation and returns either:
365    /// - `Changed(v)` if the predicate is true, presuming that `v` are also true
366    /// - `Unchanged` if we don't have enough info to be sure
367    /// - `Error(e)` if the predicate does not hold
368    ///
369    /// This is called much less often than `needs_process_obligation`, so we
370    /// never inline it.
371    #[inline(never)]
372    #[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("process_obligation",
                                    "rustc_trait_selection::traits::fulfill",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                                    ::tracing_core::__macro_support::Option::Some(372u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                                    ::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::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,
                        &{ 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:
                    ProcessResult<PendingPredicateObligation<'tcx>,
                    FulfillmentErrorCode<'tcx>> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            pending_obligation.stalled_on.clear();
            let obligation = &mut pending_obligation.obligation;
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/fulfill.rs:381",
                                    "rustc_trait_selection::traits::fulfill",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                                    ::tracing_core::__macro_support::Option::Some(381u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                                    ::tracing_core::field::FieldSet::new(&["message",
                                                    "obligation"],
                                        ::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!("pre-resolve")
                                                        as &dyn Value)),
                                            (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&debug(&obligation)
                                                        as &dyn Value))])
                        });
                } else { ; }
            };
            if obligation.predicate.has_non_region_infer() {
                obligation.predicate =
                    self.selcx.infcx.resolve_vars_if_possible(obligation.predicate);
            }
            let obligation = &pending_obligation.obligation;
            let infcx = self.selcx.infcx;
            if sizedness_fast_path(infcx.tcx, obligation.predicate,
                    obligation.param_env) {
                return ProcessResult::Changed(::thin_vec::ThinVec::new());
            }
            if obligation.predicate.has_aliases() {
                let mut obligations = PredicateObligations::new();
                let predicate =
                    normalize_with_depth_to(&mut self.selcx,
                        obligation.param_env, obligation.cause.clone(),
                        obligation.recursion_depth + 1, obligation.predicate,
                        &mut obligations);
                if predicate != obligation.predicate {
                    obligations.push(obligation.with(infcx.tcx, predicate));
                    return ProcessResult::Changed(mk_pending(obligation,
                                obligations));
                }
            }
            let binder = obligation.predicate.kind();
            match binder.no_bound_vars() {
                None =>
                    match binder.skip_binder() {
                        ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref))
                            => {
                            let trait_obligation =
                                obligation.with(infcx.tcx, binder.rebind(trait_ref));
                            self.process_trait_obligation(obligation, trait_obligation,
                                &mut pending_obligation.stalled_on)
                        }
                        ty::PredicateKind::Clause(ty::ClauseKind::Projection(data))
                            => {
                            let project_obligation =
                                obligation.with(infcx.tcx, binder.rebind(data));
                            self.process_projection_obligation(obligation,
                                project_obligation, &mut pending_obligation.stalled_on)
                        }
                        ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(_))
                            | ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(_))
                            |
                            ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
                            | ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) |
                            ty::PredicateKind::DynCompatible(_) |
                            ty::PredicateKind::Subtype(_) | ty::PredicateKind::Coerce(_)
                            |
                            ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
                            | ty::PredicateKind::ConstEquate(..) |
                            ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..)) =>
                            {
                            let pred =
                                ty::Binder::dummy(infcx.enter_forall_and_leak_universe(binder));
                            let mut obligations =
                                PredicateObligations::with_capacity(1);
                            obligations.push(obligation.with(infcx.tcx, pred));
                            ProcessResult::Changed(mk_pending(obligation, obligations))
                        }
                        ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
                        ty::PredicateKind::NormalizesTo(..) => {
                            ::rustc_middle::util::bug::bug_fmt(format_args!("NormalizesTo is only used by the new solver"))
                        }
                        ty::PredicateKind::AliasRelate(..) => {
                            ::rustc_middle::util::bug::bug_fmt(format_args!("AliasRelate is only used by the new solver"))
                        }
                        ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_))
                            => {
                            {
                                ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
                                        format_args!("unexpected higher ranked `UnstableFeature` goal")));
                            }
                        }
                    },
                Some(pred) =>
                    match pred {
                        ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
                            let trait_obligation =
                                obligation.with(infcx.tcx, Binder::dummy(data));
                            self.process_trait_obligation(obligation, trait_obligation,
                                &mut pending_obligation.stalled_on)
                        }
                        ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(data))
                            => {
                            let host_obligation = obligation.with(infcx.tcx, data);
                            self.process_host_obligation(obligation, host_obligation,
                                &mut pending_obligation.stalled_on)
                        }
                        ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(data))
                            => {
                            if infcx.considering_regions {
                                infcx.register_region_outlives_constraint(data,
                                    ty::VisibleForLeakCheck::Yes, &obligation.cause);
                            }
                            ProcessResult::Changed(Default::default())
                        }
                        ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(t_a,
                            r_b))) => {
                            if infcx.considering_regions {
                                infcx.register_type_outlives_constraint(t_a, r_b,
                                    &obligation.cause);
                            }
                            ProcessResult::Changed(Default::default())
                        }
                        ty::PredicateKind::Clause(ty::ClauseKind::Projection(ref data))
                            => {
                            let project_obligation =
                                obligation.with(infcx.tcx, Binder::dummy(*data));
                            self.process_projection_obligation(obligation,
                                project_obligation, &mut pending_obligation.stalled_on)
                        }
                        ty::PredicateKind::DynCompatible(trait_def_id) => {
                            if !self.selcx.tcx().is_dyn_compatible(trait_def_id) {
                                ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::Unimplemented))
                            } else { ProcessResult::Changed(Default::default()) }
                        }
                        ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
                        ty::PredicateKind::NormalizesTo(..) => {
                            ::rustc_middle::util::bug::bug_fmt(format_args!("NormalizesTo is only used by the new solver"))
                        }
                        ty::PredicateKind::AliasRelate(..) => {
                            ::rustc_middle::util::bug::bug_fmt(format_args!("AliasRelate is only used by the new solver"))
                        }
                        ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct,
                            ty)) => {
                            let ct = infcx.shallow_resolve_const(ct);
                            let ct_ty =
                                match ct.kind() {
                                    ty::ConstKind::Infer(var) => {
                                        let var =
                                            match var {
                                                ty::InferConst::Var(vid) => TyOrConstInferVar::Const(vid),
                                                ty::InferConst::Fresh(_) => {
                                                    ::rustc_middle::util::bug::bug_fmt(format_args!("encountered fresh const in fulfill"))
                                                }
                                            };
                                        pending_obligation.stalled_on.clear();
                                        pending_obligation.stalled_on.extend([var]);
                                        return ProcessResult::Unchanged;
                                    }
                                    ty::ConstKind::Error(_) => {
                                        return ProcessResult::Changed(PendingPredicateObligations::new());
                                    }
                                    ty::ConstKind::Value(cv) => cv.ty,
                                    ty::ConstKind::Unevaluated(uv) =>
                                        infcx.tcx.type_of(uv.def).instantiate(infcx.tcx,
                                                uv.args).skip_norm_wip(),
                                    ty::ConstKind::Expr(_) => {
                                        return ProcessResult::Changed(mk_pending(obligation,
                                                    PredicateObligations::new()));
                                    }
                                    ty::ConstKind::Placeholder(_) => {
                                        ::rustc_middle::util::bug::bug_fmt(format_args!("placeholder const {0:?} in old solver",
                                                ct))
                                    }
                                    ty::ConstKind::Bound(_, _) =>
                                        ::rustc_middle::util::bug::bug_fmt(format_args!("escaping bound vars in {0:?}",
                                                ct)),
                                    ty::ConstKind::Param(param_ct) => {
                                        param_ct.find_const_ty_from_env(obligation.param_env)
                                    }
                                };
                            match infcx.at(&obligation.cause,
                                        obligation.param_env).eq(DefineOpaqueTypes::Yes, ct_ty, ty)
                                {
                                Ok(inf_ok) =>
                                    ProcessResult::Changed(mk_pending(obligation,
                                            inf_ok.into_obligations())),
                                Err(_) =>
                                    ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::ConstArgHasWrongType {
                                                ct,
                                                ct_ty,
                                                expected_ty: ty,
                                            })),
                            }
                        }
                        _ if
                            !self.selcx.tcx().recursion_limit().value_within_limit(obligation.recursion_depth)
                            => {
                            self.selcx.infcx.err_ctxt().report_overflow_obligation(&obligation,
                                false);
                        }
                        ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term))
                            => {
                            if term.is_trivially_wf(self.selcx.tcx()) {
                                return ProcessResult::Changed(::thin_vec::ThinVec::new());
                            }
                            match wf::obligations(self.selcx.infcx,
                                    obligation.param_env, obligation.cause.body_id,
                                    obligation.recursion_depth + 1, term, obligation.cause.span)
                                {
                                None => {
                                    pending_obligation.stalled_on =
                                        ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                                [TyOrConstInferVar::maybe_from_term(term).unwrap()]));
                                    ProcessResult::Unchanged
                                }
                                Some(os) =>
                                    ProcessResult::Changed(mk_pending(obligation, os)),
                            }
                        }
                        ty::PredicateKind::Subtype(subtype) => {
                            match self.selcx.infcx.subtype_predicate(&obligation.cause,
                                    obligation.param_env, Binder::dummy(subtype)) {
                                Err((a, b)) => {
                                    pending_obligation.stalled_on =
                                        ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                                [TyOrConstInferVar::Ty(a), TyOrConstInferVar::Ty(b)]));
                                    ProcessResult::Unchanged
                                }
                                Ok(Ok(ok)) => {
                                    ProcessResult::Changed(mk_pending(obligation,
                                            ok.obligations))
                                }
                                Ok(Err(err)) => {
                                    let expected_found =
                                        if subtype.a_is_expected {
                                            ExpectedFound::new(subtype.a, subtype.b)
                                        } else { ExpectedFound::new(subtype.b, subtype.a) };
                                    ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found,
                                            err))
                                }
                            }
                        }
                        ty::PredicateKind::Coerce(coerce) => {
                            match self.selcx.infcx.coerce_predicate(&obligation.cause,
                                    obligation.param_env, Binder::dummy(coerce)) {
                                Err((a, b)) => {
                                    pending_obligation.stalled_on =
                                        ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                                [TyOrConstInferVar::Ty(a), TyOrConstInferVar::Ty(b)]));
                                    ProcessResult::Unchanged
                                }
                                Ok(Ok(ok)) => {
                                    ProcessResult::Changed(mk_pending(obligation,
                                            ok.obligations))
                                }
                                Ok(Err(err)) => {
                                    let expected_found = ExpectedFound::new(coerce.b, coerce.a);
                                    ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found,
                                            err))
                                }
                            }
                        }
                        ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv))
                            => {
                            match const_evaluatable::is_const_evaluatable(self.selcx.infcx,
                                    uv, obligation.param_env, obligation.cause.span) {
                                Ok(()) => ProcessResult::Changed(Default::default()),
                                Err(NotConstEvaluatable::MentionsInfer) => {
                                    pending_obligation.stalled_on.clear();
                                    pending_obligation.stalled_on.extend(uv.walk().filter_map(TyOrConstInferVar::maybe_from_generic_arg));
                                    ProcessResult::Unchanged
                                }
                                Err(e @ NotConstEvaluatable::MentionsParam | e @
                                    NotConstEvaluatable::Error(_)) =>
                                    ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::NotConstEvaluatable(e))),
                            }
                        }
                        ty::PredicateKind::ConstEquate(c1, c2) => {
                            let tcx = self.selcx.tcx();
                            if !tcx.features().generic_const_exprs() {
                                {
                                    ::core::panicking::panic_fmt(format_args!("`ConstEquate` without a feature gate: {0:?} {1:?}",
                                            c1, c2));
                                }
                            };
                            {
                                let c1 = tcx.expand_abstract_consts(c1);
                                let c2 = tcx.expand_abstract_consts(c2);
                                {
                                    use ::tracing::__macro_support::Callsite as _;
                                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                        {
                                            static META: ::tracing::Metadata<'static> =
                                                {
                                                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/fulfill.rs:714",
                                                        "rustc_trait_selection::traits::fulfill",
                                                        ::tracing::Level::DEBUG,
                                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                                                        ::tracing_core::__macro_support::Option::Some(714u32),
                                                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                                                        ::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!("equating consts:\nc1= {0:?}\nc2= {1:?}",
                                                                                    c1, c2) as &dyn Value))])
                                            });
                                    } else { ; }
                                };
                                use rustc_hir::def::DefKind;
                                match (c1.kind(), c2.kind()) {
                                    (ty::ConstKind::Unevaluated(a),
                                        ty::ConstKind::Unevaluated(b)) if
                                        a.def == b.def &&
                                            #[allow(non_exhaustive_omitted_patterns)] match tcx.def_kind(a.def)
                                                {
                                                DefKind::AssocConst { .. } => true,
                                                _ => false,
                                            } => {
                                        if let Ok(new_obligations) =
                                                infcx.at(&obligation.cause,
                                                        obligation.param_env).eq(DefineOpaqueTypes::Yes,
                                                    ty::AliasTerm::from_unevaluated_const(tcx, a),
                                                    ty::AliasTerm::from_unevaluated_const(tcx, b)) {
                                            return ProcessResult::Changed(mk_pending(obligation,
                                                        new_obligations.into_obligations()));
                                        }
                                    }
                                    (_, ty::ConstKind::Unevaluated(_)) |
                                        (ty::ConstKind::Unevaluated(_), _) => (),
                                    (_, _) => {
                                        if let Ok(new_obligations) =
                                                infcx.at(&obligation.cause,
                                                        obligation.param_env).eq(DefineOpaqueTypes::Yes, c1, c2) {
                                            return ProcessResult::Changed(mk_pending(obligation,
                                                        new_obligations.into_obligations()));
                                        }
                                    }
                                }
                            }
                            let stalled_on = &mut pending_obligation.stalled_on;
                            let mut evaluate =
                                |c: Const<'tcx>|
                                    {
                                        if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
                                            match super::try_evaluate_const(self.selcx.infcx, c,
                                                    obligation.param_env) {
                                                Ok(val) => Ok(val),
                                                e @ Err(EvaluateConstErr::HasGenericsOrInfers) => {
                                                    stalled_on.extend(unevaluated.args.iter().filter_map(TyOrConstInferVar::maybe_from_generic_arg));
                                                    e
                                                }
                                                e @
                                                    Err(EvaluateConstErr::EvaluationFailure(_) |
                                                    EvaluateConstErr::InvalidConstParamTy(_)) => e,
                                            }
                                        } else { Ok(c) }
                                    };
                            match (evaluate(c1), evaluate(c2)) {
                                (Ok(c1), Ok(c2)) => {
                                    match self.selcx.infcx.at(&obligation.cause,
                                                obligation.param_env).eq(DefineOpaqueTypes::Yes, c1, c2) {
                                        Ok(inf_ok) =>
                                            ProcessResult::Changed(mk_pending(obligation,
                                                    inf_ok.into_obligations())),
                                        Err(err) => {
                                            ProcessResult::Error(FulfillmentErrorCode::ConstEquate(ExpectedFound::new(c1,
                                                        c2), err))
                                        }
                                    }
                                }
                                (Err(EvaluateConstErr::InvalidConstParamTy(e)), _) |
                                    (_, Err(EvaluateConstErr::InvalidConstParamTy(e))) => {
                                    ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(e))))
                                }
                                (Err(EvaluateConstErr::EvaluationFailure(e)), _) |
                                    (_, Err(EvaluateConstErr::EvaluationFailure(e))) => {
                                    ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(e))))
                                }
                                (Err(EvaluateConstErr::HasGenericsOrInfers), _) |
                                    (_, Err(EvaluateConstErr::HasGenericsOrInfers)) => {
                                    if c1.has_non_region_infer() || c2.has_non_region_infer() {
                                        ProcessResult::Unchanged
                                    } else {
                                        let expected_found = ExpectedFound::new(c1, c2);
                                        ProcessResult::Error(FulfillmentErrorCode::ConstEquate(expected_found,
                                                TypeError::ConstMismatch(expected_found)))
                                    }
                                }
                            }
                        }
                        ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol))
                            => {
                            if may_use_unstable_feature(self.selcx.infcx,
                                    obligation.param_env, symbol) {
                                ProcessResult::Changed(Default::default())
                            } else { ProcessResult::Unchanged }
                        }
                    },
            }
        }
    }
}#[instrument(level = "debug", skip(self, pending_obligation))]
373    fn process_obligation(
374        &mut self,
375        pending_obligation: &mut PendingPredicateObligation<'tcx>,
376    ) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
377        pending_obligation.stalled_on.clear();
378
379        let obligation = &mut pending_obligation.obligation;
380
381        debug!(?obligation, "pre-resolve");
382
383        if obligation.predicate.has_non_region_infer() {
384            obligation.predicate = self.selcx.infcx.resolve_vars_if_possible(obligation.predicate);
385        }
386
387        let obligation = &pending_obligation.obligation;
388
389        let infcx = self.selcx.infcx;
390
391        if sizedness_fast_path(infcx.tcx, obligation.predicate, obligation.param_env) {
392            return ProcessResult::Changed(thin_vec![]);
393        }
394
395        if obligation.predicate.has_aliases() {
396            let mut obligations = PredicateObligations::new();
397            let predicate = normalize_with_depth_to(
398                &mut self.selcx,
399                obligation.param_env,
400                obligation.cause.clone(),
401                obligation.recursion_depth + 1,
402                obligation.predicate,
403                &mut obligations,
404            );
405            if predicate != obligation.predicate {
406                obligations.push(obligation.with(infcx.tcx, predicate));
407                return ProcessResult::Changed(mk_pending(obligation, obligations));
408            }
409        }
410        let binder = obligation.predicate.kind();
411        match binder.no_bound_vars() {
412            None => match binder.skip_binder() {
413                // Evaluation will discard candidates using the leak check.
414                // This means we need to pass it the bound version of our
415                // predicate.
416                ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) => {
417                    let trait_obligation = obligation.with(infcx.tcx, binder.rebind(trait_ref));
418
419                    self.process_trait_obligation(
420                        obligation,
421                        trait_obligation,
422                        &mut pending_obligation.stalled_on,
423                    )
424                }
425                ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
426                    let project_obligation = obligation.with(infcx.tcx, binder.rebind(data));
427
428                    self.process_projection_obligation(
429                        obligation,
430                        project_obligation,
431                        &mut pending_obligation.stalled_on,
432                    )
433                }
434                ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(_))
435                | ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(_))
436                | ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
437                | ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_))
438                | ty::PredicateKind::DynCompatible(_)
439                | ty::PredicateKind::Subtype(_)
440                | ty::PredicateKind::Coerce(_)
441                | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
442                | ty::PredicateKind::ConstEquate(..)
443                // FIXME(const_trait_impl): We may need to do this using the higher-ranked
444                // pred instead of just instantiating it with placeholders b/c of
445                // higher-ranked implied bound issues in the old solver.
446                | ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..)) => {
447                    let pred = ty::Binder::dummy(infcx.enter_forall_and_leak_universe(binder));
448                    let mut obligations = PredicateObligations::with_capacity(1);
449                    obligations.push(obligation.with(infcx.tcx, pred));
450
451                    ProcessResult::Changed(mk_pending(obligation, obligations))
452                }
453                ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
454                ty::PredicateKind::NormalizesTo(..) => {
455                    bug!("NormalizesTo is only used by the new solver")
456                }
457                ty::PredicateKind::AliasRelate(..) => {
458                    bug!("AliasRelate is only used by the new solver")
459                }
460                ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_)) => {
461                   unreachable!("unexpected higher ranked `UnstableFeature` goal")
462                }
463            },
464            Some(pred) => match pred {
465                ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
466                    let trait_obligation = obligation.with(infcx.tcx, Binder::dummy(data));
467
468                    self.process_trait_obligation(
469                        obligation,
470                        trait_obligation,
471                        &mut pending_obligation.stalled_on,
472                    )
473                }
474
475                ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(data)) => {
476                    let host_obligation = obligation.with(infcx.tcx, data);
477
478                    self.process_host_obligation(
479                        obligation,
480                        host_obligation,
481                        &mut pending_obligation.stalled_on,
482                    )
483                }
484
485                ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(data)) => {
486                    if infcx.considering_regions {
487                        infcx.register_region_outlives_constraint(
488                            data,
489                            ty::VisibleForLeakCheck::Yes,
490                            &obligation.cause,
491                        );
492                    }
493
494                    ProcessResult::Changed(Default::default())
495                }
496
497                ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(
498                    t_a,
499                    r_b,
500                ))) => {
501                    if infcx.considering_regions {
502                        infcx.register_type_outlives_constraint(t_a, r_b, &obligation.cause);
503                    }
504                    ProcessResult::Changed(Default::default())
505                }
506
507                ty::PredicateKind::Clause(ty::ClauseKind::Projection(ref data)) => {
508                    let project_obligation = obligation.with(infcx.tcx, Binder::dummy(*data));
509
510                    self.process_projection_obligation(
511                        obligation,
512                        project_obligation,
513                        &mut pending_obligation.stalled_on,
514                    )
515                }
516
517                ty::PredicateKind::DynCompatible(trait_def_id) => {
518                    if !self.selcx.tcx().is_dyn_compatible(trait_def_id) {
519                        ProcessResult::Error(FulfillmentErrorCode::Select(
520                            SelectionError::Unimplemented,
521                        ))
522                    } else {
523                        ProcessResult::Changed(Default::default())
524                    }
525                }
526
527                ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
528                ty::PredicateKind::NormalizesTo(..) => {
529                    bug!("NormalizesTo is only used by the new solver")
530                }
531                ty::PredicateKind::AliasRelate(..) => {
532                    bug!("AliasRelate is only used by the new solver")
533                }
534                // Compute `ConstArgHasType` above the overflow check below.
535                // This is because this is not ever a useful obligation to report
536                // as the cause of an overflow.
537                ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
538                    let ct = infcx.shallow_resolve_const(ct);
539                    let ct_ty = match ct.kind() {
540                        ty::ConstKind::Infer(var) => {
541                            let var = match var {
542                                ty::InferConst::Var(vid) => TyOrConstInferVar::Const(vid),
543                                ty::InferConst::Fresh(_) => {
544                                    bug!("encountered fresh const in fulfill")
545                                }
546                            };
547                            pending_obligation.stalled_on.clear();
548                            pending_obligation.stalled_on.extend([var]);
549                            return ProcessResult::Unchanged;
550                        }
551                        ty::ConstKind::Error(_) => {
552                            return ProcessResult::Changed(PendingPredicateObligations::new());
553                        }
554                        ty::ConstKind::Value(cv) => cv.ty,
555                        ty::ConstKind::Unevaluated(uv) => infcx
556                            .tcx
557                            .type_of(uv.def)
558                            .instantiate(infcx.tcx, uv.args)
559                            .skip_norm_wip(),
560                        // FIXME(generic_const_exprs): we should construct an alias like
561                        // `<lhs_ty as Add<rhs_ty>>::Output` when this is an `Expr` representing
562                        // `lhs + rhs`.
563                        ty::ConstKind::Expr(_) => {
564                            return ProcessResult::Changed(mk_pending(
565                                obligation,
566                                PredicateObligations::new(),
567                            ));
568                        }
569                        ty::ConstKind::Placeholder(_) => {
570                            bug!("placeholder const {:?} in old solver", ct)
571                        }
572                        ty::ConstKind::Bound(_, _) => bug!("escaping bound vars in {:?}", ct),
573                        ty::ConstKind::Param(param_ct) => {
574                            param_ct.find_const_ty_from_env(obligation.param_env)
575                        }
576                    };
577
578                    match infcx.at(&obligation.cause, obligation.param_env).eq(
579                        // Only really exercised by generic_const_exprs
580                        DefineOpaqueTypes::Yes,
581                        ct_ty,
582                        ty,
583                    ) {
584                        Ok(inf_ok) => ProcessResult::Changed(mk_pending(
585                            obligation,
586                            inf_ok.into_obligations(),
587                        )),
588                        Err(_) => ProcessResult::Error(FulfillmentErrorCode::Select(
589                            SelectionError::ConstArgHasWrongType { ct, ct_ty, expected_ty: ty },
590                        )),
591                    }
592                }
593
594                // General case overflow check. Allow `process_trait_obligation`
595                // and `process_projection_obligation` to handle checking for
596                // the recursion limit themselves. Also don't check some
597                // predicate kinds that don't give further obligations.
598                _ if !self
599                    .selcx
600                    .tcx()
601                    .recursion_limit()
602                    .value_within_limit(obligation.recursion_depth) =>
603                {
604                    self.selcx.infcx.err_ctxt().report_overflow_obligation(&obligation, false);
605                }
606
607                ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => {
608                    if term.is_trivially_wf(self.selcx.tcx()) {
609                        return ProcessResult::Changed(thin_vec![]);
610                    }
611
612                    match wf::obligations(
613                        self.selcx.infcx,
614                        obligation.param_env,
615                        obligation.cause.body_id,
616                        obligation.recursion_depth + 1,
617                        term,
618                        obligation.cause.span,
619                    ) {
620                        None => {
621                            pending_obligation.stalled_on =
622                                vec![TyOrConstInferVar::maybe_from_term(term).unwrap()];
623                            ProcessResult::Unchanged
624                        }
625                        Some(os) => ProcessResult::Changed(mk_pending(obligation, os)),
626                    }
627                }
628
629                ty::PredicateKind::Subtype(subtype) => {
630                    match self.selcx.infcx.subtype_predicate(
631                        &obligation.cause,
632                        obligation.param_env,
633                        Binder::dummy(subtype),
634                    ) {
635                        Err((a, b)) => {
636                            // None means that both are unresolved.
637                            pending_obligation.stalled_on =
638                                vec![TyOrConstInferVar::Ty(a), TyOrConstInferVar::Ty(b)];
639                            ProcessResult::Unchanged
640                        }
641                        Ok(Ok(ok)) => {
642                            ProcessResult::Changed(mk_pending(obligation, ok.obligations))
643                        }
644                        Ok(Err(err)) => {
645                            let expected_found = if subtype.a_is_expected {
646                                ExpectedFound::new(subtype.a, subtype.b)
647                            } else {
648                                ExpectedFound::new(subtype.b, subtype.a)
649                            };
650                            ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found, err))
651                        }
652                    }
653                }
654
655                ty::PredicateKind::Coerce(coerce) => {
656                    match self.selcx.infcx.coerce_predicate(
657                        &obligation.cause,
658                        obligation.param_env,
659                        Binder::dummy(coerce),
660                    ) {
661                        Err((a, b)) => {
662                            // None means that both are unresolved.
663                            pending_obligation.stalled_on =
664                                vec![TyOrConstInferVar::Ty(a), TyOrConstInferVar::Ty(b)];
665                            ProcessResult::Unchanged
666                        }
667                        Ok(Ok(ok)) => {
668                            ProcessResult::Changed(mk_pending(obligation, ok.obligations))
669                        }
670                        Ok(Err(err)) => {
671                            let expected_found = ExpectedFound::new(coerce.b, coerce.a);
672                            ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found, err))
673                        }
674                    }
675                }
676
677                ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => {
678                    match const_evaluatable::is_const_evaluatable(
679                        self.selcx.infcx,
680                        uv,
681                        obligation.param_env,
682                        obligation.cause.span,
683                    ) {
684                        Ok(()) => ProcessResult::Changed(Default::default()),
685                        Err(NotConstEvaluatable::MentionsInfer) => {
686                            pending_obligation.stalled_on.clear();
687                            pending_obligation.stalled_on.extend(
688                                uv.walk().filter_map(TyOrConstInferVar::maybe_from_generic_arg),
689                            );
690                            ProcessResult::Unchanged
691                        }
692                        Err(
693                            e @ NotConstEvaluatable::MentionsParam
694                            | e @ NotConstEvaluatable::Error(_),
695                        ) => ProcessResult::Error(FulfillmentErrorCode::Select(
696                            SelectionError::NotConstEvaluatable(e),
697                        )),
698                    }
699                }
700
701                ty::PredicateKind::ConstEquate(c1, c2) => {
702                    let tcx = self.selcx.tcx();
703                    assert!(
704                        tcx.features().generic_const_exprs(),
705                        "`ConstEquate` without a feature gate: {c1:?} {c2:?}",
706                    );
707                    // FIXME: we probably should only try to unify abstract constants
708                    // if the constants depend on generic parameters.
709                    //
710                    // Let's just see where this breaks :shrug:
711                    {
712                        let c1 = tcx.expand_abstract_consts(c1);
713                        let c2 = tcx.expand_abstract_consts(c2);
714                        debug!("equating consts:\nc1= {:?}\nc2= {:?}", c1, c2);
715
716                        use rustc_hir::def::DefKind;
717                        match (c1.kind(), c2.kind()) {
718                            (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b))
719                                if a.def == b.def
720                                    && matches!(
721                                        tcx.def_kind(a.def),
722                                        DefKind::AssocConst { .. }
723                                    ) =>
724                            {
725                                if let Ok(new_obligations) = infcx
726                                    .at(&obligation.cause, obligation.param_env)
727                                    // Can define opaque types as this is only reachable with
728                                    // `generic_const_exprs`
729                                    .eq(
730                                        DefineOpaqueTypes::Yes,
731                                        ty::AliasTerm::from_unevaluated_const(tcx, a),
732                                        ty::AliasTerm::from_unevaluated_const(tcx, b),
733                                    )
734                                {
735                                    return ProcessResult::Changed(mk_pending(
736                                        obligation,
737                                        new_obligations.into_obligations(),
738                                    ));
739                                }
740                            }
741                            (_, ty::ConstKind::Unevaluated(_))
742                            | (ty::ConstKind::Unevaluated(_), _) => (),
743                            (_, _) => {
744                                if let Ok(new_obligations) = infcx
745                                    .at(&obligation.cause, obligation.param_env)
746                                    // Can define opaque types as this is only reachable with
747                                    // `generic_const_exprs`
748                                    .eq(DefineOpaqueTypes::Yes, c1, c2)
749                                {
750                                    return ProcessResult::Changed(mk_pending(
751                                        obligation,
752                                        new_obligations.into_obligations(),
753                                    ));
754                                }
755                            }
756                        }
757                    }
758
759                    let stalled_on = &mut pending_obligation.stalled_on;
760
761                    let mut evaluate = |c: Const<'tcx>| {
762                        if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
763                            match super::try_evaluate_const(
764                                self.selcx.infcx,
765                                c,
766                                obligation.param_env,
767                            ) {
768                                Ok(val) => Ok(val),
769                                e @ Err(EvaluateConstErr::HasGenericsOrInfers) => {
770                                    stalled_on.extend(
771                                        unevaluated
772                                            .args
773                                            .iter()
774                                            .filter_map(TyOrConstInferVar::maybe_from_generic_arg),
775                                    );
776                                    e
777                                }
778                                e @ Err(
779                                    EvaluateConstErr::EvaluationFailure(_)
780                                    | EvaluateConstErr::InvalidConstParamTy(_),
781                                ) => e,
782                            }
783                        } else {
784                            Ok(c)
785                        }
786                    };
787
788                    match (evaluate(c1), evaluate(c2)) {
789                        (Ok(c1), Ok(c2)) => {
790                            match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq(
791                                // Can define opaque types as this is only reachable with
792                                // `generic_const_exprs`
793                                DefineOpaqueTypes::Yes,
794                                c1,
795                                c2,
796                            ) {
797                                Ok(inf_ok) => ProcessResult::Changed(mk_pending(
798                                    obligation,
799                                    inf_ok.into_obligations(),
800                                )),
801                                Err(err) => {
802                                    ProcessResult::Error(FulfillmentErrorCode::ConstEquate(
803                                        ExpectedFound::new(c1, c2),
804                                        err,
805                                    ))
806                                }
807                            }
808                        }
809                        (Err(EvaluateConstErr::InvalidConstParamTy(e)), _)
810                        | (_, Err(EvaluateConstErr::InvalidConstParamTy(e))) => {
811                            ProcessResult::Error(FulfillmentErrorCode::Select(
812                                SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(e)),
813                            ))
814                        }
815                        (Err(EvaluateConstErr::EvaluationFailure(e)), _)
816                        | (_, Err(EvaluateConstErr::EvaluationFailure(e))) => {
817                            ProcessResult::Error(FulfillmentErrorCode::Select(
818                                SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(e)),
819                            ))
820                        }
821                        (Err(EvaluateConstErr::HasGenericsOrInfers), _)
822                        | (_, Err(EvaluateConstErr::HasGenericsOrInfers)) => {
823                            if c1.has_non_region_infer() || c2.has_non_region_infer() {
824                                ProcessResult::Unchanged
825                            } else {
826                                // Two different constants using generic parameters ~> error.
827                                let expected_found = ExpectedFound::new(c1, c2);
828                                ProcessResult::Error(FulfillmentErrorCode::ConstEquate(
829                                    expected_found,
830                                    TypeError::ConstMismatch(expected_found),
831                                ))
832                            }
833                        }
834                    }
835                }
836                ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
837                    if may_use_unstable_feature(self.selcx.infcx, obligation.param_env, symbol) {
838                        ProcessResult::Changed(Default::default())
839                    } else {
840                        ProcessResult::Unchanged
841                    }
842                }
843            },
844        }
845    }
846
847    #[inline(never)]
848    fn process_backedge<'c, I>(
849        &mut self,
850        cycle: I,
851        _marker: PhantomData<&'c PendingPredicateObligation<'tcx>>,
852    ) -> Result<(), FulfillmentErrorCode<'tcx>>
853    where
854        I: Clone + Iterator<Item = &'c PendingPredicateObligation<'tcx>>,
855    {
856        if self.selcx.coinductive_match(cycle.clone().map(|s| s.obligation.predicate)) {
857            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/fulfill.rs:857",
                        "rustc_trait_selection::traits::fulfill",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                        ::tracing_core::__macro_support::Option::Some(857u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                        ::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!("process_child_obligations: coinductive match")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("process_child_obligations: coinductive match");
858            Ok(())
859        } else {
860            let cycle = cycle.map(|c| c.obligation.clone()).collect();
861            Err(FulfillmentErrorCode::Cycle(cycle))
862        }
863    }
864}
865
866impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
867    #[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("process_trait_obligation",
                                    "rustc_trait_selection::traits::fulfill",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                                    ::tracing_core::__macro_support::Option::Some(867u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                                    ::tracing_core::field::FieldSet::new(&["trait_obligation"],
                                        ::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(&trait_obligation)
                                                            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:
                    ProcessResult<PendingPredicateObligation<'tcx>,
                    FulfillmentErrorCode<'tcx>> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let infcx = self.selcx.infcx;
            if obligation.predicate.is_global() &&
                    !infcx.typing_mode().is_coherence() {
                if infcx.predicate_must_hold_considering_regions(obligation) {
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/fulfill.rs:879",
                                            "rustc_trait_selection::traits::fulfill",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                                            ::tracing_core::__macro_support::Option::Some(879u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                                            ::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!("selecting trait at depth {0} evaluated to holds",
                                                                        obligation.recursion_depth) as &dyn Value))])
                                });
                        } else { ; }
                    };
                    return ProcessResult::Changed(Default::default());
                }
            }
            match self.selcx.poly_select(&trait_obligation) {
                Ok(Some(impl_source)) => {
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/fulfill.rs:889",
                                            "rustc_trait_selection::traits::fulfill",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                                            ::tracing_core::__macro_support::Option::Some(889u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                                            ::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!("selecting trait at depth {0} yielded Ok(Some)",
                                                                        obligation.recursion_depth) as &dyn Value))])
                                });
                        } else { ; }
                    };
                    ProcessResult::Changed(mk_pending(obligation,
                            impl_source.nested_obligations()))
                }
                Ok(None) => {
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/fulfill.rs:893",
                                            "rustc_trait_selection::traits::fulfill",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                                            ::tracing_core::__macro_support::Option::Some(893u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                                            ::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!("selecting trait at depth {0} yielded Ok(None)",
                                                                        obligation.recursion_depth) as &dyn Value))])
                                });
                        } else { ; }
                    };
                    stalled_on.clear();
                    stalled_on.extend(args_infer_vars(&self.selcx,
                            trait_obligation.predicate.map_bound(|pred|
                                    pred.trait_ref.args)));
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/fulfill.rs:905",
                                            "rustc_trait_selection::traits::fulfill",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                                            ::tracing_core::__macro_support::Option::Some(905u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                                            ::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!("process_predicate: pending obligation {0:?} now stalled on {1:?}",
                                                                        infcx.resolve_vars_if_possible(obligation.clone()),
                                                                        stalled_on) as &dyn Value))])
                                });
                        } else { ; }
                    };
                    ProcessResult::Unchanged
                }
                Err(selection_err) => {
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/fulfill.rs:914",
                                            "rustc_trait_selection::traits::fulfill",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                                            ::tracing_core::__macro_support::Option::Some(914u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                                            ::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!("selecting trait at depth {0} yielded Err",
                                                                        obligation.recursion_depth) as &dyn Value))])
                                });
                        } else { ; }
                    };
                    ProcessResult::Error(FulfillmentErrorCode::Select(selection_err))
                }
            }
        }
    }
}#[instrument(level = "debug", skip(self, obligation, stalled_on))]
868    fn process_trait_obligation(
869        &mut self,
870        obligation: &PredicateObligation<'tcx>,
871        trait_obligation: PolyTraitObligation<'tcx>,
872        stalled_on: &mut Vec<TyOrConstInferVar>,
873    ) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
874        let infcx = self.selcx.infcx;
875        if obligation.predicate.is_global() && !infcx.typing_mode().is_coherence() {
876            // no type variables present, can use evaluation for better caching.
877            // FIXME: consider caching errors too.
878            if infcx.predicate_must_hold_considering_regions(obligation) {
879                debug!(
880                    "selecting trait at depth {} evaluated to holds",
881                    obligation.recursion_depth
882                );
883                return ProcessResult::Changed(Default::default());
884            }
885        }
886
887        match self.selcx.poly_select(&trait_obligation) {
888            Ok(Some(impl_source)) => {
889                debug!("selecting trait at depth {} yielded Ok(Some)", obligation.recursion_depth);
890                ProcessResult::Changed(mk_pending(obligation, impl_source.nested_obligations()))
891            }
892            Ok(None) => {
893                debug!("selecting trait at depth {} yielded Ok(None)", obligation.recursion_depth);
894
895                // This is a bit subtle: for the most part, the
896                // only reason we can fail to make progress on
897                // trait selection is because we don't have enough
898                // information about the types in the trait.
899                stalled_on.clear();
900                stalled_on.extend(args_infer_vars(
901                    &self.selcx,
902                    trait_obligation.predicate.map_bound(|pred| pred.trait_ref.args),
903                ));
904
905                debug!(
906                    "process_predicate: pending obligation {:?} now stalled on {:?}",
907                    infcx.resolve_vars_if_possible(obligation.clone()),
908                    stalled_on
909                );
910
911                ProcessResult::Unchanged
912            }
913            Err(selection_err) => {
914                debug!("selecting trait at depth {} yielded Err", obligation.recursion_depth);
915
916                ProcessResult::Error(FulfillmentErrorCode::Select(selection_err))
917            }
918        }
919    }
920
921    fn process_projection_obligation(
922        &mut self,
923        obligation: &PredicateObligation<'tcx>,
924        project_obligation: PolyProjectionObligation<'tcx>,
925        stalled_on: &mut Vec<TyOrConstInferVar>,
926    ) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
927        let tcx = self.selcx.tcx();
928        let infcx = self.selcx.infcx;
929        if obligation.predicate.is_global() && !infcx.typing_mode().is_coherence() {
930            // no type variables present, can use evaluation for better caching.
931            // FIXME: consider caching errors too.
932            if infcx.predicate_must_hold_considering_regions(obligation) {
933                if let Some(key) = ProjectionCacheKey::from_poly_projection_obligation(
934                    &mut self.selcx,
935                    &project_obligation,
936                ) {
937                    // If `predicate_must_hold_considering_regions` succeeds, then we've
938                    // evaluated all sub-obligations. We can therefore mark the 'root'
939                    // obligation as complete, and skip evaluating sub-obligations.
940                    infcx
941                        .inner
942                        .borrow_mut()
943                        .projection_cache()
944                        .complete(key, EvaluationResult::EvaluatedToOk);
945                }
946                return ProcessResult::Changed(Default::default());
947            } else {
948                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/fulfill.rs:948",
                        "rustc_trait_selection::traits::fulfill",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/fulfill.rs"),
                        ::tracing_core::__macro_support::Option::Some(948u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
                        ::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!("Does NOT hold: {0:?}",
                                                    obligation) as &dyn Value))])
            });
    } else { ; }
};debug!("Does NOT hold: {:?}", obligation);
949            }
950        }
951
952        match project::poly_project_and_unify_term(&mut self.selcx, &project_obligation) {
953            ProjectAndUnifyResult::Holds(os) => ProcessResult::Changed(mk_pending(obligation, os)),
954            ProjectAndUnifyResult::FailedNormalization => {
955                stalled_on.clear();
956                stalled_on.extend(args_infer_vars(
957                    &self.selcx,
958                    project_obligation.predicate.map_bound(|pred| pred.projection_term.args),
959                ));
960                ProcessResult::Unchanged
961            }
962            // Let the caller handle the recursion
963            ProjectAndUnifyResult::Recursive => {
964                let mut obligations = PredicateObligations::with_capacity(1);
965                obligations.push(project_obligation.with(tcx, project_obligation.predicate));
966
967                ProcessResult::Changed(mk_pending(obligation, obligations))
968            }
969            ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
970                ProcessResult::Error(FulfillmentErrorCode::Project(e))
971            }
972        }
973    }
974
975    fn process_host_obligation(
976        &mut self,
977        obligation: &PredicateObligation<'tcx>,
978        host_obligation: HostEffectObligation<'tcx>,
979        stalled_on: &mut Vec<TyOrConstInferVar>,
980    ) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
981        match effects::evaluate_host_effect_obligation(&mut self.selcx, &host_obligation) {
982            Ok(nested) => ProcessResult::Changed(mk_pending(obligation, nested)),
983            Err(effects::EvaluationFailure::Ambiguous) => {
984                stalled_on.clear();
985                stalled_on.extend(args_infer_vars(
986                    &self.selcx,
987                    ty::Binder::dummy(host_obligation.predicate.trait_ref.args),
988                ));
989                ProcessResult::Unchanged
990            }
991            Err(effects::EvaluationFailure::NoSolution) => {
992                ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::Unimplemented))
993            }
994        }
995    }
996}
997
998/// Returns the set of inference variables contained in `args`.
999fn args_infer_vars<'tcx>(
1000    selcx: &SelectionContext<'_, 'tcx>,
1001    args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
1002) -> impl Iterator<Item = TyOrConstInferVar> {
1003    selcx
1004        .infcx
1005        .resolve_vars_if_possible(args)
1006        .skip_binder() // ok because this check doesn't care about regions
1007        .iter()
1008        .filter(|arg| arg.has_non_region_infer())
1009        .flat_map(|arg| {
1010            let mut walker = arg.walk();
1011            while let Some(c) = walker.next() {
1012                if !c.has_non_region_infer() {
1013                    walker.visited.remove(&c);
1014                    walker.skip_current_subtree();
1015                }
1016            }
1017            walker.visited.into_iter()
1018        })
1019        .filter_map(TyOrConstInferVar::maybe_from_generic_arg)
1020}
1021
1022#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for OldSolverError<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_tuple_field1_finish(f, "OldSolverError",
            &&self.0)
    }
}Debug)]
1023pub struct OldSolverError<'tcx>(
1024    Error<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>>,
1025);
1026
1027impl<'tcx> FromSolverError<'tcx, OldSolverError<'tcx>> for FulfillmentError<'tcx> {
1028    fn from_solver_error(_infcx: &InferCtxt<'tcx>, error: OldSolverError<'tcx>) -> Self {
1029        let mut iter = error.0.backtrace.into_iter();
1030        let obligation = iter.next().unwrap().obligation;
1031        // The root obligation is the last item in the backtrace - if there's only
1032        // one item, then it's the same as the main obligation
1033        let root_obligation = iter.next_back().map_or_else(|| obligation.clone(), |e| e.obligation);
1034        FulfillmentError::new(obligation, error.0.error, root_obligation)
1035    }
1036}
1037
1038impl<'tcx> FromSolverError<'tcx, OldSolverError<'tcx>> for ScrubbedTraitError<'tcx> {
1039    fn from_solver_error(_infcx: &InferCtxt<'tcx>, error: OldSolverError<'tcx>) -> Self {
1040        match error.0.error {
1041            FulfillmentErrorCode::Select(_)
1042            | FulfillmentErrorCode::Project(_)
1043            | FulfillmentErrorCode::Subtype(_, _)
1044            | FulfillmentErrorCode::ConstEquate(_, _) => ScrubbedTraitError::TrueError,
1045            FulfillmentErrorCode::Ambiguity { overflow: _ } => ScrubbedTraitError::Ambiguity,
1046            FulfillmentErrorCode::Cycle(cycle) => ScrubbedTraitError::Cycle(cycle),
1047        }
1048    }
1049}