Skip to main content

rustc_trait_selection/traits/select/
mod.rs

1//! Candidate selection. See the [rustc dev guide] for more information on how this works.
2//!
3//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html#selection
4
5use std::cell::{Cell, RefCell};
6use std::cmp;
7use std::fmt::{self, Display};
8use std::ops::ControlFlow;
9
10use hir::def::DefKind;
11use rustc_attr_ir::lang_items::LangItem;
12use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
13use rustc_errors::Diag;
14use rustc_hir as hir;
15use rustc_hir::def_id::DefId;
16use rustc_infer::infer::BoundRegionConversionTime::{self, HigherRankedType};
17use rustc_infer::infer::DefineOpaqueTypes;
18use rustc_infer::infer::at::ToTrace;
19use rustc_infer::infer::relate::TypeRelation;
20use rustc_infer::traits::{ImplSource, PredicateObligations, TraitObligation};
21use rustc_macros::{TypeFoldable, TypeVisitable};
22use rustc_middle::dep_graph::{DepKind, DepNodeIndex};
23pub use rustc_middle::traits::select::*;
24use rustc_middle::ty::abstract_const::NotConstEvaluatable;
25use rustc_middle::ty::error::TypeErrorToStringExt;
26use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
27use rustc_middle::ty::{
28    self, CandidatePreferenceMode, CantBeErased, DeepRejectCtxt, GenericArgsRef,
29    PolyProjectionClause, SizedTraitKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, TypingMode,
30    Unnormalized, Upcast, elaborate, may_use_unstable_feature,
31};
32use rustc_next_trait_solver::solve::AliasBoundKind;
33use rustc_span::bug;
34use tracing::{debug, instrument, trace};
35
36use self::EvaluationResult::*;
37use self::SelectionCandidate::*;
38use super::project::ProjectionTermObligation;
39use super::util::closure_trait_ref_and_return_type;
40use super::{
41    ImplDerivedCause, Normalized, Obligation, ObligationCause, ObligationCauseCode,
42    PolyTraitObligation, PredicateObligation, Selection, SelectionError, SelectionResult,
43    TraitQueryMode, const_evaluatable, project, util, wf,
44};
45use crate::error_reporting::InferCtxtErrorExt;
46use crate::infer::{InferCtxt, InferOk, TypeFreshener};
47use crate::solve::InferCtxtSelectExt as _;
48use crate::traits::normalize::{normalize_with_depth, normalize_with_depth_to};
49use crate::traits::project::{ProjectAndUnifyResult, ProjectionCacheKeyExt};
50use crate::traits::{EvaluateConstErr, ProjectionCacheKey, effects, sizedness_fast_path};
51
52mod _match;
53mod candidate_assembly;
54mod confirmation;
55
56#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for IntercrateAmbiguityCause<'tcx> {
    #[inline]
    fn clone(&self) -> Self {
        match self {
            Self::DownstreamCrate { trait_ref: __self_0, self_ty: __self_1 }
                =>
                IntercrateAmbiguityCause::DownstreamCrate {
                    trait_ref: ::core::clone::Clone::clone(__self_0),
                    self_ty: ::core::clone::Clone::clone(__self_1),
                },
            Self::UpstreamCrateUpdate { trait_ref: __self_0, self_ty: __self_1
                } =>
                IntercrateAmbiguityCause::UpstreamCrateUpdate {
                    trait_ref: ::core::clone::Clone::clone(__self_0),
                    self_ty: ::core::clone::Clone::clone(__self_1),
                },
        }
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for IntercrateAmbiguityCause<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::DownstreamCrate { trait_ref: __self_0, self_ty: __self_1 }
                =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "DownstreamCrate", "trait_ref", __self_0, "self_ty",
                    &__self_1),
            Self::UpstreamCrateUpdate { trait_ref: __self_0, self_ty: __self_1
                } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "UpstreamCrateUpdate", "trait_ref", __self_0, "self_ty",
                    &__self_1),
        }
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for IntercrateAmbiguityCause<'tcx> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<ty::TraitRef<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<Option<Ty<'tcx>>>;
        let _: ::core::cmp::AssertParamIsEq<ty::TraitRef<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<Option<Ty<'tcx>>>;
    }
}Eq, #[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for
    IntercrateAmbiguityCause<'tcx> {
}
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for IntercrateAmbiguityCause<'tcx> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
                ::core::intrinsics::discriminant_value(other) &&
            match (self, other) {
                (Self::DownstreamCrate {
                    trait_ref: __self_0, self_ty: __self_1 },
                    Self::DownstreamCrate {
                    trait_ref: __arg1_0, self_ty: __arg1_1 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (Self::UpstreamCrateUpdate {
                    trait_ref: __self_0, self_ty: __self_1 },
                    Self::UpstreamCrateUpdate {
                    trait_ref: __arg1_0, self_ty: __arg1_1 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                _ => unsafe { ::core::intrinsics::unreachable() }
            }
    }
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for IntercrateAmbiguityCause<'tcx> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
            state);
        match self {
            Self::DownstreamCrate { trait_ref: __self_0, self_ty: __self_1 }
                => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            Self::UpstreamCrateUpdate { trait_ref: __self_0, self_ty: __self_1
                } => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
        }
    }
}Hash)]
57pub enum IntercrateAmbiguityCause<'tcx> {
58    DownstreamCrate { trait_ref: ty::TraitRef<'tcx>, self_ty: Option<Ty<'tcx>> },
59    UpstreamCrateUpdate { trait_ref: ty::TraitRef<'tcx>, self_ty: Option<Ty<'tcx>> },
60}
61
62impl<'tcx> IntercrateAmbiguityCause<'tcx> {
63    /// Emits notes when the overlap is caused by complex intercrate ambiguities.
64    /// See #23980 for details.
65    pub fn add_intercrate_ambiguity_hint(&self, err: &mut Diag<'_>) {
66        err.note(self.intercrate_ambiguity_hint());
67    }
68
69    pub fn intercrate_ambiguity_hint(&self) -> String {
70        {
    let _guard = NoTrimmedGuard::new();
    match self {
        IntercrateAmbiguityCause::DownstreamCrate { trait_ref, self_ty } => {
            ::alloc::__export::must_use({
                    ::alloc::fmt::format(format_args!("downstream crates may implement trait `{0}`{1}",
                            trait_ref.print_trait_sugared(),
                            if let Some(self_ty) = self_ty {
                                ::alloc::__export::must_use({
                                        ::alloc::fmt::format(format_args!(" for type `{0}`",
                                                self_ty))
                                    })
                            } else { String::new() }))
                })
        }
        IntercrateAmbiguityCause::UpstreamCrateUpdate { trait_ref, self_ty }
            => {
            ::alloc::__export::must_use({
                    ::alloc::fmt::format(format_args!("upstream crates may add a new impl of trait `{0}`{1} in future versions",
                            trait_ref.print_trait_sugared(),
                            if let Some(self_ty) = self_ty {
                                ::alloc::__export::must_use({
                                        ::alloc::fmt::format(format_args!(" for type `{0}`",
                                                self_ty))
                                    })
                            } else { String::new() }))
                })
        }
    }
}with_no_trimmed_paths!(match self {
71            IntercrateAmbiguityCause::DownstreamCrate { trait_ref, self_ty } => {
72                format!(
73                    "downstream crates may implement trait `{trait_desc}`{self_desc}",
74                    trait_desc = trait_ref.print_trait_sugared(),
75                    self_desc = if let Some(self_ty) = self_ty {
76                        format!(" for type `{self_ty}`")
77                    } else {
78                        String::new()
79                    }
80                )
81            }
82            IntercrateAmbiguityCause::UpstreamCrateUpdate { trait_ref, self_ty } => {
83                format!(
84                    "upstream crates may add a new impl of trait `{trait_desc}`{self_desc} \
85                in future versions",
86                    trait_desc = trait_ref.print_trait_sugared(),
87                    self_desc = if let Some(self_ty) = self_ty {
88                        format!(" for type `{self_ty}`")
89                    } else {
90                        String::new()
91                    }
92                )
93            }
94        })
95    }
96}
97
98pub struct SelectionContext<'cx, 'tcx> {
99    pub infcx: &'cx InferCtxt<'tcx>,
100
101    /// Freshener used specifically for entries on the obligation
102    /// stack. This ensures that all entries on the stack at one time
103    /// will have the same set of placeholder entries, which is
104    /// important for checking for trait bounds that recursively
105    /// require themselves.
106    freshener: TypeFreshener<'cx, 'tcx>,
107
108    /// The mode that trait queries run in, which informs our error handling
109    /// policy. In essence, canonicalized queries need their errors propagated
110    /// rather than immediately reported because we do not have accurate spans.
111    query_mode: TraitQueryMode,
112}
113
114// A stack that walks back up the stack frame.
115struct TraitObligationStack<'prev, 'tcx> {
116    obligation: &'prev PolyTraitObligation<'tcx>,
117
118    /// The trait predicate from `obligation` but "freshened" with the
119    /// selection-context's freshener. Used to check for recursion.
120    fresh_trait_pred: ty::PolyTraitClause<'tcx>,
121
122    /// Starts out equal to `depth` -- if, during evaluation, we
123    /// encounter a cycle, then we will set this flag to the minimum
124    /// depth of that cycle for all participants in the cycle. These
125    /// participants will then forego caching their results. This is
126    /// not the most efficient solution, but it addresses #60010. The
127    /// problem we are trying to prevent:
128    ///
129    /// - If you have `A: AutoTrait` requires `B: AutoTrait` and `C: NonAutoTrait`
130    /// - `B: AutoTrait` requires `A: AutoTrait` (coinductive cycle, ok)
131    /// - `C: NonAutoTrait` requires `A: AutoTrait` (non-coinductive cycle, not ok)
132    ///
133    /// you don't want to cache that `B: AutoTrait` or `A: AutoTrait`
134    /// is `EvaluatedToOk`; this is because they were only considered
135    /// ok on the premise that if `A: AutoTrait` held, but we indeed
136    /// encountered a problem (later on) with `A: AutoTrait`. So we
137    /// currently set a flag on the stack node for `B: AutoTrait` (as
138    /// well as the second instance of `A: AutoTrait`) to suppress
139    /// caching.
140    ///
141    /// This is a simple, targeted fix. A more-performant fix requires
142    /// deeper changes, but would permit more caching: we could
143    /// basically defer caching until we have fully evaluated the
144    /// tree, and then cache the entire tree at once. In any case, the
145    /// performance impact here shouldn't be so horrible: every time
146    /// this is hit, we do cache at least one trait, so we only
147    /// evaluate each member of a cycle up to N times, where N is the
148    /// length of the cycle. This means the performance impact is
149    /// bounded and we shouldn't have any terrible worst-cases.
150    reached_depth: Cell<usize>,
151
152    previous: TraitObligationStackList<'prev, 'tcx>,
153
154    /// The number of parent frames plus one (thus, the topmost frame has depth 1).
155    depth: usize,
156
157    /// The depth-first number of this node in the search graph -- a
158    /// pre-order index. Basically, a freshly incremented counter.
159    dfn: usize,
160}
161
162struct SelectionCandidateSet<'tcx> {
163    /// A list of candidates that definitely apply to the current
164    /// obligation (meaning: types unify).
165    vec: Vec<SelectionCandidate<'tcx>>,
166
167    /// If `true`, then there were candidates that might or might
168    /// not have applied, but we couldn't tell. This occurs when some
169    /// of the input types are type variables, in which case there are
170    /// various "builtin" rules that might or might not trigger.
171    ambiguous: bool,
172}
173
174#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for EvaluatedCandidate<'tcx> {
}
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for EvaluatedCandidate<'tcx> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.candidate == other.candidate &&
            self.evaluation == other.evaluation
    }
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for EvaluatedCandidate<'tcx> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<SelectionCandidate<'tcx>>;
        let _: ::core::cmp::AssertParamIsEq<EvaluationResult>;
    }
}Eq, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for EvaluatedCandidate<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "EvaluatedCandidate", "candidate", &self.candidate, "evaluation",
            &&self.evaluation)
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for EvaluatedCandidate<'tcx> {
    #[inline]
    fn clone(&self) -> Self {
        EvaluatedCandidate {
            candidate: ::core::clone::Clone::clone(&self.candidate),
            evaluation: ::core::clone::Clone::clone(&self.evaluation),
        }
    }
}Clone)]
175struct EvaluatedCandidate<'tcx> {
176    candidate: SelectionCandidate<'tcx>,
177    evaluation: EvaluationResult,
178}
179
180impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
181    pub fn new(infcx: &'cx InferCtxt<'tcx>) -> SelectionContext<'cx, 'tcx> {
182        SelectionContext {
183            infcx,
184            freshener: TypeFreshener::new(infcx),
185            query_mode: TraitQueryMode::Standard,
186        }
187    }
188
189    pub fn typing_mode(&self) -> TypingMode<'tcx, CantBeErased> {
190        self.infcx.typing_mode_raw().assert_not_erased()
191    }
192
193    pub fn with_query_mode(
194        infcx: &'cx InferCtxt<'tcx>,
195        query_mode: TraitQueryMode,
196    ) -> SelectionContext<'cx, 'tcx> {
197        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:197",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(197u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("query_mode")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("query_mode");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("with_query_mode")
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&query_mode)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?query_mode, "with_query_mode");
198        SelectionContext { query_mode, ..SelectionContext::new(infcx) }
199    }
200
201    pub fn tcx(&self) -> TyCtxt<'tcx> {
202        self.infcx.tcx
203    }
204
205    ///////////////////////////////////////////////////////////////////////////
206    // Selection
207    //
208    // The selection phase tries to identify *how* an obligation will
209    // be resolved. For example, it will identify which impl or
210    // parameter bound is to be used. The process can be inconclusive
211    // if the self type in the obligation is not fully inferred. Selection
212    // can result in an error in one of two ways:
213    //
214    // 1. If no applicable impl or parameter bound can be found.
215    // 2. If the output type parameters in the obligation do not match
216    //    those specified by the impl/bound. For example, if the obligation
217    //    is `Vec<Foo>: Iterable<Bar>`, but the impl specifies
218    //    `impl<T> Iterable<T> for Vec<T>`, than an error would result.
219
220    /// Attempts to satisfy the obligation. If successful, this will affect the surrounding
221    /// type environment by performing unification.
222    {}
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("poly_select",
                                "rustc_trait_selection::traits::select",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(222u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("obligation")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("obligation");
                                                    NAME.as_str()
                                                }], ::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};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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:
                                SelectionResult<'tcx, Selection<'tcx>> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if self.infcx.next_trait_solver() {
                            return self.infcx.select_in_new_trait_solver(obligation);
                        }
                        let candidate =
                            match self.select_from_obligation(obligation) {
                                Err(SelectionError::Overflow(OverflowError::Canonical)) => {
                                    if !(self.query_mode == TraitQueryMode::Canonical) {
                                        ::core::panicking::panic("assertion failed: self.query_mode == TraitQueryMode::Canonical")
                                    };
                                    return Err(SelectionError::Overflow(OverflowError::Canonical));
                                }
                                Err(e) => { return Err(e); }
                                Ok(None) => { return Ok(None); }
                                Ok(Some(candidate)) => candidate,
                            };
                        match self.confirm_candidate(obligation, candidate) {
                            Err(SelectionError::Overflow(OverflowError::Canonical)) => {
                                if !(self.query_mode == TraitQueryMode::Canonical) {
                                    ::core::panicking::panic("assertion failed: self.query_mode == TraitQueryMode::Canonical")
                                };
                                Err(SelectionError::Overflow(OverflowError::Canonical))
                            }
                            Err(e) => Err(e),
                            Ok(ImplSource::Builtin(..)) if
                                self.typing_mode().is_reflection() => {
                                Err(SelectionError::Unimplemented)
                            }
                            Ok(candidate) => Ok(Some(candidate)),
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:222",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(222u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
223    pub fn poly_select(
224        &mut self,
225        obligation: &PolyTraitObligation<'tcx>,
226    ) -> SelectionResult<'tcx, Selection<'tcx>> {
227        if self.infcx.next_trait_solver() {
228            return self.infcx.select_in_new_trait_solver(obligation);
229        }
230
231        let candidate = match self.select_from_obligation(obligation) {
232            Err(SelectionError::Overflow(OverflowError::Canonical)) => {
233                // In standard mode, overflow must have been caught and reported
234                // earlier.
235                assert!(self.query_mode == TraitQueryMode::Canonical);
236                return Err(SelectionError::Overflow(OverflowError::Canonical));
237            }
238            Err(e) => {
239                return Err(e);
240            }
241            Ok(None) => {
242                return Ok(None);
243            }
244            Ok(Some(candidate)) => candidate,
245        };
246
247        match self.confirm_candidate(obligation, candidate) {
248            Err(SelectionError::Overflow(OverflowError::Canonical)) => {
249                assert!(self.query_mode == TraitQueryMode::Canonical);
250                Err(SelectionError::Overflow(OverflowError::Canonical))
251            }
252            Err(e) => Err(e),
253            Ok(ImplSource::Builtin(..)) if self.typing_mode().is_reflection() => {
254                // Builtin impls regularly don't satisfy the try_as_dyn requirements, so
255                // we just reject all of them.
256                Err(SelectionError::Unimplemented)
257            }
258            Ok(candidate) => Ok(Some(candidate)),
259        }
260    }
261
262    pub fn select(
263        &mut self,
264        obligation: &TraitObligation<'tcx>,
265    ) -> SelectionResult<'tcx, Selection<'tcx>> {
266        self.poly_select(&Obligation {
267            cause: obligation.cause.clone(),
268            param_env: obligation.param_env,
269            predicate: ty::Binder::dummy(obligation.predicate),
270            recursion_depth: obligation.recursion_depth,
271        })
272    }
273
274    fn select_from_obligation(
275        &mut self,
276        obligation: &PolyTraitObligation<'tcx>,
277    ) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
278        if true {
    if !!obligation.predicate.has_escaping_bound_vars() {
        ::core::panicking::panic("assertion failed: !obligation.predicate.has_escaping_bound_vars()")
    };
};debug_assert!(!obligation.predicate.has_escaping_bound_vars());
279
280        let pec = &ProvisionalEvaluationCache::default();
281        let stack = self.push_stack(TraitObligationStackList::empty(pec), obligation);
282
283        self.candidate_from_obligation(&stack)
284    }
285
286    {}
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("candidate_from_obligation",
                                "rustc_trait_selection::traits::select",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(286u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("stack")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("stack");
                                                    NAME.as_str()
                                                }], ::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};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&stack)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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:
                                SelectionResult<'tcx, SelectionCandidate<'tcx>> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if true {
                            if !!self.infcx.next_trait_solver() {
                                ::core::panicking::panic("assertion failed: !self.infcx.next_trait_solver()")
                            };
                        };
                        self.check_recursion_limit(stack.obligation,
                                stack.obligation)?;
                        let cache_fresh_trait_pred =
                            stack.obligation.predicate.fold_with(&mut TypeFreshener::new(self.infcx));
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:302",
                                                "rustc_trait_selection::traits::select",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(302u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("cache_fresh_trait_pred")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("cache_fresh_trait_pred");
                                                                    NAME.as_str()
                                                                }], ::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};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&cache_fresh_trait_pred)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        if true {
                            if !!stack.obligation.predicate.has_escaping_bound_vars() {
                                ::core::panicking::panic("assertion failed: !stack.obligation.predicate.has_escaping_bound_vars()")
                            };
                        };
                        if let Some(c) =
                                self.check_candidate_cache(stack.obligation.param_env,
                                    cache_fresh_trait_pred) {
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:308",
                                                    "rustc_trait_selection::traits::select",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(308u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                    ::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};
                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("CACHE HIT")
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            return c;
                        }
                        let (candidate, dep_node) =
                            self.in_task(|this|
                                    this.candidate_from_obligation_no_cache(stack));
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:321",
                                                "rustc_trait_selection::traits::select",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(321u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                ::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};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("CACHE MISS")
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        self.insert_candidate_cache(stack.obligation.param_env,
                            cache_fresh_trait_pred, dep_node, candidate.clone());
                        candidate
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:286",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(286u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
287    fn candidate_from_obligation<'o>(
288        &mut self,
289        stack: &TraitObligationStack<'o, 'tcx>,
290    ) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
291        debug_assert!(!self.infcx.next_trait_solver());
292        // Watch out for overflow. This intentionally bypasses (and does
293        // not update) the cache.
294        self.check_recursion_limit(stack.obligation, stack.obligation)?;
295
296        // Check the cache. Note that we freshen the trait-ref
297        // separately rather than using `stack.fresh_trait_pred` --
298        // this is because we want the unbound variables to be
299        // replaced with fresh types starting from index 0.
300        let cache_fresh_trait_pred =
301            stack.obligation.predicate.fold_with(&mut TypeFreshener::new(self.infcx));
302        debug!(?cache_fresh_trait_pred);
303        debug_assert!(!stack.obligation.predicate.has_escaping_bound_vars());
304
305        if let Some(c) =
306            self.check_candidate_cache(stack.obligation.param_env, cache_fresh_trait_pred)
307        {
308            debug!("CACHE HIT");
309            return c;
310        }
311
312        // If no match, compute result and insert into cache.
313        //
314        // FIXME(nikomatsakis) -- this cache is not taking into
315        // account cycles that may have occurred in forming the
316        // candidate. I don't know of any specific problems that
317        // result but it seems awfully suspicious.
318        let (candidate, dep_node) =
319            self.in_task(|this| this.candidate_from_obligation_no_cache(stack));
320
321        debug!("CACHE MISS");
322        self.insert_candidate_cache(
323            stack.obligation.param_env,
324            cache_fresh_trait_pred,
325            dep_node,
326            candidate.clone(),
327        );
328        candidate
329    }
330
331    fn candidate_from_obligation_no_cache<'o>(
332        &mut self,
333        stack: &TraitObligationStack<'o, 'tcx>,
334    ) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
335        let candidate_set = self.assemble_candidates(stack)?;
336
337        if candidate_set.ambiguous {
338            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:338",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(338u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("candidate set contains ambig")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("candidate set contains ambig");
339            return Ok(None);
340        }
341
342        let candidates = candidate_set.vec;
343
344        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:344",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(344u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("stack")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("stack");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("candidates")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("candidates");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assembled {0} candidates",
                                                    candidates.len()) as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&stack)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidates)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?stack, ?candidates, "assembled {} candidates", candidates.len());
345
346        // At this point, we know that each of the entries in the
347        // candidate set is *individually* applicable. Now we have to
348        // figure out if they contain mutual incompatibilities. This
349        // frequently arises if we have an unconstrained input type --
350        // for example, we are looking for `$0: Eq` where `$0` is some
351        // unconstrained type variable. In that case, we'll get a
352        // candidate which assumes $0 == int, one that assumes `$0 ==
353        // usize`, etc. This spells an ambiguity.
354
355        let mut candidates = self.filter_impls(candidates, stack.obligation);
356
357        // If there is more than one candidate, first winnow them down
358        // by considering extra conditions (nested obligations and so
359        // forth). We don't winnow if there is exactly one
360        // candidate. This is a relatively minor distinction but it
361        // can lead to better inference and error-reporting. An
362        // example would be if there was an impl:
363        //
364        //     impl<T:Clone> Vec<T> { fn push_clone(...) { ... } }
365        //
366        // and we were to see some code `foo.push_clone()` where `boo`
367        // is a `Vec<Bar>` and `Bar` does not implement `Clone`. If
368        // we were to winnow, we'd wind up with zero candidates.
369        // Instead, we select the right impl now but report "`Bar` does
370        // not implement `Clone`".
371        if candidates.len() == 1 {
372            return Ok(candidates.pop());
373        }
374
375        // Winnow, but record the exact outcome of evaluation, which
376        // is needed for specialization. Propagate overflow if it occurs.
377        let candidates = candidates
378            .into_iter()
379            .map(|c| match self.evaluate_candidate(stack, &c) {
380                Ok(eval) if eval.may_apply() => {
381                    Ok(Some(EvaluatedCandidate { candidate: c, evaluation: eval }))
382                }
383                Ok(_) => Ok(None),
384                Err(OverflowError::Canonical) => {
385                    Err(SelectionError::Overflow(OverflowError::Canonical))
386                }
387                Err(OverflowError::Error(e)) => {
388                    Err(SelectionError::Overflow(OverflowError::Error(e)))
389                }
390            })
391            .flat_map(Result::transpose)
392            .collect::<Result<Vec<_>, _>>()?;
393
394        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:394",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(394u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("stack")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("stack");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("candidates")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("candidates");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0} potentially applicable candidates",
                                                    candidates.len()) as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&stack)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidates)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?stack, ?candidates, "{} potentially applicable candidates", candidates.len());
395        // If there are *NO* candidates, then there are no impls --
396        // that we know of, anyway. Note that in the case where there
397        // are unbound type variables within the obligation, it might
398        // be the case that you could still satisfy the obligation
399        // from another crate by instantiating the type variables with
400        // a type from another crate that does have an impl. This case
401        // is checked for in `evaluate_stack` (and hence users
402        // who might care about this case, like coherence, should use
403        // that function).
404        if candidates.is_empty() {
405            // If there's an error type, 'downgrade' our result from
406            // `Err(Unimplemented)` to `Ok(None)`. This helps us avoid
407            // emitting additional spurious errors, since we're guaranteed
408            // to have emitted at least one.
409            if stack.obligation.predicate.references_error() {
410                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:410",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(410u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("stack.obligation.predicate")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("stack.obligation.predicate");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("found error type in predicate, treating as ambiguous")
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&stack.obligation.predicate)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?stack.obligation.predicate, "found error type in predicate, treating as ambiguous");
411                Ok(None)
412            } else {
413                Err(SelectionError::Unimplemented)
414            }
415        } else {
416            let has_non_region_infer = stack.obligation.predicate.has_non_region_infer();
417            let candidate_preference_mode =
418                CandidatePreferenceMode::compute(self.tcx(), stack.obligation.predicate.def_id());
419            Ok(self.winnow_candidates(has_non_region_infer, candidate_preference_mode, candidates))
420        }
421    }
422
423    ///////////////////////////////////////////////////////////////////////////
424    // EVALUATION
425    //
426    // Tests whether an obligation can be selected or whether an impl
427    // can be applied to particular types. It skips the "confirmation"
428    // step and hence completely ignores output type parameters.
429    //
430    // The result is "true" if the obligation *may* hold and "false" if
431    // we can be sure it does not.
432
433    /// Evaluates whether the obligation `obligation` can be satisfied
434    /// and returns an `EvaluationResult`. This is meant for the
435    /// *initial* call.
436    ///
437    /// Do not use this directly, use `infcx.evaluate_obligation` instead.
438    pub fn evaluate_root_obligation(
439        &mut self,
440        obligation: &PredicateObligation<'tcx>,
441    ) -> Result<EvaluationResult, OverflowError> {
442        if true {
    if !!self.infcx.next_trait_solver() {
        ::core::panicking::panic("assertion failed: !self.infcx.next_trait_solver()")
    };
};debug_assert!(!self.infcx.next_trait_solver());
443        self.evaluation_probe(|this| {
444            let goal = this
445                .infcx
446                .deeply_resolve_ignoring_regions((obligation.predicate, obligation.param_env));
447            let mut result = this.evaluate_predicate_recursively(
448                TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
449                obligation.clone(),
450            )?;
451            // If the predicate has done any inference, then downgrade the
452            // result to ambiguous.
453            if this.infcx.deeply_resolve_ignoring_regions(goal) != goal {
454                result = result.max(EvaluatedToAmbig);
455            }
456            Ok(result)
457        })
458    }
459
460    /// Computes the evaluation result of `op`, discarding any constraints.
461    ///
462    /// This also runs for leak check to allow higher ranked region errors to impact
463    /// selection. By default it checks for leaks from all universes created inside of
464    /// `op`, but this can be overwritten if necessary.
465    fn evaluation_probe(
466        &mut self,
467        op: impl FnOnce(&mut Self) -> Result<EvaluationResult, OverflowError>,
468    ) -> Result<EvaluationResult, OverflowError> {
469        self.infcx.probe(|snapshot| -> Result<EvaluationResult, OverflowError> {
470            let outer_universe = self.infcx.universe();
471            let result = op(self)?;
472
473            match self.infcx.leak_check(outer_universe, Some(snapshot)) {
474                Ok(()) => {}
475                Err(_) => return Ok(EvaluatedToErr),
476            }
477
478            if self.infcx.opaque_types_added_in_snapshot(snapshot) {
479                return Ok(result.max(EvaluatedToOkModuloOpaqueTypes));
480            }
481
482            if self.infcx.region_constraints_added_in_snapshot(snapshot) {
483                Ok(result.max(EvaluatedToOkModuloRegions))
484            } else {
485                Ok(result)
486            }
487        })
488    }
489
490    /// Evaluates the predicates in `predicates` recursively. This may
491    /// guide inference. If this is not desired, run it inside of a
492    /// is run within an inference probe.
493    /// `probe`.
494    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("evaluate_predicates_recursively",
                                    "rustc_trait_selection::traits::select",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(494u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("predicates")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("predicates");
                                                        NAME.as_str()
                                                    }], ::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};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&predicates)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return:
                    Result<EvaluationResult, OverflowError> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let mut result = EvaluatedToOk;
            for mut obligation in predicates {
                obligation.set_depth_from_parent(stack.depth());
                let eval =
                    self.evaluate_predicate_recursively(stack, obligation)?;
                if let EvaluatedToErr = eval {
                    return Ok(EvaluatedToErr);
                } else { result = cmp::max(result, eval); }
            }
            Ok(result)
        }
    }
}#[instrument(skip(self, stack), level = "debug")]
495    fn evaluate_predicates_recursively<'o, I>(
496        &mut self,
497        stack: TraitObligationStackList<'o, 'tcx>,
498        predicates: I,
499    ) -> Result<EvaluationResult, OverflowError>
500    where
501        I: IntoIterator<Item = PredicateObligation<'tcx>> + std::fmt::Debug,
502    {
503        let mut result = EvaluatedToOk;
504        for mut obligation in predicates {
505            obligation.set_depth_from_parent(stack.depth());
506            let eval = self.evaluate_predicate_recursively(stack, obligation)?;
507            if let EvaluatedToErr = eval {
508                // fast-path - EvaluatedToErr is the top of the lattice,
509                // so we don't need to look on the other predicates.
510                return Ok(EvaluatedToErr);
511            } else {
512                result = cmp::max(result, eval);
513            }
514        }
515        Ok(result)
516    }
517
518    {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("evaluate_predicate_recursively",
                                "rustc_trait_selection::traits::select",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(518u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("obligation")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("obligation");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("previous_stack")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("previous_stack");
                                                    NAME.as_str()
                                                }], ::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};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&previous_stack.head())
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return:
                                Result<EvaluationResult, OverflowError> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if true {
                            if !!self.infcx.next_trait_solver() {
                                ::core::panicking::panic("assertion failed: !self.infcx.next_trait_solver()")
                            };
                        };
                        match previous_stack.head() {
                            Some(h) =>
                                self.check_recursion_limit(&obligation, h.obligation)?,
                            None =>
                                self.check_recursion_limit(&obligation, &obligation)?,
                        }
                        if !self.infcx.disable_trait_solver_fast_paths() &&
                                sizedness_fast_path(self.tcx(), obligation.predicate,
                                    obligation.param_env) {
                            return Ok(EvaluatedToOk);
                        }
                        let bound_predicate = obligation.predicate.kind();
                        match bound_predicate.skip_binder() {
                            ty::PredicateKind::Clause(ty::ClauseKind::Trait(t)) => {
                                let t = bound_predicate.rebind(t);
                                if true {
                                    if !!t.has_escaping_bound_vars() {
                                        ::core::panicking::panic("assertion failed: !t.has_escaping_bound_vars()")
                                    };
                                };
                                let obligation = obligation.with(self.tcx(), t);
                                self.evaluate_trait_predicate_recursively(previous_stack,
                                    obligation)
                            }
                            ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(data))
                                => {
                                self.infcx.enter_forall(bound_predicate.rebind(data),
                                    |data|
                                        {
                                            match effects::evaluate_host_effect_obligation(self,
                                                    &obligation.with(self.tcx(), data)) {
                                                Ok(nested) =>
                                                    self.evaluate_predicates_recursively(previous_stack,
                                                        nested),
                                                Err(effects::EvaluationFailure::Ambiguous) =>
                                                    Ok(EvaluatedToAmbig),
                                                Err(effects::EvaluationFailure::NoSolution) =>
                                                    Ok(EvaluatedToErr),
                                            }
                                        })
                            }
                            ty::PredicateKind::Subtype(p) => {
                                let p = bound_predicate.rebind(p);
                                match self.infcx.subtype_predicate(&obligation.cause,
                                        obligation.param_env, p) {
                                    Ok(Ok(InferOk { obligations, .. })) => {
                                        self.evaluate_predicates_recursively(previous_stack,
                                            obligations)
                                    }
                                    Ok(Err(_)) => Ok(EvaluatedToErr),
                                    Err(..) => Ok(EvaluatedToAmbig),
                                }
                            }
                            ty::PredicateKind::Coerce(p) => {
                                let p = bound_predicate.rebind(p);
                                match self.infcx.coerce_predicate(&obligation.cause,
                                        obligation.param_env, p) {
                                    Ok(Ok(InferOk { obligations, .. })) => {
                                        self.evaluate_predicates_recursively(previous_stack,
                                            obligations)
                                    }
                                    Ok(Err(_)) => Ok(EvaluatedToErr),
                                    Err(..) => Ok(EvaluatedToAmbig),
                                }
                            }
                            ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term))
                                => {
                                if term.is_trivially_wf(self.tcx()) {
                                    return Ok(EvaluatedToOk);
                                }
                                let cache = previous_stack.cache;
                                let dfn = cache.next_dfn();
                                for stack_term in
                                    previous_stack.cache.wf_args.borrow().iter().rev() {
                                    if stack_term.0 != term { continue; }
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:623",
                                                            "rustc_trait_selection::traits::select",
                                                            ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(623u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                            ::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};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("WellFormed({0:?}) on stack",
                                                                                        term) as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    if let Some(stack) = previous_stack.head {
                                        let cycle =
                                            stack.iter().take_while(|s| s.depth > stack_term.1);
                                        let tcx = self.tcx();
                                        let cycle =
                                            cycle.map(|stack| stack.obligation.predicate.upcast(tcx));
                                        if self.coinductive_match(cycle) {
                                            stack.update_reached_depth(stack_term.1);
                                            return Ok(EvaluatedToOk);
                                        } else { return Ok(EvaluatedToAmbigStackDependent); }
                                    }
                                    return Ok(EvaluatedToOk);
                                }
                                match wf::obligations(self.infcx, obligation.param_env,
                                        obligation.cause.body_def_id,
                                        obligation.recursion_depth + 1, term, obligation.cause.span)
                                    {
                                    Some(obligations) => {
                                        cache.wf_args.borrow_mut().push((term,
                                                previous_stack.depth()));
                                        let result =
                                            self.evaluate_predicates_recursively(previous_stack,
                                                obligations);
                                        cache.wf_args.borrow_mut().pop();
                                        let result = result?;
                                        if !result.must_apply_modulo_regions() {
                                            cache.on_failure(dfn);
                                        }
                                        cache.on_completion(dfn);
                                        Ok(result)
                                    }
                                    None => Ok(EvaluatedToAmbig),
                                }
                            }
                            ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(pred))
                                => {
                                if pred.0.has_free_regions() || pred.0.has_bound_regions()
                                            || pred.0.has_non_region_infer() ||
                                        pred.0.has_non_region_param() {
                                    Ok(EvaluatedToOkModuloRegions)
                                } else { Ok(EvaluatedToOk) }
                            }
                            ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..))
                                => {
                                Ok(EvaluatedToOkModuloRegions)
                            }
                            ty::PredicateKind::DynCompatible(trait_def_id) => {
                                if self.tcx().is_dyn_compatible(trait_def_id) {
                                    Ok(EvaluatedToOk)
                                } else { Ok(EvaluatedToErr) }
                            }
                            ty::PredicateKind::Clause(ty::ClauseKind::Projection(data))
                                => {
                                let data = bound_predicate.rebind(data);
                                let project_obligation = obligation.with(self.tcx(), data);
                                match project::poly_project_and_unify_term(self,
                                        &project_obligation) {
                                    ProjectAndUnifyResult::Holds(mut subobligations) => {
                                        'compute_res:
                                            {
                                            if let Some(key) =
                                                        ProjectionCacheKey::from_poly_projection_obligation(self,
                                                            &project_obligation) &&
                                                    let Some(cached_res) =
                                                        self.infcx.inner.borrow_mut().projection_cache().is_complete(key)
                                                {
                                                break 'compute_res Ok(cached_res);
                                            }
                                            for subobligation in subobligations.iter_mut() {
                                                subobligation.set_depth_from_parent(obligation.recursion_depth);
                                            }
                                            let res =
                                                self.evaluate_predicates_recursively(previous_stack,
                                                    subobligations);
                                            if let Ok(eval_rslt) = res &&
                                                        (eval_rslt == EvaluatedToOk ||
                                                                eval_rslt == EvaluatedToOkModuloRegions) &&
                                                    let Some(key) =
                                                        ProjectionCacheKey::from_poly_projection_obligation(self,
                                                            &project_obligation) {
                                                self.infcx.inner.borrow_mut().projection_cache().complete(key,
                                                    eval_rslt);
                                            }
                                            res
                                        }
                                    }
                                    ProjectAndUnifyResult::FailedNormalization =>
                                        Ok(EvaluatedToAmbig),
                                    ProjectAndUnifyResult::Recursive =>
                                        Ok(EvaluatedToAmbigStackDependent),
                                    ProjectAndUnifyResult::MismatchedProjectionTypes(_) =>
                                        Ok(EvaluatedToErr),
                                }
                            }
                            ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol))
                                => {
                                if may_use_unstable_feature(self.infcx,
                                        obligation.param_env, symbol) {
                                    Ok(EvaluatedToOk)
                                } else { Ok(EvaluatedToAmbig) }
                            }
                            ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const))
                                => {
                                match const_evaluatable::is_const_evaluatable(self.infcx,
                                        alias_const, obligation.param_env, obligation.cause.span) {
                                    Ok(()) => Ok(EvaluatedToOk),
                                    Err(NotConstEvaluatable::MentionsInfer) =>
                                        Ok(EvaluatedToAmbig),
                                    Err(NotConstEvaluatable::MentionsParam) =>
                                        Ok(EvaluatedToErr),
                                    Err(_) => Ok(EvaluatedToErr),
                                }
                            }
                            ty::PredicateKind::ConstEquate(c1, c2) => {
                                let tcx = self.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 /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:800",
                                                            "rustc_trait_selection::traits::select",
                                                            ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(800u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                            ::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};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("evaluate_predicate_recursively: equating consts:\nc1= {0:?}\nc2= {1:?}",
                                                                                        c1, c2) as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    match (c1.kind(), c2.kind()) {
                                        (ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b)) if
                                            a.kind == b.kind &&
                                                #[allow(non_exhaustive_omitted_patterns)] match a.kind {
                                                    ty::AliasConstKind::Projection { .. } |
                                                        ty::AliasConstKind::InherentSelf { .. } |
                                                        ty::AliasConstKind::InherentImpl { .. } => true,
                                                    _ => false,
                                                } => {
                                            if let Ok(InferOk { obligations, value: () }) =
                                                    self.infcx.at(&obligation.cause,
                                                            obligation.param_env).eq(DefineOpaqueTypes::Yes,
                                                        ty::AliasTerm::from(a), ty::AliasTerm::from(b)) {
                                                return self.evaluate_predicates_recursively(previous_stack,
                                                        obligations);
                                            }
                                        }
                                        (_, ty::ConstKind::Alias(_, _)) |
                                            (ty::ConstKind::Alias(_, _), _) => (),
                                        (_, _) => {
                                            if let Ok(InferOk { obligations, value: () }) =
                                                    self.infcx.at(&obligation.cause,
                                                            obligation.param_env).eq(DefineOpaqueTypes::Yes, c1, c2) {
                                                return self.evaluate_predicates_recursively(previous_stack,
                                                        obligations);
                                            }
                                        }
                                    }
                                }
                                let evaluate =
                                    |c: ty::Const<'tcx>|
                                        {
                                            if let ty::ConstKind::Alias(_, _) = c.kind() {
                                                crate::traits::try_evaluate_const(self.infcx, c,
                                                    obligation.param_env, |v| Ok::<_, !>(v.skip_norm_wip()))
                                            } else { Ok(c) }
                                        };
                                match (evaluate(c1), evaluate(c2)) {
                                    (Ok(c1), Ok(c2)) => {
                                        match self.infcx.at(&obligation.cause,
                                                    obligation.param_env).eq(DefineOpaqueTypes::Yes, c1, c2) {
                                            Ok(inf_ok) =>
                                                self.evaluate_predicates_recursively(previous_stack,
                                                    inf_ok.into_obligations()),
                                            Err(_) => Ok(EvaluatedToErr),
                                        }
                                    }
                                    (Err(EvaluateConstErr::InvalidConstParamTy(..)), _) |
                                        (_, Err(EvaluateConstErr::InvalidConstParamTy(..))) =>
                                        Ok(EvaluatedToErr),
                                    (Err(EvaluateConstErr::EvaluationFailure(..)), _) |
                                        (_, Err(EvaluateConstErr::EvaluationFailure(..))) =>
                                        Ok(EvaluatedToErr),
                                    (Err(EvaluateConstErr::HasGenericsOrInfers), _) |
                                        (_, Err(EvaluateConstErr::HasGenericsOrInfers)) => {
                                        if c1.has_non_region_infer() || c2.has_non_region_infer() {
                                            Ok(EvaluatedToAmbig)
                                        } else { Ok(EvaluatedToErr) }
                                    }
                                }
                            }
                            ty::PredicateKind::NormalizesTo(..) => {
                                ::rustc_span::macros::bug_impl(None,
                                    format_args!("NormalizesTo is only used by the new solver"),
                                    Location::caller())
                            }
                            ty::PredicateKind::Ambiguous => Ok(EvaluatedToAmbig),
                            ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct,
                                ty)) => {
                                let ct = self.infcx.shallow_resolve_const(ct);
                                let ct_ty =
                                    match ct.kind() {
                                        ty::ConstKind::Infer(_) => { return Ok(EvaluatedToAmbig); }
                                        ty::ConstKind::Error(_) => return Ok(EvaluatedToOk),
                                        ty::ConstKind::Value(cv) => cv.ty,
                                        ty::ConstKind::Alias(_, alias_const) => {
                                            alias_const.type_of(self.tcx()).skip_norm_wip()
                                        }
                                        ty::ConstKind::Expr(_) => return Ok(EvaluatedToOk),
                                        ty::ConstKind::Placeholder(_) => {
                                            ::rustc_span::macros::bug_impl(None,
                                                format_args!("placeholder const {0:?} in old solver", ct),
                                                Location::caller())
                                        }
                                        ty::ConstKind::Bound(_, _) =>
                                            ::rustc_span::macros::bug_impl(None,
                                                format_args!("escaping bound vars in {0:?}", ct),
                                                Location::caller()),
                                        ty::ConstKind::Param(param_ct) => {
                                            param_ct.find_const_ty_from_env(obligation.param_env)
                                        }
                                    };
                                match self.infcx.at(&obligation.cause,
                                            obligation.param_env).eq(DefineOpaqueTypes::Yes, ct_ty, ty)
                                    {
                                    Ok(inf_ok) =>
                                        self.evaluate_predicates_recursively(previous_stack,
                                            inf_ok.into_obligations()),
                                    Err(_) => Ok(EvaluatedToErr),
                                }
                            }
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:518",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(518u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(
519        level = "debug",
520        skip(self, previous_stack),
521        fields(previous_stack = ?previous_stack.head())
522        ret,
523    )]
524    fn evaluate_predicate_recursively<'o>(
525        &mut self,
526        previous_stack: TraitObligationStackList<'o, 'tcx>,
527        obligation: PredicateObligation<'tcx>,
528    ) -> Result<EvaluationResult, OverflowError> {
529        debug_assert!(!self.infcx.next_trait_solver());
530        // `previous_stack` stores a `PolyTraitObligation`, while `obligation` is
531        // a `PredicateObligation`. These are distinct types, so we can't
532        // use any `Option` combinator method that would force them to be
533        // the same.
534        match previous_stack.head() {
535            Some(h) => self.check_recursion_limit(&obligation, h.obligation)?,
536            None => self.check_recursion_limit(&obligation, &obligation)?,
537        }
538
539        if !self.infcx.disable_trait_solver_fast_paths()
540            && sizedness_fast_path(self.tcx(), obligation.predicate, obligation.param_env)
541        {
542            return Ok(EvaluatedToOk);
543        }
544
545        let bound_predicate = obligation.predicate.kind();
546        match bound_predicate.skip_binder() {
547            ty::PredicateKind::Clause(ty::ClauseKind::Trait(t)) => {
548                let t = bound_predicate.rebind(t);
549                debug_assert!(!t.has_escaping_bound_vars());
550                let obligation = obligation.with(self.tcx(), t);
551                self.evaluate_trait_predicate_recursively(previous_stack, obligation)
552            }
553
554            ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(data)) => {
555                self.infcx.enter_forall(bound_predicate.rebind(data), |data| {
556                    match effects::evaluate_host_effect_obligation(
557                        self,
558                        &obligation.with(self.tcx(), data),
559                    ) {
560                        Ok(nested) => self.evaluate_predicates_recursively(previous_stack, nested),
561                        Err(effects::EvaluationFailure::Ambiguous) => Ok(EvaluatedToAmbig),
562                        Err(effects::EvaluationFailure::NoSolution) => Ok(EvaluatedToErr),
563                    }
564                })
565            }
566
567            ty::PredicateKind::Subtype(p) => {
568                let p = bound_predicate.rebind(p);
569                // Does this code ever run?
570                match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) {
571                    Ok(Ok(InferOk { obligations, .. })) => {
572                        self.evaluate_predicates_recursively(previous_stack, obligations)
573                    }
574                    Ok(Err(_)) => Ok(EvaluatedToErr),
575                    Err(..) => Ok(EvaluatedToAmbig),
576                }
577            }
578
579            ty::PredicateKind::Coerce(p) => {
580                let p = bound_predicate.rebind(p);
581                // Does this code ever run?
582                match self.infcx.coerce_predicate(&obligation.cause, obligation.param_env, p) {
583                    Ok(Ok(InferOk { obligations, .. })) => {
584                        self.evaluate_predicates_recursively(previous_stack, obligations)
585                    }
586                    Ok(Err(_)) => Ok(EvaluatedToErr),
587                    Err(..) => Ok(EvaluatedToAmbig),
588                }
589            }
590
591            ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => {
592                if term.is_trivially_wf(self.tcx()) {
593                    return Ok(EvaluatedToOk);
594                }
595
596                // So, there is a bit going on here. First, `WellFormed` predicates
597                // are coinductive, like trait predicates with auto traits.
598                // This means that we need to detect if we have recursively
599                // evaluated `WellFormed(X)`. Otherwise, we would run into
600                // a "natural" overflow error.
601                //
602                // Now, the next question is whether we need to do anything
603                // special with caching. Considering the following tree:
604                // - `WF(Foo<T>)`
605                //   - `Bar<T>: Send`
606                //     - `WF(Foo<T>)`
607                //   - `Foo<T>: Trait`
608                // In this case, the innermost `WF(Foo<T>)` should return
609                // `EvaluatedToOk`, since it's coinductive. Then if
610                // `Bar<T>: Send` is resolved to `EvaluatedToOk`, it can be
611                // inserted into a cache (because without thinking about `WF`
612                // goals, it isn't in a cycle). If `Foo<T>: Trait` later doesn't
613                // hold, then `Bar<T>: Send` shouldn't hold. Therefore, we
614                // *do* need to keep track of coinductive cycles.
615
616                let cache = previous_stack.cache;
617                let dfn = cache.next_dfn();
618
619                for stack_term in previous_stack.cache.wf_args.borrow().iter().rev() {
620                    if stack_term.0 != term {
621                        continue;
622                    }
623                    debug!("WellFormed({:?}) on stack", term);
624                    if let Some(stack) = previous_stack.head {
625                        // Okay, let's imagine we have two different stacks:
626                        //   `T: NonAutoTrait -> WF(T) -> T: NonAutoTrait`
627                        //   `WF(T) -> T: NonAutoTrait -> WF(T)`
628                        // Because of this, we need to check that all
629                        // predicates between the WF goals are coinductive.
630                        // Otherwise, we can say that `T: NonAutoTrait` is
631                        // true.
632                        // Let's imagine we have a predicate stack like
633                        //         `Foo: Bar -> WF(T) -> T: NonAutoTrait -> T: Auto`
634                        // depth   ^1                    ^2                 ^3
635                        // and the current predicate is `WF(T)`. `wf_args`
636                        // would contain `(T, 1)`. We want to check all
637                        // trait predicates greater than `1`. The previous
638                        // stack would be `T: Auto`.
639                        let cycle = stack.iter().take_while(|s| s.depth > stack_term.1);
640                        let tcx = self.tcx();
641                        let cycle = cycle.map(|stack| stack.obligation.predicate.upcast(tcx));
642                        if self.coinductive_match(cycle) {
643                            stack.update_reached_depth(stack_term.1);
644                            return Ok(EvaluatedToOk);
645                        } else {
646                            return Ok(EvaluatedToAmbigStackDependent);
647                        }
648                    }
649                    return Ok(EvaluatedToOk);
650                }
651
652                match wf::obligations(
653                    self.infcx,
654                    obligation.param_env,
655                    obligation.cause.body_def_id,
656                    obligation.recursion_depth + 1,
657                    term,
658                    obligation.cause.span,
659                ) {
660                    Some(obligations) => {
661                        cache.wf_args.borrow_mut().push((term, previous_stack.depth()));
662                        let result =
663                            self.evaluate_predicates_recursively(previous_stack, obligations);
664                        cache.wf_args.borrow_mut().pop();
665
666                        let result = result?;
667
668                        if !result.must_apply_modulo_regions() {
669                            cache.on_failure(dfn);
670                        }
671
672                        cache.on_completion(dfn);
673
674                        Ok(result)
675                    }
676                    None => Ok(EvaluatedToAmbig),
677                }
678            }
679
680            ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(pred)) => {
681                // A global type with no free lifetimes or generic parameters
682                // outlives anything.
683                if pred.0.has_free_regions()
684                    || pred.0.has_bound_regions()
685                    || pred.0.has_non_region_infer()
686                    || pred.0.has_non_region_param()
687                {
688                    Ok(EvaluatedToOkModuloRegions)
689                } else {
690                    Ok(EvaluatedToOk)
691                }
692            }
693
694            ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..)) => {
695                // We do not consider region relationships when evaluating trait matches.
696                Ok(EvaluatedToOkModuloRegions)
697            }
698
699            ty::PredicateKind::DynCompatible(trait_def_id) => {
700                // `DynCompatible` obligations are only emitted as
701                // nested obligations of `WellFormed` goals. It is quite
702                // rare, but possible, that we encounter them during
703                // evaluation. See #158665 for more details here.
704                if self.tcx().is_dyn_compatible(trait_def_id) {
705                    Ok(EvaluatedToOk)
706                } else {
707                    Ok(EvaluatedToErr)
708                }
709            }
710
711            ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
712                let data = bound_predicate.rebind(data);
713                let project_obligation = obligation.with(self.tcx(), data);
714                match project::poly_project_and_unify_term(self, &project_obligation) {
715                    ProjectAndUnifyResult::Holds(mut subobligations) => {
716                        'compute_res: {
717                            // If we've previously marked this projection as 'complete', then
718                            // use the final cached result (either `EvaluatedToOk` or
719                            // `EvaluatedToOkModuloRegions`), and skip re-evaluating the
720                            // sub-obligations.
721                            if let Some(key) = ProjectionCacheKey::from_poly_projection_obligation(
722                                self,
723                                &project_obligation,
724                            ) && let Some(cached_res) =
725                                self.infcx.inner.borrow_mut().projection_cache().is_complete(key)
726                            {
727                                break 'compute_res Ok(cached_res);
728                            }
729
730                            // Need to explicitly set the depth of nested goals here as
731                            // projection obligations can cycle by themselves and in
732                            // `evaluate_predicates_recursively` we only add the depth
733                            // for parent trait goals because only these get added to the
734                            // `TraitObligationStackList`.
735                            for subobligation in subobligations.iter_mut() {
736                                subobligation.set_depth_from_parent(obligation.recursion_depth);
737                            }
738                            let res = self
739                                .evaluate_predicates_recursively(previous_stack, subobligations);
740                            if let Ok(eval_rslt) = res
741                                && (eval_rslt == EvaluatedToOk
742                                    || eval_rslt == EvaluatedToOkModuloRegions)
743                                && let Some(key) =
744                                    ProjectionCacheKey::from_poly_projection_obligation(
745                                        self,
746                                        &project_obligation,
747                                    )
748                            {
749                                // If the result is something that we can cache, then mark this
750                                // entry as 'complete'. This will allow us to skip evaluating the
751                                // subobligations at all the next time we evaluate the projection
752                                // predicate.
753                                self.infcx
754                                    .inner
755                                    .borrow_mut()
756                                    .projection_cache()
757                                    .complete(key, eval_rslt);
758                            }
759                            res
760                        }
761                    }
762                    ProjectAndUnifyResult::FailedNormalization => Ok(EvaluatedToAmbig),
763                    ProjectAndUnifyResult::Recursive => Ok(EvaluatedToAmbigStackDependent),
764                    ProjectAndUnifyResult::MismatchedProjectionTypes(_) => Ok(EvaluatedToErr),
765                }
766            }
767
768            ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
769                if may_use_unstable_feature(self.infcx, obligation.param_env, symbol) {
770                    Ok(EvaluatedToOk)
771                } else {
772                    Ok(EvaluatedToAmbig)
773                }
774            }
775
776            ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => {
777                match const_evaluatable::is_const_evaluatable(
778                    self.infcx,
779                    alias_const,
780                    obligation.param_env,
781                    obligation.cause.span,
782                ) {
783                    Ok(()) => Ok(EvaluatedToOk),
784                    Err(NotConstEvaluatable::MentionsInfer) => Ok(EvaluatedToAmbig),
785                    Err(NotConstEvaluatable::MentionsParam) => Ok(EvaluatedToErr),
786                    Err(_) => Ok(EvaluatedToErr),
787                }
788            }
789
790            ty::PredicateKind::ConstEquate(c1, c2) => {
791                let tcx = self.tcx();
792                assert!(
793                    tcx.features().generic_const_exprs(),
794                    "`ConstEquate` without a feature gate: {c1:?} {c2:?}",
795                );
796
797                {
798                    let c1 = tcx.expand_abstract_consts(c1);
799                    let c2 = tcx.expand_abstract_consts(c2);
800                    debug!(
801                        "evaluate_predicate_recursively: equating consts:\nc1= {:?}\nc2= {:?}",
802                        c1, c2
803                    );
804
805                    match (c1.kind(), c2.kind()) {
806                        (ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b))
807                            if a.kind == b.kind
808                                && matches!(
809                                    a.kind,
810                                    ty::AliasConstKind::Projection { .. }
811                                        | ty::AliasConstKind::InherentSelf { .. }
812                                        | ty::AliasConstKind::InherentImpl { .. }
813                                ) =>
814                        {
815                            if let Ok(InferOk { obligations, value: () }) = self
816                                .infcx
817                                .at(&obligation.cause, obligation.param_env)
818                                // Can define opaque types as this is only reachable with
819                                // `generic_const_exprs`
820                                .eq(
821                                    DefineOpaqueTypes::Yes,
822                                    ty::AliasTerm::from(a),
823                                    ty::AliasTerm::from(b),
824                                )
825                            {
826                                return self
827                                    .evaluate_predicates_recursively(previous_stack, obligations);
828                            }
829                        }
830                        (_, ty::ConstKind::Alias(_, _)) | (ty::ConstKind::Alias(_, _), _) => (),
831                        (_, _) => {
832                            if let Ok(InferOk { obligations, value: () }) = self
833                                .infcx
834                                .at(&obligation.cause, obligation.param_env)
835                                // Can define opaque types as this is only reachable with
836                                // `generic_const_exprs`
837                                .eq(DefineOpaqueTypes::Yes, c1, c2)
838                            {
839                                return self
840                                    .evaluate_predicates_recursively(previous_stack, obligations);
841                            }
842                        }
843                    }
844                }
845
846                let evaluate = |c: ty::Const<'tcx>| {
847                    if let ty::ConstKind::Alias(_, _) = c.kind() {
848                        crate::traits::try_evaluate_const(
849                            self.infcx,
850                            c,
851                            obligation.param_env,
852                            |v| Ok::<_, !>(v.skip_norm_wip()),
853                        )
854                    } else {
855                        Ok(c)
856                    }
857                };
858
859                match (evaluate(c1), evaluate(c2)) {
860                    (Ok(c1), Ok(c2)) => {
861                        match self.infcx.at(&obligation.cause, obligation.param_env).eq(
862                            // Can define opaque types as this is only reachable with
863                            // `generic_const_exprs`
864                            DefineOpaqueTypes::Yes,
865                            c1,
866                            c2,
867                        ) {
868                            Ok(inf_ok) => self.evaluate_predicates_recursively(
869                                previous_stack,
870                                inf_ok.into_obligations(),
871                            ),
872                            Err(_) => Ok(EvaluatedToErr),
873                        }
874                    }
875                    (Err(EvaluateConstErr::InvalidConstParamTy(..)), _)
876                    | (_, Err(EvaluateConstErr::InvalidConstParamTy(..))) => Ok(EvaluatedToErr),
877                    (Err(EvaluateConstErr::EvaluationFailure(..)), _)
878                    | (_, Err(EvaluateConstErr::EvaluationFailure(..))) => Ok(EvaluatedToErr),
879                    (Err(EvaluateConstErr::HasGenericsOrInfers), _)
880                    | (_, Err(EvaluateConstErr::HasGenericsOrInfers)) => {
881                        if c1.has_non_region_infer() || c2.has_non_region_infer() {
882                            Ok(EvaluatedToAmbig)
883                        } else {
884                            // Two different constants using generic parameters ~> error.
885                            Ok(EvaluatedToErr)
886                        }
887                    }
888                }
889            }
890            ty::PredicateKind::NormalizesTo(..) => {
891                bug!("NormalizesTo is only used by the new solver")
892            }
893            ty::PredicateKind::Ambiguous => Ok(EvaluatedToAmbig),
894            ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
895                let ct = self.infcx.shallow_resolve_const(ct);
896                let ct_ty = match ct.kind() {
897                    ty::ConstKind::Infer(_) => {
898                        return Ok(EvaluatedToAmbig);
899                    }
900                    ty::ConstKind::Error(_) => return Ok(EvaluatedToOk),
901                    ty::ConstKind::Value(cv) => cv.ty,
902                    ty::ConstKind::Alias(_, alias_const) => {
903                        alias_const.type_of(self.tcx()).skip_norm_wip()
904                    }
905                    // FIXME(generic_const_exprs): See comment in `fulfill.rs`
906                    ty::ConstKind::Expr(_) => return Ok(EvaluatedToOk),
907                    ty::ConstKind::Placeholder(_) => {
908                        bug!("placeholder const {:?} in old solver", ct)
909                    }
910                    ty::ConstKind::Bound(_, _) => bug!("escaping bound vars in {:?}", ct),
911                    ty::ConstKind::Param(param_ct) => {
912                        param_ct.find_const_ty_from_env(obligation.param_env)
913                    }
914                };
915
916                match self.infcx.at(&obligation.cause, obligation.param_env).eq(
917                    // Only really exercised by generic_const_exprs
918                    DefineOpaqueTypes::Yes,
919                    ct_ty,
920                    ty,
921                ) {
922                    Ok(inf_ok) => self
923                        .evaluate_predicates_recursively(previous_stack, inf_ok.into_obligations()),
924                    Err(_) => Ok(EvaluatedToErr),
925                }
926            }
927        }
928    }
929
930    {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("evaluate_trait_predicate_recursively",
                                "rustc_trait_selection::traits::select",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(930u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("obligation")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("obligation");
                                                    NAME.as_str()
                                                }], ::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};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return:
                                Result<EvaluationResult, OverflowError> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if true {
                            if !!self.typing_mode().is_coherence() {
                                {
                                    ::core::panicking::panic_fmt(format_args!("old solver coherence"));
                                }
                            };
                        };
                        if obligation.is_global() &&
                                obligation.param_env.caller_bounds().all(|bound|
                                        bound.has_param()) {
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:944",
                                                    "rustc_trait_selection::traits::select",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(944u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                    ::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};
                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("in global")
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            obligation.param_env = ty::ParamEnv::empty();
                        }
                        let stack = self.push_stack(previous_stack, &obligation);
                        let fresh_trait_pred = stack.fresh_trait_pred;
                        let param_env = obligation.param_env;
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:952",
                                                "rustc_trait_selection::traits::select",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(952u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("fresh_trait_pred")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("fresh_trait_pred");
                                                                    NAME.as_str()
                                                                }], ::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};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fresh_trait_pred)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        if let Some(result) =
                                self.check_evaluation_cache(param_env, fresh_trait_pred) {
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:957",
                                                    "rustc_trait_selection::traits::select",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(957u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                    ::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};
                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("CACHE HIT")
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            return Ok(result);
                        }
                        if let Some(result) =
                                stack.cache().get_provisional(fresh_trait_pred) {
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:962",
                                                    "rustc_trait_selection::traits::select",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(962u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                    ::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};
                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("PROVISIONAL CACHE HIT")
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            stack.update_reached_depth(result.reached_depth);
                            return Ok(result.result);
                        }
                        if let Some(cycle_result) =
                                self.check_evaluation_cycle(&stack) {
                            return Ok(cycle_result);
                        }
                        let (result, dep_node) =
                            self.in_task(|this|
                                    {
                                        let mut result = this.evaluate_stack(&stack)?;
                                        if EvaluationResult::EvaluatedToErr == result &&
                                                    fresh_trait_pred.has_aliases() &&
                                                fresh_trait_pred.is_global() {
                                            let mut nested_obligations = PredicateObligations::new();
                                            let predicate =
                                                normalize_with_depth_to(this, param_env,
                                                    obligation.cause.clone(), obligation.recursion_depth + 1,
                                                    Unnormalized::new_wip(obligation.predicate),
                                                    &mut nested_obligations);
                                            if predicate != obligation.predicate {
                                                let mut nested_result = EvaluationResult::EvaluatedToOk;
                                                for obligation in nested_obligations {
                                                    nested_result =
                                                        cmp::max(this.evaluate_predicate_recursively(previous_stack,
                                                                    obligation)?, nested_result);
                                                }
                                                if nested_result.must_apply_modulo_regions() {
                                                    let obligation = obligation.with(this.tcx(), predicate);
                                                    result =
                                                        cmp::max(nested_result,
                                                            this.evaluate_trait_predicate_recursively(previous_stack,
                                                                    obligation)?);
                                                }
                                            }
                                        }
                                        Ok::<_, OverflowError>(result)
                                    });
                        let result = result?;
                        if !result.must_apply_modulo_regions() {
                            stack.cache().on_failure(stack.dfn);
                        }
                        let reached_depth = stack.reached_depth.get();
                        if reached_depth >= stack.depth {
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1029",
                                                    "rustc_trait_selection::traits::select",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(1029u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                    ::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};
                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("CACHE MISS")
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            self.insert_evaluation_cache(param_env, fresh_trait_pred,
                                dep_node, result);
                            stack.cache().on_completion(stack.dfn);
                        } else if let Some(_guar) = self.infcx.tainted_by_errors() {
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1037",
                                                    "rustc_trait_selection::traits::select",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(1037u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                    ::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};
                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("CACHE MISS (tainted by errors)")
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            self.insert_evaluation_cache(param_env, fresh_trait_pred,
                                dep_node, result);
                            stack.cache().on_completion(stack.dfn);
                        } else {
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1041",
                                                    "rustc_trait_selection::traits::select",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(1041u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                    ::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};
                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("PROVISIONAL")
                                                                        as &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1042",
                                                    "rustc_trait_selection::traits::select",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(1042u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                    ::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};
                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("caching provisionally because {0:?} is a cycle participant (at depth {1}, reached depth {2})",
                                                                                fresh_trait_pred, stack.depth, reached_depth) as
                                                                        &dyn ::tracing::field::Value))])
                                        });
                                } else { ; }
                            };
                            stack.cache().insert_provisional(stack.dfn, reached_depth,
                                fresh_trait_pred, result);
                        }
                        Ok(result)
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:930",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(930u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(skip(self, previous_stack), level = "debug", ret)]
931    fn evaluate_trait_predicate_recursively<'o>(
932        &mut self,
933        previous_stack: TraitObligationStackList<'o, 'tcx>,
934        mut obligation: PolyTraitObligation<'tcx>,
935    ) -> Result<EvaluationResult, OverflowError> {
936        debug_assert!(!self.typing_mode().is_coherence(), "old solver coherence");
937
938        if obligation.is_global()
939            && obligation.param_env.caller_bounds().all(|bound| bound.has_param())
940        {
941            // If a param env has no global bounds, global obligations do not
942            // depend on its particular value in order to work, so we can clear
943            // out the param env and get better caching.
944            debug!("in global");
945            obligation.param_env = ty::ParamEnv::empty();
946        }
947
948        let stack = self.push_stack(previous_stack, &obligation);
949        let fresh_trait_pred = stack.fresh_trait_pred;
950        let param_env = obligation.param_env;
951
952        debug!(?fresh_trait_pred);
953
954        // If a trait predicate is in the (local or global) evaluation cache,
955        // then we know it holds without cycles.
956        if let Some(result) = self.check_evaluation_cache(param_env, fresh_trait_pred) {
957            debug!("CACHE HIT");
958            return Ok(result);
959        }
960
961        if let Some(result) = stack.cache().get_provisional(fresh_trait_pred) {
962            debug!("PROVISIONAL CACHE HIT");
963            stack.update_reached_depth(result.reached_depth);
964            return Ok(result.result);
965        }
966
967        // Check if this is a match for something already on the
968        // stack. If so, we don't want to insert the result into the
969        // main cache (it is cycle dependent) nor the provisional
970        // cache (which is meant for things that have completed but
971        // for a "backedge" -- this result *is* the backedge).
972        if let Some(cycle_result) = self.check_evaluation_cycle(&stack) {
973            return Ok(cycle_result);
974        }
975
976        let (result, dep_node) = self.in_task(|this| {
977            let mut result = this.evaluate_stack(&stack)?;
978
979            // fix issue #103563, we don't normalize
980            // nested obligations which produced by `TraitDef` candidate
981            // (i.e. using bounds on assoc items as assumptions).
982            // because we don't have enough information to
983            // normalize these obligations before evaluating.
984            // so we will try to normalize the obligation and evaluate again.
985            // we will replace it with new solver in the future.
986            if EvaluationResult::EvaluatedToErr == result
987                && fresh_trait_pred.has_aliases()
988                && fresh_trait_pred.is_global()
989            {
990                let mut nested_obligations = PredicateObligations::new();
991                let predicate = normalize_with_depth_to(
992                    this,
993                    param_env,
994                    obligation.cause.clone(),
995                    obligation.recursion_depth + 1,
996                    Unnormalized::new_wip(obligation.predicate),
997                    &mut nested_obligations,
998                );
999                if predicate != obligation.predicate {
1000                    let mut nested_result = EvaluationResult::EvaluatedToOk;
1001                    for obligation in nested_obligations {
1002                        nested_result = cmp::max(
1003                            this.evaluate_predicate_recursively(previous_stack, obligation)?,
1004                            nested_result,
1005                        );
1006                    }
1007
1008                    if nested_result.must_apply_modulo_regions() {
1009                        let obligation = obligation.with(this.tcx(), predicate);
1010                        result = cmp::max(
1011                            nested_result,
1012                            this.evaluate_trait_predicate_recursively(previous_stack, obligation)?,
1013                        );
1014                    }
1015                }
1016            }
1017
1018            Ok::<_, OverflowError>(result)
1019        });
1020
1021        let result = result?;
1022
1023        if !result.must_apply_modulo_regions() {
1024            stack.cache().on_failure(stack.dfn);
1025        }
1026
1027        let reached_depth = stack.reached_depth.get();
1028        if reached_depth >= stack.depth {
1029            debug!("CACHE MISS");
1030            self.insert_evaluation_cache(param_env, fresh_trait_pred, dep_node, result);
1031            stack.cache().on_completion(stack.dfn);
1032        } else if let Some(_guar) = self.infcx.tainted_by_errors() {
1033            // When an error has occurred, we allow global caching of results even if they
1034            // appear stack-dependent. This prevents exponential re-evaluation of cycles
1035            // in the presence of errors, avoiding compiler hangs like #150907.
1036            // This is safe because compilation will fail anyway.
1037            debug!("CACHE MISS (tainted by errors)");
1038            self.insert_evaluation_cache(param_env, fresh_trait_pred, dep_node, result);
1039            stack.cache().on_completion(stack.dfn);
1040        } else {
1041            debug!("PROVISIONAL");
1042            debug!(
1043                "caching provisionally because {:?} \
1044                 is a cycle participant (at depth {}, reached depth {})",
1045                fresh_trait_pred, stack.depth, reached_depth,
1046            );
1047
1048            stack.cache().insert_provisional(stack.dfn, reached_depth, fresh_trait_pred, result);
1049        }
1050
1051        Ok(result)
1052    }
1053
1054    /// If there is any previous entry on the stack that precisely
1055    /// matches this obligation, then we can assume that the
1056    /// obligation is satisfied for now (still all other conditions
1057    /// must be met of course). One obvious case this comes up is
1058    /// marker traits like `Send`. Think of a linked list:
1059    ///
1060    ///     struct List<T> { data: T, next: Option<Box<List<T>>> }
1061    ///
1062    /// `Box<List<T>>` will be `Send` if `T` is `Send` and
1063    /// `Option<Box<List<T>>>` is `Send`, and in turn
1064    /// `Option<Box<List<T>>>` is `Send` if `Box<List<T>>` is
1065    /// `Send`.
1066    ///
1067    /// Note that we do this comparison using the `fresh_trait_pred`
1068    /// fields. Because these have all been freshened using
1069    /// `self.freshener`, we can be sure that (a) this will not
1070    /// affect the inferencer state and (b) that if we see two
1071    /// fresh regions with the same index, they refer to the same
1072    /// unbound type variable.
1073    fn check_evaluation_cycle(
1074        &mut self,
1075        stack: &TraitObligationStack<'_, 'tcx>,
1076    ) -> Option<EvaluationResult> {
1077        if let Some(cycle_depth) = stack
1078            .iter()
1079            .skip(1) // Skip top-most frame.
1080            .find(|prev| {
1081                stack.obligation.param_env == prev.obligation.param_env
1082                    && stack.fresh_trait_pred == prev.fresh_trait_pred
1083            })
1084            .map(|stack| stack.depth)
1085        {
1086            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1086",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1086u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("evaluate_stack --> recursive at depth {0}",
                                                    cycle_depth) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("evaluate_stack --> recursive at depth {}", cycle_depth);
1087
1088            // If we have a stack like `A B C D E A`, where the top of
1089            // the stack is the final `A`, then this will iterate over
1090            // `A, E, D, C, B` -- i.e., all the participants apart
1091            // from the cycle head. We mark them as participating in a
1092            // cycle. This suppresses caching for those nodes. See
1093            // `in_cycle` field for more details.
1094            stack.update_reached_depth(cycle_depth);
1095
1096            // Subtle: when checking for a coinductive cycle, we do
1097            // not compare using the "freshened trait refs" (which
1098            // have erased regions) but rather the fully explicit
1099            // trait refs. This is important because it's only a cycle
1100            // if the regions match exactly.
1101            let cycle = stack.iter().skip(1).take_while(|s| s.depth >= cycle_depth);
1102            let tcx = self.tcx();
1103            let cycle = cycle.map(|stack| stack.obligation.predicate.upcast(tcx));
1104            if self.coinductive_match(cycle) {
1105                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1105",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1105u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("evaluate_stack --> recursive, coinductive")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("evaluate_stack --> recursive, coinductive");
1106                Some(EvaluatedToOk)
1107            } else {
1108                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1108",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1108u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("evaluate_stack --> recursive, inductive")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("evaluate_stack --> recursive, inductive");
1109                Some(EvaluatedToAmbigStackDependent)
1110            }
1111        } else {
1112            None
1113        }
1114    }
1115
1116    fn evaluate_stack<'o>(
1117        &mut self,
1118        stack: &TraitObligationStack<'o, 'tcx>,
1119    ) -> Result<EvaluationResult, OverflowError> {
1120        if true {
    if !!self.infcx.next_trait_solver() {
        ::core::panicking::panic("assertion failed: !self.infcx.next_trait_solver()")
    };
};debug_assert!(!self.infcx.next_trait_solver());
1121        // In intercrate mode, whenever any of the generics are unbound,
1122        // there can always be an impl. Even if there are no impls in
1123        // this crate, perhaps the type would be unified with
1124        // something from another crate that does provide an impl.
1125        //
1126        // In intra mode, we must still be conservative. The reason is
1127        // that we want to avoid cycles. Imagine an impl like:
1128        //
1129        //     impl<T:Eq> Eq for Vec<T>
1130        //
1131        // and a trait reference like `$0 : Eq` where `$0` is an
1132        // unbound variable. When we evaluate this trait-reference, we
1133        // will unify `$0` with `Vec<$1>` (for some fresh variable
1134        // `$1`), on the condition that `$1 : Eq`. We will then wind
1135        // up with many candidates (since that are other `Eq` impls
1136        // that apply) and try to winnow things down. This results in
1137        // a recursive evaluation that `$1 : Eq` -- as you can
1138        // imagine, this is just where we started. To avoid that, we
1139        // check for unbound variables and return an ambiguous (hence possible)
1140        // match if we've seen this trait before.
1141        //
1142        // This suffices to allow chains like `FnMut` implemented in
1143        // terms of `Fn` etc, but we could probably make this more
1144        // precise still.
1145        //
1146        // FIXME(gca_min_const_items): Consider consts as well?
1147        let unbound_input_types =
1148            stack.fresh_trait_pred.skip_binder().trait_ref.args.types().any(|ty| ty.is_fresh());
1149
1150        if unbound_input_types
1151            && stack.iter().skip(1).any(|prev| {
1152                stack.obligation.param_env == prev.obligation.param_env
1153                    && self.match_fresh_trait_preds(stack.fresh_trait_pred, prev.fresh_trait_pred)
1154            })
1155        {
1156            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1156",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1156u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("evaluate_stack --> unbound argument, recursive --> giving up")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("evaluate_stack --> unbound argument, recursive --> giving up");
1157            return Ok(EvaluatedToAmbigStackDependent);
1158        }
1159
1160        match self.candidate_from_obligation(stack) {
1161            Ok(Some(c)) => self.evaluate_candidate(stack, &c),
1162            Ok(None) => Ok(EvaluatedToAmbig),
1163            Err(SelectionError::Overflow(OverflowError::Canonical)) => {
1164                Err(OverflowError::Canonical)
1165            }
1166            Err(..) => Ok(EvaluatedToErr),
1167        }
1168    }
1169
1170    /// For defaulted traits, we use a co-inductive strategy to solve, so
1171    /// that recursion is ok. This routine returns `true` if the top of the
1172    /// stack (`cycle[0]`):
1173    ///
1174    /// - is a coinductive trait: an auto-trait or `Sized`,
1175    /// - it also appears in the backtrace at some position `X`,
1176    /// - all the predicates at positions `X..` between `X` and the top are
1177    ///   also coinductive traits.
1178    pub(crate) fn coinductive_match<I>(&mut self, mut cycle: I) -> bool
1179    where
1180        I: Iterator<Item = ty::Predicate<'tcx>>,
1181    {
1182        cycle.all(|p| match p.kind().skip_binder() {
1183            ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
1184                self.infcx.tcx.trait_is_coinductive(data.def_id())
1185            }
1186            ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => {
1187                // FIXME(generic_const_exprs): GCE needs well-formedness predicates to be
1188                // coinductive, but GCE is on the way out anyways, so this should eventually
1189                // be replaced with `false`.
1190                self.infcx.tcx.features().generic_const_exprs()
1191            }
1192            _ => false,
1193        })
1194    }
1195
1196    /// Further evaluates `candidate` to decide whether all type parameters match and whether nested
1197    /// obligations are met. Returns whether `candidate` remains viable after this further
1198    /// scrutiny.
1199    {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("evaluate_candidate",
                                "rustc_trait_selection::traits::select",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(1199u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("candidate")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("candidate");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("depth")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("depth");
                                                    NAME.as_str()
                                                }], ::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};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&stack.obligation.recursion_depth
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return:
                                Result<EvaluationResult, OverflowError> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let mut result =
                            self.evaluation_probe(|this|
                                        {
                                            match this.confirm_candidate(stack.obligation,
                                                    candidate.clone()) {
                                                Ok(selection) => {
                                                    {
                                                        use ::tracing::__macro_support::Callsite as _;
                                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                                            {
                                                                static META: ::tracing::Metadata<'static> =
                                                                    {
                                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1213",
                                                                            "rustc_trait_selection::traits::select",
                                                                            ::tracing::Level::DEBUG,
                                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                                            ::tracing_core::__macro_support::Option::Some(1213u32),
                                                                            ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                                            ::tracing_core::field::FieldSet::new(&[{
                                                                                                const NAME:
                                                                                                    ::tracing::__macro_support::FieldName<{
                                                                                                        ::tracing::__macro_support::FieldName::len("selection")
                                                                                                    }> =
                                                                                                    ::tracing::__macro_support::FieldName::new("selection");
                                                                                                NAME.as_str()
                                                                                            }], ::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};
                                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&selection)
                                                                                                as &dyn ::tracing::field::Value))])
                                                                });
                                                        } else { ; }
                                                    };
                                                    if let ImplSource::Builtin(..) = selection &&
                                                            this.typing_mode().is_reflection() {
                                                        return Ok(EvaluatedToErr);
                                                    }
                                                    this.evaluate_predicates_recursively(stack.list(),
                                                        selection.nested_obligations().into_iter())
                                                }
                                                Err(..) => Ok(EvaluatedToErr),
                                            }
                                        })?;
                        if stack.fresh_trait_pred.has_erased_regions() {
                            result = result.max(EvaluatedToOkModuloRegions);
                        }
                        Ok(result)
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1199",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1199u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(
1200        level = "debug",
1201        skip(self, stack),
1202        fields(depth = stack.obligation.recursion_depth),
1203        ret
1204    )]
1205    fn evaluate_candidate<'o>(
1206        &mut self,
1207        stack: &TraitObligationStack<'o, 'tcx>,
1208        candidate: &SelectionCandidate<'tcx>,
1209    ) -> Result<EvaluationResult, OverflowError> {
1210        let mut result = self.evaluation_probe(|this| {
1211            match this.confirm_candidate(stack.obligation, candidate.clone()) {
1212                Ok(selection) => {
1213                    debug!(?selection);
1214                    if let ImplSource::Builtin(..) = selection
1215                        && this.typing_mode().is_reflection()
1216                    {
1217                        return Ok(EvaluatedToErr);
1218                    }
1219                    this.evaluate_predicates_recursively(
1220                        stack.list(),
1221                        selection.nested_obligations().into_iter(),
1222                    )
1223                }
1224                Err(..) => Ok(EvaluatedToErr),
1225            }
1226        })?;
1227
1228        // If we erased any lifetimes, then we want to use
1229        // `EvaluatedToOkModuloRegions` instead of `EvaluatedToOk`
1230        // as your final result. The result will be cached using
1231        // the freshened trait predicate as a key, so we need
1232        // our result to be correct by *any* choice of original lifetimes,
1233        // not just the lifetime choice for this particular (non-erased)
1234        // predicate.
1235        // See issue #80691
1236        if stack.fresh_trait_pred.has_erased_regions() {
1237            result = result.max(EvaluatedToOkModuloRegions);
1238        }
1239
1240        Ok(result)
1241    }
1242
1243    fn check_evaluation_cache(
1244        &self,
1245        param_env: ty::ParamEnv<'tcx>,
1246        trait_pred: ty::PolyTraitClause<'tcx>,
1247    ) -> Option<EvaluationResult> {
1248        let infcx = self.infcx;
1249        let tcx = infcx.tcx;
1250        if self.can_use_global_caches(param_env, trait_pred) {
1251            let key = (infcx.typing_env(param_env), trait_pred);
1252            if let Some(res) = tcx.caches.evaluation_cache.get(&key, tcx) {
1253                Some(res)
1254            } else {
1255                if true {
    {
        match (&infcx.evaluation_cache.get(&(param_env, trait_pred), tcx),
                &None) {
            (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);
                }
            }
        }
    };
};debug_assert_eq!(infcx.evaluation_cache.get(&(param_env, trait_pred), tcx), None);
1256                None
1257            }
1258        } else {
1259            self.infcx.evaluation_cache.get(&(param_env, trait_pred), tcx)
1260        }
1261    }
1262
1263    fn insert_evaluation_cache(
1264        &mut self,
1265        param_env: ty::ParamEnv<'tcx>,
1266        trait_pred: ty::PolyTraitClause<'tcx>,
1267        dep_node: DepNodeIndex,
1268        result: EvaluationResult,
1269    ) {
1270        // Avoid caching results that depend on more than just the trait-ref
1271        // - the stack can create recursion.
1272        if result.is_stack_dependent() {
1273            return;
1274        }
1275
1276        let infcx = self.infcx;
1277        let tcx = infcx.tcx;
1278        if self.can_use_global_caches(param_env, trait_pred) {
1279            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1279",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1279u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("trait_pred")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("trait_pred");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("result")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("result");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("insert_evaluation_cache global")
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_pred)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&result)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?trait_pred, ?result, "insert_evaluation_cache global");
1280            // This may overwrite the cache with the same value
1281            tcx.caches.evaluation_cache.insert(
1282                (infcx.typing_env(param_env), trait_pred),
1283                dep_node,
1284                result,
1285            );
1286            return;
1287        } else {
1288            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1288",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1288u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("trait_pred")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("trait_pred");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("result")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("result");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("insert_evaluation_cache local")
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_pred)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&result)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?trait_pred, ?result, "insert_evaluation_cache local");
1289            self.infcx.evaluation_cache.insert((param_env, trait_pred), dep_node, result);
1290        }
1291    }
1292
1293    fn check_recursion_depth<T>(
1294        &self,
1295        depth: usize,
1296        error_obligation: &Obligation<'tcx, T>,
1297    ) -> Result<(), OverflowError>
1298    where
1299        T: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + Clone,
1300    {
1301        if !self.infcx.tcx.recursion_limit().value_within_limit(depth) {
1302            match self.query_mode {
1303                TraitQueryMode::Standard => {
1304                    if let Some(e) = self.infcx.tainted_by_errors() {
1305                        return Err(OverflowError::Error(e));
1306                    }
1307                    self.infcx.err_ctxt().report_overflow_obligation(error_obligation, true);
1308                }
1309                TraitQueryMode::Canonical => {
1310                    return Err(OverflowError::Canonical);
1311                }
1312            }
1313        }
1314        Ok(())
1315    }
1316
1317    /// Checks that the recursion limit has not been exceeded.
1318    ///
1319    /// The weird return type of this function allows it to be used with the `try` (`?`)
1320    /// operator within certain functions.
1321    #[inline(always)]
1322    fn check_recursion_limit<T: Display + TypeFoldable<TyCtxt<'tcx>>, V>(
1323        &self,
1324        obligation: &Obligation<'tcx, T>,
1325        error_obligation: &Obligation<'tcx, V>,
1326    ) -> Result<(), OverflowError>
1327    where
1328        V: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + Clone,
1329    {
1330        self.check_recursion_depth(obligation.recursion_depth, error_obligation)
1331    }
1332
1333    fn in_task<OP, R>(&mut self, op: OP) -> (R, DepNodeIndex)
1334    where
1335        OP: FnOnce(&mut Self) -> R,
1336    {
1337        self.tcx().dep_graph.with_anon_task(self.tcx(), DepKind::TraitSelect, || op(self))
1338    }
1339
1340    /// filter_impls filters candidates that have a positive impl for a negative
1341    /// goal and a negative impl for a positive goal
1342    {}
#[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("filter_impls",
                                    "rustc_trait_selection::traits::select",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1342u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("obligation")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("obligation");
                                                        NAME.as_str()
                                                    }], ::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};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
                                                            as &dyn ::tracing::field::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: Vec<SelectionCandidate<'tcx>> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1348",
                                    "rustc_trait_selection::traits::select",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1348u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::TRACE <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::TRACE <=
                                ::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};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0:#?}",
                                                                candidates) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let tcx = self.tcx();
            candidates.retain(|candidate|
                    {
                        if let &ImplCandidate(def_id) = candidate {
                            match (tcx.impl_polarity(def_id), obligation.polarity()) {
                                (ty::ImplPolarity::Positive, ty::ClausePolarity::Positive) |
                                    (ty::ImplPolarity::Negative, ty::ClausePolarity::Negative)
                                    => true,
                                _ => false,
                            }
                        } else { true }
                    });
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1365",
                                    "rustc_trait_selection::traits::select",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1365u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::TRACE <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::TRACE <=
                                ::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};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0:#?}",
                                                                candidates) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            candidates
        }
    }
}#[instrument(level = "debug", skip(self, candidates))]
1343    fn filter_impls(
1344        &mut self,
1345        mut candidates: Vec<SelectionCandidate<'tcx>>,
1346        obligation: &PolyTraitObligation<'tcx>,
1347    ) -> Vec<SelectionCandidate<'tcx>> {
1348        trace!("{candidates:#?}");
1349        let tcx = self.tcx();
1350
1351        candidates.retain(|candidate| {
1352            if let &ImplCandidate(def_id) = candidate {
1353                match (tcx.impl_polarity(def_id), obligation.polarity()) {
1354                    (ty::ImplPolarity::Positive, ty::ClausePolarity::Positive)
1355                    | (ty::ImplPolarity::Negative, ty::ClausePolarity::Negative) => true,
1356
1357                    // remove impl candidates with mismatched polarity to the obligation
1358                    _ => false,
1359                }
1360            } else {
1361                true
1362            }
1363        });
1364
1365        trace!("{candidates:#?}");
1366        candidates
1367    }
1368
1369    /// Returns `true` if the global caches can be used.
1370    fn can_use_global_caches(
1371        &self,
1372        param_env: ty::ParamEnv<'tcx>,
1373        pred: ty::PolyTraitClause<'tcx>,
1374    ) -> bool {
1375        // If there are any inference variables in the `ParamEnv`, then we
1376        // always use a cache local to this particular scope. Otherwise, we
1377        // switch to a global cache.
1378        if param_env.has_infer() || pred.has_infer() {
1379            return false;
1380        }
1381
1382        match self.typing_mode() {
1383            // Avoid using the global cache when we're defining opaque types
1384            // as their hidden type may impact the result of candidate selection.
1385            //
1386            // HACK: This is still theoretically unsound. Goals can indirectly rely
1387            // on opaques in the defining scope, and it's easier to do so with TAIT.
1388            // However, if we disqualify *all* goals from being cached, perf suffers.
1389            // This is likely fixed by better caching in general in the new solver.
1390            // See: <https://github.com/rust-lang/rust/issues/132064>.
1391            TypingMode::Typeck { defining_opaque_types_and_generators: defining_opaque_types }
1392            | TypingMode::PostTypeckThroughBorrowck { defining_opaque_types } => {
1393                defining_opaque_types.is_empty()
1394                    || (!pred.has_opaque_types() && !pred.has_coroutines())
1395            }
1396            // Impls that are not fully generic are completely ignored as "nonexistent"
1397            // in this mode, so the results wildly differ from normal trait solving.
1398            TypingMode::Reflection => false,
1399            // The hidden types of `defined_opaque_types` is not local to the current
1400            // inference context, so we can freely move this to the global cache.
1401            TypingMode::PostBorrowck { .. } => true,
1402            // The global cache is only used if there are no opaque types in
1403            // the defining scope or we're outside of analysis.
1404            //
1405            // FIXME(#132279): This is still incorrect as we treat opaque types
1406            // and default associated items differently between these two modes.
1407            TypingMode::PostAnalysis | TypingMode::Codegen => true,
1408            TypingMode::Coherence => {
1409                {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("old solver coherence")));
}unreachable!("old solver coherence")
1410            }
1411        }
1412    }
1413
1414    fn check_candidate_cache(
1415        &mut self,
1416        param_env: ty::ParamEnv<'tcx>,
1417        cache_fresh_trait_pred: ty::PolyTraitClause<'tcx>,
1418    ) -> Option<SelectionResult<'tcx, SelectionCandidate<'tcx>>> {
1419        let infcx = self.infcx;
1420        let tcx = infcx.tcx;
1421        let pred = cache_fresh_trait_pred.skip_binder();
1422
1423        if self.can_use_global_caches(param_env, cache_fresh_trait_pred) {
1424            if let Some(res) =
1425                tcx.caches.selection_cache.get(&(infcx.typing_env(param_env), pred), tcx)
1426            {
1427                return Some(res);
1428            } else if truecfg!(debug_assertions) {
1429                match infcx.selection_cache.get(&(param_env, pred), tcx) {
1430                    None | Some(Err(SelectionError::Overflow(OverflowError::Canonical))) => {}
1431                    res => ::rustc_span::macros::bug_impl(None,
    format_args!("unexpected local cache result: {0:?}", res),
    Location::caller())bug!("unexpected local cache result: {res:?}"),
1432                }
1433            }
1434        }
1435
1436        // Subtle: we need to check the local cache even if we're able to use the
1437        // global cache as we don't cache overflow in the global cache but need to
1438        // cache it as otherwise rustdoc hangs when compiling diesel.
1439        infcx.selection_cache.get(&(param_env, pred), tcx)
1440    }
1441
1442    /// Determines whether can we safely cache the result
1443    /// of selecting an obligation. This is almost always `true`,
1444    /// except when dealing with certain `ParamCandidate`s.
1445    ///
1446    /// Ordinarily, a `ParamCandidate` will contain no inference variables,
1447    /// since it was usually produced directly from a `DefId`. However,
1448    /// certain cases (currently only librustdoc's blanket impl finder),
1449    /// a `ParamEnv` may be explicitly constructed with inference types.
1450    /// When this is the case, we do *not* want to cache the resulting selection
1451    /// candidate. This is due to the fact that it might not always be possible
1452    /// to equate the obligation's trait ref and the candidate's trait ref,
1453    /// if more constraints end up getting added to an inference variable.
1454    ///
1455    /// Because of this, we always want to re-run the full selection
1456    /// process for our obligation the next time we see it, since
1457    /// we might end up picking a different `SelectionCandidate` (or none at all).
1458    fn can_cache_candidate(
1459        &self,
1460        result: &SelectionResult<'tcx, SelectionCandidate<'tcx>>,
1461    ) -> bool {
1462        match result {
1463            Ok(Some(SelectionCandidate::ParamCandidate(trait_ref))) => !trait_ref.has_infer(),
1464            _ => true,
1465        }
1466    }
1467
1468    {}
#[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("insert_candidate_cache",
                                    "rustc_trait_selection::traits::select",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1468u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("candidate")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("candidate");
                                                        NAME.as_str()
                                                    }], ::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};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let infcx = self.infcx;
            let tcx = infcx.tcx;
            let pred = cache_fresh_trait_pred.skip_binder();
            if !self.can_cache_candidate(&candidate) {
                {
                    use ::tracing::__macro_support::Callsite as _;
                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                        {
                            static META: ::tracing::Metadata<'static> =
                                {
                                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1481",
                                        "rustc_trait_selection::traits::select",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                        ::tracing_core::__macro_support::Option::Some(1481u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                        ::tracing_core::field::FieldSet::new(&["message",
                                                        {
                                                            const NAME:
                                                                ::tracing::__macro_support::FieldName<{
                                                                    ::tracing::__macro_support::FieldName::len("pred")
                                                                }> =
                                                                ::tracing::__macro_support::FieldName::new("pred");
                                                            NAME.as_str()
                                                        },
                                                        {
                                                            const NAME:
                                                                ::tracing::__macro_support::FieldName<{
                                                                    ::tracing::__macro_support::FieldName::len("candidate")
                                                                }> =
                                                                ::tracing::__macro_support::FieldName::new("candidate");
                                                            NAME.as_str()
                                                        }], ::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};
                                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("insert_candidate_cache - candidate is not cacheable")
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&pred)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
                                                            as &dyn ::tracing::field::Value))])
                            });
                    } else { ; }
                };
                return;
            }
            if self.can_use_global_caches(param_env, cache_fresh_trait_pred) {
                if let Err(SelectionError::Overflow(OverflowError::Canonical))
                        = candidate
                    {} else {
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1489",
                                            "rustc_trait_selection::traits::select",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                            ::tracing_core::__macro_support::Option::Some(1489u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                            ::tracing_core::field::FieldSet::new(&["message",
                                                            {
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("pred")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("pred");
                                                                NAME.as_str()
                                                            },
                                                            {
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("candidate")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("candidate");
                                                                NAME.as_str()
                                                            }], ::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};
                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("insert_candidate_cache global")
                                                                as &dyn ::tracing::field::Value)),
                                                    (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&pred)
                                                                as &dyn ::tracing::field::Value)),
                                                    (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
                                                                as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    if true {
                        if !!candidate.has_infer() {
                            ::core::panicking::panic("assertion failed: !candidate.has_infer()")
                        };
                    };
                    tcx.caches.selection_cache.insert((infcx.typing_env(param_env),
                            pred), dep_node, candidate);
                    return;
                }
            }
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1502",
                                    "rustc_trait_selection::traits::select",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1502u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                    ::tracing_core::field::FieldSet::new(&["message",
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("pred")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("pred");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("candidate")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("candidate");
                                                        NAME.as_str()
                                                    }], ::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};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("insert_candidate_cache local")
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&pred)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            self.infcx.selection_cache.insert((param_env, pred), dep_node,
                candidate);
        }
    }
}#[instrument(skip(self, param_env, cache_fresh_trait_pred, dep_node), level = "debug")]
1469    fn insert_candidate_cache(
1470        &mut self,
1471        param_env: ty::ParamEnv<'tcx>,
1472        cache_fresh_trait_pred: ty::PolyTraitClause<'tcx>,
1473        dep_node: DepNodeIndex,
1474        candidate: SelectionResult<'tcx, SelectionCandidate<'tcx>>,
1475    ) {
1476        let infcx = self.infcx;
1477        let tcx = infcx.tcx;
1478        let pred = cache_fresh_trait_pred.skip_binder();
1479
1480        if !self.can_cache_candidate(&candidate) {
1481            debug!(?pred, ?candidate, "insert_candidate_cache - candidate is not cacheable");
1482            return;
1483        }
1484
1485        if self.can_use_global_caches(param_env, cache_fresh_trait_pred) {
1486            if let Err(SelectionError::Overflow(OverflowError::Canonical)) = candidate {
1487                // Don't cache overflow globally; we only produce this in certain modes.
1488            } else {
1489                debug!(?pred, ?candidate, "insert_candidate_cache global");
1490                debug_assert!(!candidate.has_infer());
1491
1492                // This may overwrite the cache with the same value.
1493                tcx.caches.selection_cache.insert(
1494                    (infcx.typing_env(param_env), pred),
1495                    dep_node,
1496                    candidate,
1497                );
1498                return;
1499            }
1500        }
1501
1502        debug!(?pred, ?candidate, "insert_candidate_cache local");
1503        self.infcx.selection_cache.insert((param_env, pred), dep_node, candidate);
1504    }
1505
1506    /// Looks at the item bounds of the projection or opaque type.
1507    /// If this is a nested rigid projection, such as
1508    /// `<<T as Tr1>::Assoc as Tr2>::Assoc`, consider the item bounds
1509    /// on both `Tr1::Assoc` and `Tr2::Assoc`, since we may encounter
1510    /// relative bounds on both via the `associated_type_bounds` feature.
1511    pub(super) fn for_each_item_bound<T>(
1512        &mut self,
1513        mut self_ty: Ty<'tcx>,
1514        mut for_each: impl FnMut(
1515            &mut Self,
1516            ty::Clause<'tcx>,
1517            usize,
1518            AliasBoundKind,
1519        ) -> ControlFlow<T, ()>,
1520        on_ambiguity: impl FnOnce(),
1521    ) -> ControlFlow<T, ()> {
1522        let mut idx = 0;
1523        let mut alias_bound_kind = AliasBoundKind::SelfBounds;
1524
1525        loop {
1526            let (alias_ty, def_id) = match *self_ty.kind() {
1527                ty::Alias(
1528                    _,
1529                    alias_ty @ ty::AliasTy {
1530                        kind: ty::Projection { def_id } | ty::Opaque { def_id },
1531                        ..
1532                    },
1533                ) => (alias_ty, def_id),
1534                ty::Infer(ty::TyVar(_)) => {
1535                    on_ambiguity();
1536                    return ControlFlow::Continue(());
1537                }
1538                _ => return ControlFlow::Continue(()),
1539            };
1540
1541            // HACK: On subsequent recursions, we only care about bounds that don't
1542            // share the same type as `self_ty`. This is because for truly rigid
1543            // projections, we will never be able to equate, e.g. `<T as Tr>::A`
1544            // with `<<T as Tr>::A as Tr>::A`.
1545            let relevant_bounds = if alias_bound_kind == AliasBoundKind::NonSelfBounds {
1546                self.tcx().item_non_self_bounds(def_id)
1547            } else {
1548                self.tcx().item_self_bounds(def_id)
1549            };
1550
1551            for bound in relevant_bounds.instantiate(self.tcx(), alias_ty.args).skip_norm_wip() {
1552                for_each(self, bound, idx, alias_bound_kind)?;
1553                idx += 1;
1554            }
1555
1556            if #[allow(non_exhaustive_omitted_patterns)] match alias_ty.kind {
    ty::Projection { .. } => true,
    _ => false,
}matches!(alias_ty.kind, ty::Projection { .. }) {
1557                self_ty = alias_ty.self_ty();
1558            } else {
1559                return ControlFlow::Continue(());
1560            }
1561
1562            alias_bound_kind = AliasBoundKind::NonSelfBounds;
1563        }
1564    }
1565
1566    /// Equates the trait in `obligation` with trait bound. If the two traits
1567    /// can be equated and the normalized trait bound doesn't contain inference
1568    /// variables or placeholders, the normalized bound is returned.
1569    fn match_normalize_trait_ref(
1570        &mut self,
1571        obligation: &PolyTraitObligation<'tcx>,
1572        placeholder_trait_ref: ty::TraitRef<'tcx>,
1573        trait_bound: ty::PolyTraitRef<'tcx>,
1574    ) -> Result<Option<ty::TraitRef<'tcx>>, ()> {
1575        if true {
    if !!placeholder_trait_ref.has_escaping_bound_vars() {
        ::core::panicking::panic("assertion failed: !placeholder_trait_ref.has_escaping_bound_vars()")
    };
};debug_assert!(!placeholder_trait_ref.has_escaping_bound_vars());
1576        if placeholder_trait_ref.def_id != trait_bound.def_id() {
1577            // Avoid unnecessary normalization
1578            return Err(());
1579        }
1580
1581        let drcx = DeepRejectCtxt::relate_rigid_rigid(self.infcx.tcx);
1582        let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
1583        if !drcx.args_may_unify(obligation_args, trait_bound.skip_binder().args) {
1584            return Err(());
1585        }
1586
1587        let trait_bound = self.infcx.instantiate_binder_with_fresh_vars(
1588            obligation.cause.span,
1589            HigherRankedType,
1590            trait_bound,
1591        );
1592        let Normalized { value: trait_bound, obligations: _ } = normalize_with_depth(
1593            self,
1594            obligation.param_env,
1595            obligation.cause.clone(),
1596            obligation.recursion_depth + 1,
1597            ty::Unnormalized::new_wip(trait_bound),
1598        );
1599        self.infcx
1600            .at(&obligation.cause, obligation.param_env)
1601            .eq(DefineOpaqueTypes::No, placeholder_trait_ref, trait_bound)
1602            .map(|InferOk { obligations: _, value: () }| {
1603                // This method is called within a probe, so we can't have
1604                // inference variables and placeholders escape.
1605                if !trait_bound.has_infer() && !trait_bound.has_placeholders() {
1606                    Some(trait_bound)
1607                } else {
1608                    None
1609                }
1610            })
1611            .map_err(|_| ())
1612    }
1613
1614    fn where_clause_may_apply<'o>(
1615        &mut self,
1616        stack: &TraitObligationStack<'o, 'tcx>,
1617        where_clause_trait_ref: ty::PolyTraitRef<'tcx>,
1618    ) -> Result<EvaluationResult, OverflowError> {
1619        self.evaluation_probe(|this| {
1620            match this.match_where_clause_trait_ref(stack.obligation, where_clause_trait_ref) {
1621                Ok(obligations) => this.evaluate_predicates_recursively(stack.list(), obligations),
1622                Err(()) => Ok(EvaluatedToErr),
1623            }
1624        })
1625    }
1626
1627    /// Return `Yes` if the obligation's predicate type applies to the env_predicate, and
1628    /// `No` if it does not. Return `Ambiguous` in the case that the projection type is a GAT,
1629    /// and applying this env_predicate constrains any of the obligation's GAT parameters.
1630    ///
1631    /// This behavior is a somewhat of a hack to prevent over-constraining inference variables
1632    /// in cases like #91762.
1633    pub(super) fn match_projection_projections(
1634        &mut self,
1635        obligation: &ProjectionTermObligation<'tcx>,
1636        env_predicate: PolyProjectionClause<'tcx>,
1637        potentially_unnormalized_candidates: bool,
1638    ) -> ProjectionMatchesProjection {
1639        let def_id = obligation.predicate.expect_projection_def_id();
1640        if true {
    {
        match (&def_id, &env_predicate.item_def_id()) {
            (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);
                }
            }
        }
    };
};debug_assert_eq!(def_id, env_predicate.item_def_id());
1641
1642        let mut nested_obligations = PredicateObligations::new();
1643        let infer_predicate = self.infcx.instantiate_binder_with_fresh_vars(
1644            obligation.cause.span,
1645            BoundRegionConversionTime::HigherRankedType,
1646            env_predicate,
1647        );
1648        let mut infer_projection = infer_predicate.projection_term;
1649        if potentially_unnormalized_candidates {
1650            infer_projection = normalize_with_depth_to(
1651                self,
1652                obligation.param_env,
1653                obligation.cause.clone(),
1654                obligation.recursion_depth + 1,
1655                ty::Unnormalized::new_wip(infer_projection),
1656                &mut nested_obligations,
1657            )
1658        }
1659
1660        let is_match = self
1661            .infcx
1662            .at(&obligation.cause, obligation.param_env)
1663            .eq(DefineOpaqueTypes::No, obligation.predicate, infer_projection)
1664            .is_ok_and(|InferOk { obligations, value: () }| {
1665                self.evaluate_predicates_recursively(
1666                    TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
1667                    nested_obligations.into_iter().chain(obligations),
1668                )
1669                .is_ok_and(|res| res.may_apply())
1670            });
1671
1672        if is_match {
1673            let generics = self.tcx().generics_of(def_id);
1674            // FIXME(generic_associated_types): Addresses aggressive inference in #92917.
1675            // If this type is a GAT, and of the GAT args resolve to something new,
1676            // that means that we must have newly inferred something about the GAT.
1677            // We should give up in that case.
1678            //
1679            // This only detects one layer of inference, which is probably not what we actually
1680            // want, but fixing it causes some ambiguity:
1681            // <https://github.com/rust-lang/rust/issues/125196>.
1682            if !generics.is_own_empty()
1683                && obligation.predicate.args[generics.parent_count..].iter().any(|&p| {
1684                    p.has_non_region_infer()
1685                        && match p.kind() {
1686                            ty::GenericArgKind::Const(ct) => {
1687                                self.infcx.shallow_resolve_const(ct) != ct
1688                            }
1689                            ty::GenericArgKind::Type(ty) => self.infcx.shallow_resolve(ty) != ty,
1690                            ty::GenericArgKind::Lifetime(_) => false,
1691                        }
1692                })
1693            {
1694                ProjectionMatchesProjection::Ambiguous
1695            } else {
1696                ProjectionMatchesProjection::Yes
1697            }
1698        } else {
1699            ProjectionMatchesProjection::No
1700        }
1701    }
1702}
1703
1704/// ## Winnowing
1705///
1706/// Winnowing is the process of attempting to resolve ambiguity by
1707/// probing further. During the winnowing process, we unify all
1708/// type variables and then we also attempt to evaluate recursive
1709/// bounds to see if they are satisfied.
1710impl<'tcx> SelectionContext<'_, 'tcx> {
1711    /// If there are multiple ways to prove a trait goal, we make some
1712    /// *fairly arbitrary* choices about which candidate is actually used.
1713    ///
1714    /// For more details, look at the implementation of this method :)
1715    {}
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("winnow_candidates",
                                "rustc_trait_selection::traits::select",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(1715u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("has_non_region_infer")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("has_non_region_infer");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("candidate_preference_mode")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("candidate_preference_mode");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("candidates")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("candidates");
                                                    NAME.as_str()
                                                }], ::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};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&has_non_region_infer
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate_preference_mode)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidates)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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:
                                Option<SelectionCandidate<'tcx>> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if candidates.len() == 1 {
                            return Some(candidates.pop().unwrap().candidate);
                        }
                        let mut sized_candidates =
                            candidates.iter().filter(|c|
                                    #[allow(non_exhaustive_omitted_patterns)] match c.candidate
                                        {
                                        SizedCandidate => true,
                                        _ => false,
                                    });
                        if let Some(sized_candidate) = sized_candidates.next() {
                            if true {
                                {
                                    match (&sized_candidates.next(), &None) {
                                        (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);
                                            }
                                        }
                                    }
                                };
                            };
                            if sized_candidate.evaluation.must_apply_modulo_regions() {
                                return Some(sized_candidate.candidate.clone());
                            } else { return None; }
                        }
                        'search_victim: loop {
                            for (i, this) in candidates.iter().enumerate() {
                                let ParamCandidate(this) = this.candidate else { continue };
                                for (j, other) in candidates.iter().enumerate() {
                                    if i == j { continue; }
                                    let ParamCandidate(other) =
                                        other.candidate else { continue };
                                    if this == other {
                                        candidates.remove(j);
                                        continue 'search_victim;
                                    }
                                    if this.skip_binder().trait_ref ==
                                                    other.skip_binder().trait_ref &&
                                                this.skip_binder().polarity == other.skip_binder().polarity
                                            && !this.skip_binder().trait_ref.has_escaping_bound_vars() {
                                        candidates.remove(j);
                                        continue 'search_victim;
                                    }
                                }
                            }
                            break;
                        }
                        let mut alias_bounds =
                            candidates.iter().filter_map(|c|
                                    {
                                        if let ProjectionCandidate { idx, kind } = c.candidate {
                                            Some((idx, kind))
                                        } else { None }
                                    });
                        if #[allow(non_exhaustive_omitted_patterns)] match candidate_preference_mode
                                {
                                CandidatePreferenceMode::Marker => true,
                                _ => false,
                            } {
                            match alias_bounds.clone().filter_map(|(idx, kind)|
                                            (kind ==
                                                        AliasBoundKind::SelfBounds).then_some(idx)).try_reduce(|c1,
                                        c2|
                                        if has_non_region_infer { None } else { Some(c1.min(c2)) })
                                {
                                Some(Some(idx)) => {
                                    return Some(ProjectionCandidate {
                                                idx,
                                                kind: AliasBoundKind::SelfBounds,
                                            });
                                }
                                Some(None) => {}
                                None => return None,
                            }
                        }
                        let is_global =
                            |c: ty::PolyTraitClause<'tcx>|
                                c.is_global() && !c.has_bound_vars();
                        let param_candidates =
                            candidates.iter().filter_map(|c|
                                    if let ParamCandidate(p) = c.candidate {
                                        Some(p)
                                    } else { None });
                        let mut has_global_bounds = false;
                        let mut param_candidate = None;
                        for c in param_candidates {
                            if is_global(c) {
                                has_global_bounds = true;
                            } else if param_candidate.replace(c).is_some() {
                                return None;
                            }
                        }
                        if let Some(predicate) = param_candidate {
                            if has_global_bounds {
                                return None;
                            } else { return Some(ParamCandidate(predicate)); }
                        }
                        match alias_bounds.try_reduce(|(c1, k1), (c2, k2)|
                                    {
                                        if has_non_region_infer {
                                            None
                                        } else if c1 < c2 { Some((c1, k1)) } else { Some((c2, k2)) }
                                    }) {
                            Some(Some((idx, kind))) =>
                                return Some(ProjectionCandidate { idx, kind }),
                            Some(None) => {}
                            None => return None,
                        }
                        let object_bound =
                            candidates.iter().filter_map(|c|
                                        if let ObjectCandidate(i) = c.candidate {
                                            Some(i)
                                        } else {
                                            None
                                        }).try_reduce(|c1, c2|
                                    if has_non_region_infer { None } else { Some(c1.min(c2)) });
                        match object_bound {
                            Some(Some(index)) => {
                                return if has_non_region_infer &&
                                            candidates.iter().any(|c|
                                                    #[allow(non_exhaustive_omitted_patterns)] match c.candidate
                                                        {
                                                        ImplCandidate(_) => true,
                                                        _ => false,
                                                    }) {
                                        None
                                    } else { Some(ObjectCandidate(index)) };
                            }
                            Some(None) => {}
                            None => return None,
                        }
                        let upcast_bound =
                            candidates.iter().filter_map(|c|
                                        {
                                            if let TraitUpcastingUnsizeCandidate(i) = c.candidate {
                                                Some(i)
                                            } else { None }
                                        }).try_reduce(|c1, c2|
                                    if has_non_region_infer { None } else { Some(c1.min(c2)) });
                        match upcast_bound {
                            Some(Some(index)) =>
                                return Some(TraitUpcastingUnsizeCandidate(index)),
                            Some(None) => {}
                            None => return None,
                        }
                        let impls =
                            candidates.iter().filter_map(|c|
                                    {
                                        if let ImplCandidate(def_id) = c.candidate {
                                            Some((def_id, c.evaluation))
                                        } else { None }
                                    });
                        let mut impl_candidate = None;
                        for c in impls {
                            if let Some(prev) = impl_candidate.replace(c) {
                                if self.prefer_lhs_over_victim(has_non_region_infer, c,
                                        prev.0)
                                    {} else if self.prefer_lhs_over_victim(has_non_region_infer,
                                        prev, c.0) {
                                    impl_candidate = Some(prev);
                                } else { return None; }
                            }
                        }
                        if let Some((def_id, _evaluation)) = impl_candidate {
                            if candidates.iter().all(|c|
                                        match c.candidate {
                                            SizedCandidate | BuiltinCandidate | TransmutabilityCandidate
                                                | AutoImplCandidate | ClosureCandidate { .. } |
                                                AsyncClosureCandidate | AsyncFnKindHelperCandidate |
                                                CoroutineCandidate | FutureCandidate | IteratorCandidate |
                                                AsyncIteratorCandidate | FnPointerCandidate |
                                                TraitAliasCandidate | TraitUpcastingUnsizeCandidate(_) |
                                                BuiltinObjectCandidate | BuiltinUnsizeCandidate |
                                                TryAsDynCandidate | BikeshedGuaranteedNoDropCandidate =>
                                                false,
                                            ParamCandidate(_) | ImplCandidate(_) => true,
                                            ProjectionCandidate { .. } | ObjectCandidate(_) =>
                                                ::core::panicking::panic("internal error: entered unreachable code"),
                                        }) {
                                return Some(ImplCandidate(def_id));
                            } else { return None; }
                        }
                        if candidates.len() == 1 {
                            Some(candidates.pop().unwrap().candidate)
                        } else {
                            let mut not_a_global_where_bound =
                                candidates.into_iter().filter(|c|
                                        !#[allow(non_exhaustive_omitted_patterns)] match c.candidate
                                                {
                                                ParamCandidate(p) if is_global(p) => true,
                                                _ => false,
                                            });
                            not_a_global_where_bound.next().map(|c|
                                        c.candidate).filter(|_|
                                    not_a_global_where_bound.next().is_none())
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:1715",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1715u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
1716    fn winnow_candidates(
1717        &mut self,
1718        has_non_region_infer: bool,
1719        candidate_preference_mode: CandidatePreferenceMode,
1720        mut candidates: Vec<EvaluatedCandidate<'tcx>>,
1721    ) -> Option<SelectionCandidate<'tcx>> {
1722        if candidates.len() == 1 {
1723            return Some(candidates.pop().unwrap().candidate);
1724        }
1725
1726        // We prefer `Sized` candidates over everything.
1727        let mut sized_candidates =
1728            candidates.iter().filter(|c| matches!(c.candidate, SizedCandidate));
1729        if let Some(sized_candidate) = sized_candidates.next() {
1730            // There should only ever be a single sized candidate
1731            // as they would otherwise overlap.
1732            debug_assert_eq!(sized_candidates.next(), None);
1733            // Only prefer the built-in `Sized` candidate if its nested goals are certain.
1734            // Otherwise, we may encounter failure later on if inference causes this candidate
1735            // to not hold, but a where clause would've applied instead.
1736            if sized_candidate.evaluation.must_apply_modulo_regions() {
1737                return Some(sized_candidate.candidate.clone());
1738            } else {
1739                return None;
1740            }
1741        }
1742
1743        // Before we consider where-bounds, we have to deduplicate them here and also
1744        // drop where-bounds in case the same where-bound exists without bound vars.
1745        // This is necessary as elaborating super-trait bounds may result in duplicates.
1746        'search_victim: loop {
1747            for (i, this) in candidates.iter().enumerate() {
1748                let ParamCandidate(this) = this.candidate else { continue };
1749                for (j, other) in candidates.iter().enumerate() {
1750                    if i == j {
1751                        continue;
1752                    }
1753
1754                    let ParamCandidate(other) = other.candidate else { continue };
1755                    if this == other {
1756                        candidates.remove(j);
1757                        continue 'search_victim;
1758                    }
1759
1760                    if this.skip_binder().trait_ref == other.skip_binder().trait_ref
1761                        && this.skip_binder().polarity == other.skip_binder().polarity
1762                        && !this.skip_binder().trait_ref.has_escaping_bound_vars()
1763                    {
1764                        candidates.remove(j);
1765                        continue 'search_victim;
1766                    }
1767                }
1768            }
1769
1770            break;
1771        }
1772
1773        let mut alias_bounds = candidates.iter().filter_map(|c| {
1774            if let ProjectionCandidate { idx, kind } = c.candidate {
1775                Some((idx, kind))
1776            } else {
1777                None
1778            }
1779        });
1780        // Extract non-nested alias bound candidates, will be preferred over where bounds if
1781        // we're proving an auto-trait, sizedness trait or default trait.
1782        if matches!(candidate_preference_mode, CandidatePreferenceMode::Marker) {
1783            match alias_bounds
1784                .clone()
1785                .filter_map(|(idx, kind)| (kind == AliasBoundKind::SelfBounds).then_some(idx))
1786                .try_reduce(|c1, c2| if has_non_region_infer { None } else { Some(c1.min(c2)) })
1787            {
1788                Some(Some(idx)) => {
1789                    return Some(ProjectionCandidate { idx, kind: AliasBoundKind::SelfBounds });
1790                }
1791                Some(None) => {}
1792                None => return None,
1793            }
1794        }
1795
1796        // The next highest priority is for non-global where-bounds. However, while we don't
1797        // prefer global where-clauses here, we do bail with ambiguity when encountering both
1798        // a global and a non-global where-clause.
1799        //
1800        // Our handling of where-bounds is generally fairly messy but necessary for backwards
1801        // compatibility, see #50825 for why we need to handle global where-bounds like this.
1802        let is_global = |c: ty::PolyTraitClause<'tcx>| c.is_global() && !c.has_bound_vars();
1803        let param_candidates = candidates
1804            .iter()
1805            .filter_map(|c| if let ParamCandidate(p) = c.candidate { Some(p) } else { None });
1806        let mut has_global_bounds = false;
1807        let mut param_candidate = None;
1808        for c in param_candidates {
1809            if is_global(c) {
1810                has_global_bounds = true;
1811            } else if param_candidate.replace(c).is_some() {
1812                // Ambiguity, two potentially different where-clauses
1813                return None;
1814            }
1815        }
1816        if let Some(predicate) = param_candidate {
1817            // Ambiguity, a global and a non-global where-bound.
1818            if has_global_bounds {
1819                return None;
1820            } else {
1821                return Some(ParamCandidate(predicate));
1822            }
1823        }
1824
1825        // Prefer alias-bounds over blanket impls for rigid associated types. This is
1826        // fairly arbitrary but once again necessary for backwards compatibility.
1827        // If there are multiple applicable candidates which don't affect type inference,
1828        // choose the one with the lowest index.
1829        match alias_bounds.try_reduce(|(c1, k1), (c2, k2)| {
1830            if has_non_region_infer {
1831                None
1832            } else if c1 < c2 {
1833                Some((c1, k1))
1834            } else {
1835                Some((c2, k2))
1836            }
1837        }) {
1838            Some(Some((idx, kind))) => return Some(ProjectionCandidate { idx, kind }),
1839            Some(None) => {}
1840            None => return None,
1841        }
1842
1843        // Need to prioritize builtin trait object impls as `<dyn Any as Any>::type_id`
1844        // should use the vtable method and not the method provided by the user-defined
1845        // impl `impl<T: ?Sized> Any for T { .. }`. This really shouldn't exist but is
1846        // necessary due to #57893. We again arbitrarily prefer the applicable candidate
1847        // with the lowest index.
1848        //
1849        // We do not want to use these impls to guide inference in case a user-written impl
1850        // may also apply.
1851        let object_bound = candidates
1852            .iter()
1853            .filter_map(|c| if let ObjectCandidate(i) = c.candidate { Some(i) } else { None })
1854            .try_reduce(|c1, c2| if has_non_region_infer { None } else { Some(c1.min(c2)) });
1855        match object_bound {
1856            Some(Some(index)) => {
1857                return if has_non_region_infer
1858                    && candidates.iter().any(|c| matches!(c.candidate, ImplCandidate(_)))
1859                {
1860                    None
1861                } else {
1862                    Some(ObjectCandidate(index))
1863                };
1864            }
1865            Some(None) => {}
1866            None => return None,
1867        }
1868        // Same for upcasting.
1869        let upcast_bound = candidates
1870            .iter()
1871            .filter_map(|c| {
1872                if let TraitUpcastingUnsizeCandidate(i) = c.candidate { Some(i) } else { None }
1873            })
1874            .try_reduce(|c1, c2| if has_non_region_infer { None } else { Some(c1.min(c2)) });
1875        match upcast_bound {
1876            Some(Some(index)) => return Some(TraitUpcastingUnsizeCandidate(index)),
1877            Some(None) => {}
1878            None => return None,
1879        }
1880
1881        // Finally, handle overlapping user-written impls.
1882        let impls = candidates.iter().filter_map(|c| {
1883            if let ImplCandidate(def_id) = c.candidate {
1884                Some((def_id, c.evaluation))
1885            } else {
1886                None
1887            }
1888        });
1889        let mut impl_candidate = None;
1890        for c in impls {
1891            if let Some(prev) = impl_candidate.replace(c) {
1892                if self.prefer_lhs_over_victim(has_non_region_infer, c, prev.0) {
1893                    // Ok, prefer `c` over the previous entry
1894                } else if self.prefer_lhs_over_victim(has_non_region_infer, prev, c.0) {
1895                    // Ok, keep `prev` instead of the new entry
1896                    impl_candidate = Some(prev);
1897                } else {
1898                    // Ambiguity, two potentially different where-clauses
1899                    return None;
1900                }
1901            }
1902        }
1903        if let Some((def_id, _evaluation)) = impl_candidate {
1904            // Don't use impl candidates which overlap with other candidates.
1905            // This should pretty much only ever happen with malformed impls.
1906            if candidates.iter().all(|c| match c.candidate {
1907                SizedCandidate
1908                | BuiltinCandidate
1909                | TransmutabilityCandidate
1910                | AutoImplCandidate
1911                | ClosureCandidate { .. }
1912                | AsyncClosureCandidate
1913                | AsyncFnKindHelperCandidate
1914                | CoroutineCandidate
1915                | FutureCandidate
1916                | IteratorCandidate
1917                | AsyncIteratorCandidate
1918                | FnPointerCandidate
1919                | TraitAliasCandidate
1920                | TraitUpcastingUnsizeCandidate(_)
1921                | BuiltinObjectCandidate
1922                | BuiltinUnsizeCandidate
1923                | TryAsDynCandidate
1924                | BikeshedGuaranteedNoDropCandidate => false,
1925                // Non-global param candidates have already been handled, global
1926                // where-bounds get ignored.
1927                ParamCandidate(_) | ImplCandidate(_) => true,
1928                ProjectionCandidate { .. } | ObjectCandidate(_) => unreachable!(),
1929            }) {
1930                return Some(ImplCandidate(def_id));
1931            } else {
1932                return None;
1933            }
1934        }
1935
1936        if candidates.len() == 1 {
1937            Some(candidates.pop().unwrap().candidate)
1938        } else {
1939            // Also try ignoring all global where-bounds and check whether we end
1940            // with a unique candidate in this case.
1941            let mut not_a_global_where_bound = candidates
1942                .into_iter()
1943                .filter(|c| !matches!(c.candidate, ParamCandidate(p) if is_global(p)));
1944            not_a_global_where_bound
1945                .next()
1946                .map(|c| c.candidate)
1947                .filter(|_| not_a_global_where_bound.next().is_none())
1948        }
1949    }
1950
1951    fn prefer_lhs_over_victim(
1952        &self,
1953        has_non_region_infer: bool,
1954        (lhs, lhs_evaluation): (DefId, EvaluationResult),
1955        victim: DefId,
1956    ) -> bool {
1957        let tcx = self.tcx();
1958        // See if we can toss out `victim` based on specialization.
1959        //
1960        // While this requires us to know *for sure* that the `lhs` impl applies
1961        // we still use modulo regions here. This is fine as specialization currently
1962        // assumes that specializing impls have to be always applicable, meaning that
1963        // the only allowed region constraints may be constraints also present on the default impl.
1964        if lhs_evaluation.must_apply_modulo_regions() {
1965            if tcx.specializes((lhs, victim)) {
1966                return true;
1967            }
1968        }
1969
1970        match tcx.impls_are_allowed_to_overlap(lhs, victim) {
1971            // For candidates which already reference errors it doesn't really
1972            // matter what we do 🤷
1973            Some(ty::ImplOverlapKind::Permitted { marker: false }) => {
1974                lhs_evaluation.must_apply_considering_regions()
1975            }
1976            Some(ty::ImplOverlapKind::Permitted { marker: true }) => {
1977                // Subtle: If the predicate we are evaluating has inference
1978                // variables, do *not* allow discarding candidates due to
1979                // marker trait impls.
1980                //
1981                // Without this restriction, we could end up accidentally
1982                // constraining inference variables based on an arbitrarily
1983                // chosen trait impl.
1984                //
1985                // Imagine we have the following code:
1986                //
1987                // ```rust
1988                // #[marker] trait MyTrait {}
1989                // impl MyTrait for u8 {}
1990                // impl MyTrait for bool {}
1991                // ```
1992                //
1993                // And we are evaluating the predicate `<_#0t as MyTrait>`.
1994                //
1995                // During selection, we will end up with one candidate for each
1996                // impl of `MyTrait`. If we were to discard one impl in favor
1997                // of the other, we would be left with one candidate, causing
1998                // us to "successfully" select the predicate, unifying
1999                // _#0t with (for example) `u8`.
2000                //
2001                // However, we have no reason to believe that this unification
2002                // is correct - we've essentially just picked an arbitrary
2003                // *possibility* for _#0t, and required that this be the *only*
2004                // possibility.
2005                //
2006                // Eventually, we will either:
2007                // 1) Unify all inference variables in the predicate through
2008                // some other means (e.g. type-checking of a function). We will
2009                // then be in a position to drop marker trait candidates
2010                // without constraining inference variables (since there are
2011                // none left to constrain)
2012                // 2) Be left with some unconstrained inference variables. We
2013                // will then correctly report an inference error, since the
2014                // existence of multiple marker trait impls tells us nothing
2015                // about which one should actually apply.
2016                !has_non_region_infer && lhs_evaluation.must_apply_considering_regions()
2017            }
2018            None => false,
2019        }
2020    }
2021}
2022
2023impl<'tcx> SelectionContext<'_, 'tcx> {
2024    fn sizedness_conditions(
2025        &mut self,
2026        self_ty: Ty<'tcx>,
2027        sizedness: SizedTraitKind,
2028    ) -> ty::Binder<'tcx, Vec<Ty<'tcx>>> {
2029        match self_ty.kind() {
2030            ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
2031            | ty::Uint(_)
2032            | ty::Int(_)
2033            | ty::Bool
2034            | ty::Float(_)
2035            | ty::FnDef(..)
2036            | ty::FnPtr(..)
2037            | ty::RawPtr(..)
2038            | ty::Char
2039            | ty::Ref(..)
2040            | ty::Coroutine(..)
2041            | ty::CoroutineWitness(..)
2042            | ty::Array(..)
2043            | ty::Closure(..)
2044            | ty::CoroutineClosure(..)
2045            | ty::Never
2046            | ty::Error(_) => ty::Binder::dummy(::alloc::vec::Vec::new()vec![]),
2047
2048            ty::Str | ty::Slice(_) | ty::Dynamic(..) => match sizedness {
2049                SizedTraitKind::Sized => {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("tried to assemble `Sized` for unsized type")));
}unreachable!("tried to assemble `Sized` for unsized type"),
2050                SizedTraitKind::MetaSized => ty::Binder::dummy(::alloc::vec::Vec::new()vec![]),
2051            },
2052
2053            ty::Foreign(..) => {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("tried to assemble `Sized` for unsized type")));
}unreachable!("tried to assemble `Sized` for unsized type"),
2054
2055            ty::Tuple(tys) => {
2056                ty::Binder::dummy(tys.last().map_or_else(Vec::new, |&last| ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [last]))vec![last]))
2057            }
2058
2059            ty::Pat(ty, _) => ty::Binder::dummy(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [*ty]))vec![*ty]),
2060
2061            ty::Adt(def, args) => {
2062                if let Some(crit) = def.sizedness_constraint(self.tcx(), sizedness) {
2063                    ty::Binder::dummy(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [crit.instantiate(self.tcx(), args).skip_norm_wip()]))vec![crit.instantiate(self.tcx(), args).skip_norm_wip()])
2064                } else {
2065                    ty::Binder::dummy(::alloc::vec::Vec::new()vec![])
2066                }
2067            }
2068
2069            ty::UnsafeBinder(binder_ty) => binder_ty.map_bound(|ty| ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [ty]))vec![ty]),
2070
2071            ty::Alias(..)
2072            | ty::Param(_)
2073            | ty::Placeholder(..)
2074            | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
2075            | ty::Bound(..) => {
2076                ::rustc_span::macros::bug_impl(None,
    format_args!("asked to assemble `Sized` of unexpected type: {0:?}",
        self_ty), Location::caller());bug!("asked to assemble `Sized` of unexpected type: {:?}", self_ty);
2077            }
2078        }
2079    }
2080
2081    fn copy_clone_conditions(&mut self, self_ty: Ty<'tcx>) -> ty::Binder<'tcx, Vec<Ty<'tcx>>> {
2082        match *self_ty.kind() {
2083            ty::FnDef(..) | ty::FnPtr(..) | ty::Error(_) => ty::Binder::dummy(::alloc::vec::Vec::new()vec![]),
2084
2085            ty::Uint(_)
2086            | ty::Int(_)
2087            | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
2088            | ty::Bool
2089            | ty::Float(_)
2090            | ty::Char
2091            | ty::RawPtr(..)
2092            | ty::Never
2093            | ty::Ref(_, _, hir::Mutability::Not)
2094            | ty::Array(..) => {
2095                {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("tried to assemble `Sized` for type with libcore-provided impl")));
}unreachable!("tried to assemble `Sized` for type with libcore-provided impl")
2096            }
2097
2098            // FIXME(unsafe_binder): Should we conditionally
2099            // (i.e. universally) implement copy/clone?
2100            ty::UnsafeBinder(_) => {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("tried to assemble `Sized` for unsafe binder")));
}unreachable!("tried to assemble `Sized` for unsafe binder"),
2101
2102            ty::Tuple(tys) => {
2103                // (*) binder moved here
2104                ty::Binder::dummy(tys.iter().collect())
2105            }
2106
2107            ty::Pat(ty, _) => {
2108                // (*) binder moved here
2109                ty::Binder::dummy(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [ty]))vec![ty])
2110            }
2111
2112            ty::Coroutine(def_id, args) => match self.tcx().coroutine_movability(def_id) {
2113                hir::Movability::Static => {
2114                    {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("tried to assemble `Clone` for static coroutine")));
}unreachable!("tried to assemble `Clone` for static coroutine")
2115                }
2116                hir::Movability::Movable => {
2117                    if self.tcx().features().coroutine_clone() {
2118                        ty::Binder::dummy(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [args.as_coroutine().tupled_upvars_ty(),
                Ty::new_coroutine_witness_for_coroutine(self.tcx(), def_id,
                    args)]))vec![
2119                            args.as_coroutine().tupled_upvars_ty(),
2120                            Ty::new_coroutine_witness_for_coroutine(self.tcx(), def_id, args),
2121                        ])
2122                    } else {
2123                        {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("tried to assemble `Clone` for coroutine without enabled feature")));
}unreachable!(
2124                            "tried to assemble `Clone` for coroutine without enabled feature"
2125                        )
2126                    }
2127                }
2128            },
2129
2130            ty::CoroutineWitness(def_id, args) => self
2131                .infcx
2132                .tcx
2133                .coroutine_hidden_types(def_id)
2134                .instantiate(self.infcx.tcx, args)
2135                .skip_norm_wip()
2136                .map_bound(|witness| witness.types.to_vec()),
2137
2138            ty::Closure(_, args) => ty::Binder::dummy(args.as_closure().upvar_tys().to_vec()),
2139
2140            ty::CoroutineClosure(_, args) => {
2141                ty::Binder::dummy(args.as_coroutine_closure().upvar_tys().to_vec())
2142            }
2143
2144            ty::Foreign(..)
2145            | ty::Str
2146            | ty::Slice(_)
2147            | ty::Dynamic(..)
2148            | ty::Adt(..)
2149            | ty::Alias(..)
2150            | ty::Param(..)
2151            | ty::Placeholder(..)
2152            | ty::Bound(..)
2153            | ty::Ref(_, _, ty::Mutability::Mut)
2154            | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
2155                ::rustc_span::macros::bug_impl(None,
    format_args!("asked to assemble builtin bounds of unexpected type: {0:?}",
        self_ty), Location::caller());bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
2156            }
2157        }
2158    }
2159
2160    fn coroutine_is_gen(&mut self, self_ty: Ty<'tcx>) -> bool {
2161        #[allow(non_exhaustive_omitted_patterns)] match *self_ty.kind() {
    ty::Coroutine(did, ..) if self.tcx().coroutine_is_gen(did) => true,
    _ => false,
}matches!(*self_ty.kind(), ty::Coroutine(did, ..)
2162            if self.tcx().coroutine_is_gen(did))
2163    }
2164
2165    /// For default impls, we need to break apart a type into its
2166    /// "constituent types" -- meaning, the types that it contains.
2167    ///
2168    /// Here are some (simple) examples:
2169    ///
2170    /// ```ignore (illustrative)
2171    /// (i32, u32) -> [i32, u32]
2172    /// Foo where struct Foo { x: i32, y: u32 } -> [i32, u32]
2173    /// Bar<i32> where struct Bar<T> { x: T, y: u32 } -> [i32, u32]
2174    /// Zed<i32> where enum Zed { A(T), B(u32) } -> [i32, u32]
2175    /// ```
2176    {}
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("constituent_types_for_auto_trait",
                                "rustc_trait_selection::traits::select",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(2176u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("t")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("t");
                                                    NAME.as_str()
                                                }], ::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};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&t)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return:
                                Result<ty::Binder<'tcx, AutoImplConstituents<'tcx>>,
                                SelectionError<'tcx>> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        Ok(match *t.kind() {
                                ty::Uint(_) | ty::Int(_) | ty::Bool | ty::Float(_) |
                                    ty::FnDef(..) | ty::FnPtr(..) | ty::Error(_) |
                                    ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | ty::Never |
                                    ty::Char => {
                                    ty::Binder::dummy(AutoImplConstituents {
                                            types: ::alloc::vec::Vec::new(),
                                            assumptions: ::alloc::vec::Vec::new(),
                                        })
                                }
                                ty::Foreign(..) => {
                                    ty::Binder::dummy(AutoImplConstituents {
                                            types: ::alloc::vec::Vec::new(),
                                            assumptions: ::alloc::vec::Vec::new(),
                                        })
                                }
                                ty::UnsafeBinder(ty) => {
                                    ty.map_bound(|ty|
                                            AutoImplConstituents {
                                                types: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                                        [ty])),
                                                assumptions: ::alloc::vec::Vec::new(),
                                            })
                                }
                                ty::Str =>
                                    ty::Binder::dummy(AutoImplConstituents {
                                            types: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                                    [Ty::new_slice(self.tcx(), self.tcx().types.u8)])),
                                            assumptions: ::alloc::vec::Vec::new(),
                                        }),
                                ty::Placeholder(..) | ty::Dynamic(..) | ty::Param(..) |
                                    ty::Alias(_, ty::AliasTy {
                                    kind: ty::Projection { .. } | ty::Inherent { .. } |
                                        ty::Free { .. }, .. }) | ty::Bound(..) |
                                    ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_)
                                    | ty::FreshFloatTy(_)) => {
                                    ::rustc_span::macros::bug_impl(None,
                                        format_args!("asked to assemble constituent types of unexpected type: {0:?}",
                                            t), Location::caller());
                                }
                                ty::RawPtr(element_ty, _) | ty::Ref(_, element_ty, _) => {
                                    ty::Binder::dummy(AutoImplConstituents {
                                            types: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                                    [element_ty])),
                                            assumptions: ::alloc::vec::Vec::new(),
                                        })
                                }
                                ty::Pat(ty, _) | ty::Array(ty, _) | ty::Slice(ty) => {
                                    ty::Binder::dummy(AutoImplConstituents {
                                            types: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                                    [ty])),
                                            assumptions: ::alloc::vec::Vec::new(),
                                        })
                                }
                                ty::Tuple(tys) => {
                                    ty::Binder::dummy(AutoImplConstituents {
                                            types: tys.iter().collect(),
                                            assumptions: ::alloc::vec::Vec::new(),
                                        })
                                }
                                ty::Closure(_, args) => {
                                    let ty =
                                        self.infcx.shallow_resolve(args.as_closure().tupled_upvars_ty());
                                    ty::Binder::dummy(AutoImplConstituents {
                                            types: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                                    [ty])),
                                            assumptions: ::alloc::vec::Vec::new(),
                                        })
                                }
                                ty::CoroutineClosure(_, args) => {
                                    let ty =
                                        self.infcx.shallow_resolve(args.as_coroutine_closure().tupled_upvars_ty());
                                    ty::Binder::dummy(AutoImplConstituents {
                                            types: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                                    [ty])),
                                            assumptions: ::alloc::vec::Vec::new(),
                                        })
                                }
                                ty::Coroutine(def_id, args) => {
                                    let ty =
                                        self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
                                    let tcx = self.tcx();
                                    let witness =
                                        Ty::new_coroutine_witness_for_coroutine(tcx, def_id, args);
                                    ty::Binder::dummy(AutoImplConstituents {
                                            types: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                                    [ty, witness])),
                                            assumptions: ::alloc::vec::Vec::new(),
                                        })
                                }
                                ty::CoroutineWitness(def_id, args) =>
                                    self.infcx.tcx.coroutine_hidden_types(def_id).instantiate(self.infcx.tcx,
                                                args).skip_norm_wip().map_bound(|witness|
                                            AutoImplConstituents {
                                                types: witness.types.to_vec(),
                                                assumptions: witness.assumptions.to_vec(),
                                            }),
                                ty::Adt(def, args) if def.is_phantom_data() => {
                                    ty::Binder::dummy(AutoImplConstituents {
                                            types: args.types().collect(),
                                            assumptions: ::alloc::vec::Vec::new(),
                                        })
                                }
                                ty::Adt(def, args) =>
                                    ty::Binder::dummy(AutoImplConstituents {
                                            types: def.all_fields().map(|f|
                                                        f.ty(self.tcx(), args).skip_norm_wip()).collect(),
                                            assumptions: ::alloc::vec::Vec::new(),
                                        }),
                                ty::Alias(_, ty::AliasTy {
                                    kind: ty::Opaque { def_id }, args, .. }) => {
                                    if self.infcx.can_define_opaque_ty(def_id) {
                                        ::core::panicking::panic("internal error: entered unreachable code")
                                    } else {
                                        let ty = self.tcx().type_of_opaque(def_id);
                                        ty::Binder::dummy(AutoImplConstituents {
                                                types: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                                        [ty.instantiate(self.tcx(), args).skip_norm_wip()])),
                                                assumptions: ::alloc::vec::Vec::new(),
                                            })
                                    }
                                }
                            })
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:2176",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2176u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
2177    fn constituent_types_for_auto_trait(
2178        &self,
2179        t: Ty<'tcx>,
2180    ) -> Result<ty::Binder<'tcx, AutoImplConstituents<'tcx>>, SelectionError<'tcx>> {
2181        Ok(match *t.kind() {
2182            ty::Uint(_)
2183            | ty::Int(_)
2184            | ty::Bool
2185            | ty::Float(_)
2186            | ty::FnDef(..)
2187            | ty::FnPtr(..)
2188            | ty::Error(_)
2189            | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
2190            | ty::Never
2191            | ty::Char => {
2192                ty::Binder::dummy(AutoImplConstituents { types: vec![], assumptions: vec![] })
2193            }
2194
2195            // This branch is only for `experimental_default_bounds`.
2196            // Other foreign types were rejected earlier in
2197            // `assemble_candidates_from_auto_impls`.
2198            ty::Foreign(..) => {
2199                ty::Binder::dummy(AutoImplConstituents { types: vec![], assumptions: vec![] })
2200            }
2201
2202            ty::UnsafeBinder(ty) => {
2203                ty.map_bound(|ty| AutoImplConstituents { types: vec![ty], assumptions: vec![] })
2204            }
2205
2206            // Treat this like `struct str([u8]);`
2207            ty::Str => ty::Binder::dummy(AutoImplConstituents {
2208                types: vec![Ty::new_slice(self.tcx(), self.tcx().types.u8)],
2209                assumptions: vec![],
2210            }),
2211
2212            ty::Placeholder(..)
2213            | ty::Dynamic(..)
2214            | ty::Param(..)
2215            | ty::Alias(
2216                _,
2217                ty::AliasTy {
2218                    kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. },
2219                    ..
2220                },
2221            )
2222            | ty::Bound(..)
2223            | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
2224                bug!("asked to assemble constituent types of unexpected type: {:?}", t);
2225            }
2226
2227            ty::RawPtr(element_ty, _) | ty::Ref(_, element_ty, _) => {
2228                ty::Binder::dummy(AutoImplConstituents {
2229                    types: vec![element_ty],
2230                    assumptions: vec![],
2231                })
2232            }
2233
2234            ty::Pat(ty, _) | ty::Array(ty, _) | ty::Slice(ty) => {
2235                ty::Binder::dummy(AutoImplConstituents { types: vec![ty], assumptions: vec![] })
2236            }
2237
2238            ty::Tuple(tys) => {
2239                // (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
2240                ty::Binder::dummy(AutoImplConstituents {
2241                    types: tys.iter().collect(),
2242                    assumptions: vec![],
2243                })
2244            }
2245
2246            ty::Closure(_, args) => {
2247                let ty = self.infcx.shallow_resolve(args.as_closure().tupled_upvars_ty());
2248                ty::Binder::dummy(AutoImplConstituents { types: vec![ty], assumptions: vec![] })
2249            }
2250
2251            ty::CoroutineClosure(_, args) => {
2252                let ty = self.infcx.shallow_resolve(args.as_coroutine_closure().tupled_upvars_ty());
2253                ty::Binder::dummy(AutoImplConstituents { types: vec![ty], assumptions: vec![] })
2254            }
2255
2256            ty::Coroutine(def_id, args) => {
2257                let ty = self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
2258                let tcx = self.tcx();
2259                let witness = Ty::new_coroutine_witness_for_coroutine(tcx, def_id, args);
2260                ty::Binder::dummy(AutoImplConstituents {
2261                    types: vec![ty, witness],
2262                    assumptions: vec![],
2263                })
2264            }
2265
2266            ty::CoroutineWitness(def_id, args) => self
2267                .infcx
2268                .tcx
2269                .coroutine_hidden_types(def_id)
2270                .instantiate(self.infcx.tcx, args)
2271                .skip_norm_wip()
2272                .map_bound(|witness| AutoImplConstituents {
2273                    types: witness.types.to_vec(),
2274                    assumptions: witness.assumptions.to_vec(),
2275                }),
2276
2277            // For `PhantomData<T>`, we pass `T`.
2278            ty::Adt(def, args) if def.is_phantom_data() => {
2279                ty::Binder::dummy(AutoImplConstituents {
2280                    types: args.types().collect(),
2281                    assumptions: vec![],
2282                })
2283            }
2284
2285            ty::Adt(def, args) => ty::Binder::dummy(AutoImplConstituents {
2286                types: def.all_fields().map(|f| f.ty(self.tcx(), args).skip_norm_wip()).collect(),
2287                assumptions: vec![],
2288            }),
2289
2290            ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => {
2291                if self.infcx.can_define_opaque_ty(def_id) {
2292                    unreachable!()
2293                } else {
2294                    // We can resolve the opaque type to its hidden type,
2295                    // which enforces a DAG between the functions requiring
2296                    // the auto trait bounds in question.
2297                    let ty = self.tcx().type_of_opaque(def_id);
2298                    ty::Binder::dummy(AutoImplConstituents {
2299                        types: vec![ty.instantiate(self.tcx(), args).skip_norm_wip()],
2300                        assumptions: vec![],
2301                    })
2302                }
2303            }
2304        })
2305    }
2306
2307    fn collect_predicates_for_types(
2308        &mut self,
2309        param_env: ty::ParamEnv<'tcx>,
2310        cause: ObligationCause<'tcx>,
2311        recursion_depth: usize,
2312        trait_def_id: DefId,
2313        types: Vec<Ty<'tcx>>,
2314    ) -> PredicateObligations<'tcx> {
2315        // Because the types were potentially derived from
2316        // higher-ranked obligations they may reference late-bound
2317        // regions. For example, `for<'a> Foo<&'a i32> : Copy` would
2318        // yield a type like `for<'a> &'a i32`. In general, we
2319        // maintain the invariant that we never manipulate bound
2320        // regions, so we have to process these bound regions somehow.
2321        //
2322        // The strategy is to:
2323        //
2324        // 1. Instantiate those regions to placeholder regions (e.g.,
2325        //    `for<'a> &'a i32` becomes `&0 i32`.
2326        // 2. Produce something like `&'0 i32 : Copy`
2327        // 3. Re-bind the regions back to `for<'a> &'a i32 : Copy`
2328
2329        types
2330            .into_iter()
2331            .flat_map(|placeholder_ty| {
2332                let Normalized { value: normalized_ty, mut obligations } = normalize_with_depth(
2333                    self,
2334                    param_env,
2335                    cause.clone(),
2336                    recursion_depth,
2337                    Unnormalized::new_wip(placeholder_ty),
2338                );
2339
2340                let tcx = self.tcx();
2341                let trait_ref = if tcx.generics_of(trait_def_id).own_params.len() == 1 {
2342                    ty::TraitRef::new(tcx, trait_def_id, [normalized_ty])
2343                } else {
2344                    // If this is an ill-formed auto/built-in trait, then synthesize
2345                    // new error args for the missing generics.
2346                    let err_args = ty::GenericArgs::extend_with_error(
2347                        tcx,
2348                        trait_def_id,
2349                        &[normalized_ty.into()],
2350                    );
2351                    ty::TraitRef::new_from_args(tcx, trait_def_id, err_args)
2352                };
2353
2354                let obligation = Obligation::new(self.tcx(), cause.clone(), param_env, trait_ref);
2355                obligations.push(obligation);
2356                obligations
2357            })
2358            .collect()
2359    }
2360
2361    ///////////////////////////////////////////////////////////////////////////
2362    // Matching
2363    //
2364    // Matching is a common path used for both evaluation and
2365    // confirmation. It basically unifies types that appear in impls
2366    // and traits. This does affect the surrounding environment;
2367    // therefore, when used during evaluation, match routines must be
2368    // run inside of a `probe()` so that their side-effects are
2369    // contained.
2370
2371    fn rematch_impl(
2372        &mut self,
2373        impl_def_id: DefId,
2374        obligation: &PolyTraitObligation<'tcx>,
2375    ) -> Normalized<'tcx, GenericArgsRef<'tcx>> {
2376        let impl_trait_header = self.tcx().impl_trait_header(impl_def_id);
2377        match self.match_impl(impl_def_id, impl_trait_header, obligation) {
2378            Ok(args) => args,
2379            Err(()) => {
2380                let predicate = self.infcx.deeply_resolve_ignoring_regions(obligation.predicate);
2381                ::rustc_span::macros::bug_impl(None,
    format_args!("impl {0:?} was matchable against {1:?} but now is not",
        impl_def_id, predicate), Location::caller())bug!("impl {impl_def_id:?} was matchable against {predicate:?} but now is not")
2382            }
2383        }
2384    }
2385
2386    {}
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("match_impl",
                                "rustc_trait_selection::traits::select",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(2386u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("impl_def_id")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("impl_def_id");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("impl_trait_header")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("impl_trait_header");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("obligation")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("obligation");
                                                    NAME.as_str()
                                                }], ::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};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_def_id)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_trait_header)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return:
                                Result<Normalized<'tcx, GenericArgsRef<'tcx>>, ()> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let placeholder_obligation =
                            self.infcx.enter_forall_and_leak_universe(obligation.predicate);
                        let placeholder_obligation_trait_ref =
                            placeholder_obligation.trait_ref;
                        let impl_args =
                            self.infcx.fresh_args_for_item(obligation.cause.span,
                                impl_def_id);
                        let trait_ref =
                            impl_trait_header.trait_ref.instantiate(self.tcx(),
                                impl_args);
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:2400",
                                                "rustc_trait_selection::traits::select",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(2400u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("impl_trait_header")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("impl_trait_header");
                                                                    NAME.as_str()
                                                                }], ::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};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_trait_header)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let mut nested_obligations = PredicateObligations::new();
                        let impl_trait_ref =
                            normalize_with_depth_to(self, obligation.param_env,
                                obligation.cause.clone(), obligation.recursion_depth + 1,
                                trait_ref, &mut nested_obligations);
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:2412",
                                                "rustc_trait_selection::traits::select",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(2412u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("impl_trait_ref")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("impl_trait_ref");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("placeholder_obligation_trait_ref")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("placeholder_obligation_trait_ref");
                                                                    NAME.as_str()
                                                                }], ::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};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_trait_ref)
                                                                    as &dyn ::tracing::field::Value)),
                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&placeholder_obligation_trait_ref)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let cause =
                            ObligationCause::new(obligation.cause.span,
                                obligation.cause.body_def_id,
                                ObligationCauseCode::MatchImpl(obligation.cause.clone(),
                                    impl_def_id));
                        let InferOk { obligations, .. } =
                            self.infcx.at(&cause,
                                            obligation.param_env).eq(DefineOpaqueTypes::No,
                                        placeholder_obligation_trait_ref,
                                        impl_trait_ref).map_err(|e|
                                        {
                                            {
                                                use ::tracing::__macro_support::Callsite as _;
                                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                                    {
                                                        static META: ::tracing::Metadata<'static> =
                                                            {
                                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:2425",
                                                                    "rustc_trait_selection::traits::select",
                                                                    ::tracing::Level::DEBUG,
                                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                                    ::tracing_core::__macro_support::Option::Some(2425u32),
                                                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                                    ::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};
                                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("match_impl: failed eq_trait_refs due to `{0}`",
                                                                                                e.to_string(self.tcx())) as &dyn ::tracing::field::Value))])
                                                        });
                                                } else { ; }
                                            }
                                        })?;
                        nested_obligations.extend(obligations);
                        match self.typing_mode() {
                            TypingMode::Reflection if
                                !self.tcx().impl_is_fully_generic_for_reflection(impl_def_id)
                                => {
                                {
                                    use ::tracing::__macro_support::Callsite as _;
                                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                        {
                                            static META: ::tracing::Metadata<'static> =
                                                {
                                                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:2433",
                                                        "rustc_trait_selection::traits::select",
                                                        ::tracing::Level::DEBUG,
                                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                                        ::tracing_core::__macro_support::Option::Some(2433u32),
                                                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                                        ::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};
                                                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("reflection mode only allows fully generic impls")
                                                                            as &dyn ::tracing::field::Value))])
                                            });
                                    } else { ; }
                                };
                                return Err(());
                            }
                            TypingMode::Typeck { .. } |
                                TypingMode::PostTypeckThroughBorrowck { .. } |
                                TypingMode::PostBorrowck { .. } | TypingMode::Codegen |
                                TypingMode::ErasedNotCoherence(_) | TypingMode::Reflection |
                                TypingMode::PostAnalysis => {}
                            TypingMode::Coherence => {
                                {
                                    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
                                            format_args!("old solver coherence")));
                                }
                            }
                        }
                        Ok(Normalized {
                                value: impl_args,
                                obligations: nested_obligations,
                            })
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:2386",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2386u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
2387    fn match_impl(
2388        &mut self,
2389        impl_def_id: DefId,
2390        impl_trait_header: ty::ImplTraitHeader<'tcx>,
2391        obligation: &PolyTraitObligation<'tcx>,
2392    ) -> Result<Normalized<'tcx, GenericArgsRef<'tcx>>, ()> {
2393        let placeholder_obligation =
2394            self.infcx.enter_forall_and_leak_universe(obligation.predicate);
2395        let placeholder_obligation_trait_ref = placeholder_obligation.trait_ref;
2396
2397        let impl_args = self.infcx.fresh_args_for_item(obligation.cause.span, impl_def_id);
2398
2399        let trait_ref = impl_trait_header.trait_ref.instantiate(self.tcx(), impl_args);
2400        debug!(?impl_trait_header);
2401
2402        let mut nested_obligations = PredicateObligations::new();
2403        let impl_trait_ref = normalize_with_depth_to(
2404            self,
2405            obligation.param_env,
2406            obligation.cause.clone(),
2407            obligation.recursion_depth + 1,
2408            trait_ref,
2409            &mut nested_obligations,
2410        );
2411
2412        debug!(?impl_trait_ref, ?placeholder_obligation_trait_ref);
2413
2414        let cause = ObligationCause::new(
2415            obligation.cause.span,
2416            obligation.cause.body_def_id,
2417            ObligationCauseCode::MatchImpl(obligation.cause.clone(), impl_def_id),
2418        );
2419
2420        let InferOk { obligations, .. } = self
2421            .infcx
2422            .at(&cause, obligation.param_env)
2423            .eq(DefineOpaqueTypes::No, placeholder_obligation_trait_ref, impl_trait_ref)
2424            .map_err(|e| {
2425                debug!("match_impl: failed eq_trait_refs due to `{}`", e.to_string(self.tcx()))
2426            })?;
2427        nested_obligations.extend(obligations);
2428
2429        match self.typing_mode() {
2430            TypingMode::Reflection
2431                if !self.tcx().impl_is_fully_generic_for_reflection(impl_def_id) =>
2432            {
2433                debug!("reflection mode only allows fully generic impls");
2434                return Err(());
2435            }
2436
2437            TypingMode::Typeck { .. }
2438            | TypingMode::PostTypeckThroughBorrowck { .. }
2439            | TypingMode::PostBorrowck { .. }
2440            | TypingMode::Codegen
2441            | TypingMode::ErasedNotCoherence(_)
2442            | TypingMode::Reflection
2443            | TypingMode::PostAnalysis => {}
2444            TypingMode::Coherence => {
2445                unreachable!("old solver coherence")
2446            }
2447        }
2448
2449        Ok(Normalized { value: impl_args, obligations: nested_obligations })
2450    }
2451
2452    fn match_upcast_principal(
2453        &mut self,
2454        obligation: &PolyTraitObligation<'tcx>,
2455        unnormalized_upcast_principal: ty::Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>,
2456        a_data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
2457        b_data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
2458        a_region: ty::Region<'tcx>,
2459        b_region: ty::Region<'tcx>,
2460    ) -> SelectionResult<'tcx, PredicateObligations<'tcx>> {
2461        let tcx = self.tcx();
2462        let mut nested = PredicateObligations::new();
2463
2464        // We may upcast to auto traits that are either explicitly listed in
2465        // the object type's bounds, or implied by the principal trait ref's
2466        // supertraits.
2467        let a_auto_traits: FxIndexSet<DefId> = a_data
2468            .auto_traits()
2469            .chain(
2470                a_data
2471                    .principal_def_id()
2472                    .map(|principal_def_id| {
2473                        elaborate::supertrait_def_ids(tcx, principal_def_id)
2474                            .filter(|def_id| tcx.trait_is_auto(*def_id))
2475                    })
2476                    .into_flat_iter(),
2477            )
2478            .collect();
2479
2480        let upcast_principal = normalize_with_depth_to(
2481            self,
2482            obligation.param_env,
2483            obligation.cause.clone(),
2484            obligation.recursion_depth + 1,
2485            unnormalized_upcast_principal,
2486            &mut nested,
2487        );
2488
2489        for bound in b_data {
2490            match bound.skip_binder() {
2491                // Check that a_ty's supertrait (upcast_principal) is compatible
2492                // with the target (b_ty).
2493                ty::ExistentialPredicate::Trait(target_principal) => {
2494                    let hr_source_principal = upcast_principal.map_bound(|trait_ref| {
2495                        ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
2496                    });
2497                    let hr_target_principal = bound.rebind(target_principal);
2498
2499                    nested.extend(
2500                        self.infcx
2501                            .enter_forall(hr_target_principal, |target_principal| {
2502                                let source_principal =
2503                                    self.infcx.instantiate_binder_with_fresh_vars(
2504                                        obligation.cause.span,
2505                                        HigherRankedType,
2506                                        hr_source_principal,
2507                                    );
2508                                self.infcx.at(&obligation.cause, obligation.param_env).eq_trace(
2509                                    DefineOpaqueTypes::Yes,
2510                                    ToTrace::to_trace(
2511                                        &obligation.cause,
2512                                        hr_target_principal,
2513                                        hr_source_principal,
2514                                    ),
2515                                    target_principal,
2516                                    source_principal,
2517                                )
2518                            })
2519                            .map_err(|_| SelectionError::Unimplemented)?
2520                            .into_obligations(),
2521                    );
2522                }
2523                // Check that b_ty's projection is satisfied by exactly one of
2524                // a_ty's projections. First, we look through the list to see if
2525                // any match. If not, error. Then, if *more* than one matches, we
2526                // return ambiguity. Otherwise, if exactly one matches, equate
2527                // it with b_ty's projection.
2528                ty::ExistentialPredicate::Projection(target_projection) => {
2529                    let hr_target_projection = bound.rebind(target_projection);
2530
2531                    let mut matching_projections =
2532                        a_data.projection_bounds().filter(|&hr_source_projection| {
2533                            // Eager normalization means that we can just use can_eq
2534                            // here instead of equating and processing obligations.
2535                            hr_source_projection.item_def_id() == hr_target_projection.item_def_id()
2536                                && self.infcx.probe(|_| {
2537                                    self.infcx
2538                                        .enter_forall(hr_target_projection, |target_projection| {
2539                                            let source_projection =
2540                                                self.infcx.instantiate_binder_with_fresh_vars(
2541                                                    obligation.cause.span,
2542                                                    HigherRankedType,
2543                                                    hr_source_projection,
2544                                                );
2545                                            self.infcx
2546                                                .at(&obligation.cause, obligation.param_env)
2547                                                .eq_trace(
2548                                                    DefineOpaqueTypes::Yes,
2549                                                    ToTrace::to_trace(
2550                                                        &obligation.cause,
2551                                                        hr_target_projection,
2552                                                        hr_source_projection,
2553                                                    ),
2554                                                    target_projection,
2555                                                    source_projection,
2556                                                )
2557                                        })
2558                                        .is_ok()
2559                                })
2560                        });
2561
2562                    let Some(hr_source_projection) = matching_projections.next() else {
2563                        return Err(SelectionError::Unimplemented);
2564                    };
2565                    if matching_projections.next().is_some() {
2566                        return Ok(None);
2567                    }
2568                    nested.extend(
2569                        self.infcx
2570                            .enter_forall(hr_target_projection, |target_projection| {
2571                                let source_projection =
2572                                    self.infcx.instantiate_binder_with_fresh_vars(
2573                                        obligation.cause.span,
2574                                        HigherRankedType,
2575                                        hr_source_projection,
2576                                    );
2577                                self.infcx.at(&obligation.cause, obligation.param_env).eq_trace(
2578                                    DefineOpaqueTypes::Yes,
2579                                    ToTrace::to_trace(
2580                                        &obligation.cause,
2581                                        hr_target_projection,
2582                                        hr_source_projection,
2583                                    ),
2584                                    target_projection,
2585                                    source_projection,
2586                                )
2587                            })
2588                            .map_err(|_| SelectionError::Unimplemented)?
2589                            .into_obligations(),
2590                    );
2591                }
2592                // Check that b_ty's auto traits are present in a_ty's bounds.
2593                ty::ExistentialPredicate::AutoTrait(def_id) => {
2594                    if !a_auto_traits.contains(&def_id) {
2595                        return Err(SelectionError::Unimplemented);
2596                    }
2597                }
2598            }
2599        }
2600
2601        nested.push(Obligation::with_depth(
2602            tcx,
2603            obligation.cause.clone(),
2604            obligation.recursion_depth + 1,
2605            obligation.param_env,
2606            ty::Binder::dummy(ty::OutlivesClause(a_region, b_region)),
2607        ));
2608
2609        Ok(Some(nested))
2610    }
2611
2612    /// Normalize `where_clause_trait_ref` and try to match it against
2613    /// `obligation`. If successful, return any predicates that
2614    /// result from the normalization.
2615    fn match_where_clause_trait_ref(
2616        &mut self,
2617        obligation: &PolyTraitObligation<'tcx>,
2618        where_clause_trait_ref: ty::PolyTraitRef<'tcx>,
2619    ) -> Result<PredicateObligations<'tcx>, ()> {
2620        self.match_poly_trait_ref(obligation, where_clause_trait_ref)
2621    }
2622
2623    /// Returns `Ok` if `poly_trait_ref` being true implies that the
2624    /// obligation is satisfied.
2625    {}
#[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("match_poly_trait_ref",
                                    "rustc_trait_selection::traits::select",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2625u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("obligation")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("obligation");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("poly_trait_ref")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("poly_trait_ref");
                                                        NAME.as_str()
                                                    }], ::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};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&poly_trait_ref)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return:
                    Result<PredicateObligations<'tcx>, ()> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let predicate =
                self.infcx.enter_forall_and_leak_universe(obligation.predicate);
            let trait_ref =
                self.infcx.instantiate_binder_with_fresh_vars(obligation.cause.span,
                    HigherRankedType, poly_trait_ref);
            self.infcx.at(&obligation.cause,
                            obligation.param_env).eq(DefineOpaqueTypes::No,
                        predicate.trait_ref,
                        trait_ref).map(|InferOk { obligations, .. }|
                        obligations).map_err(|_| ())
        }
    }
}#[instrument(skip(self), level = "debug")]
2626    fn match_poly_trait_ref(
2627        &mut self,
2628        obligation: &PolyTraitObligation<'tcx>,
2629        poly_trait_ref: ty::PolyTraitRef<'tcx>,
2630    ) -> Result<PredicateObligations<'tcx>, ()> {
2631        let predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
2632        let trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
2633            obligation.cause.span,
2634            HigherRankedType,
2635            poly_trait_ref,
2636        );
2637        self.infcx
2638            .at(&obligation.cause, obligation.param_env)
2639            .eq(DefineOpaqueTypes::No, predicate.trait_ref, trait_ref)
2640            .map(|InferOk { obligations, .. }| obligations)
2641            .map_err(|_| ())
2642    }
2643
2644    ///////////////////////////////////////////////////////////////////////////
2645    // Miscellany
2646
2647    fn match_fresh_trait_preds(
2648        &self,
2649        previous: ty::PolyTraitClause<'tcx>,
2650        current: ty::PolyTraitClause<'tcx>,
2651    ) -> bool {
2652        let mut matcher = _match::MatchAgainstFreshVars::new(self.tcx());
2653        matcher.relate(previous, current).is_ok()
2654    }
2655
2656    fn push_stack<'o>(
2657        &mut self,
2658        previous_stack: TraitObligationStackList<'o, 'tcx>,
2659        obligation: &'o PolyTraitObligation<'tcx>,
2660    ) -> TraitObligationStack<'o, 'tcx> {
2661        let fresh_trait_pred = obligation.predicate.fold_with(&mut self.freshener);
2662
2663        let dfn = previous_stack.cache.next_dfn();
2664        let depth = previous_stack.depth() + 1;
2665        TraitObligationStack {
2666            obligation,
2667            fresh_trait_pred,
2668            reached_depth: Cell::new(depth),
2669            previous: previous_stack,
2670            dfn,
2671            depth,
2672        }
2673    }
2674
2675    {}
#[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("closure_trait_ref_unnormalized",
                                    "rustc_trait_selection::traits::select",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2675u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self_ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("fn_trait_def_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("fn_trait_def_id");
                                                        NAME.as_str()
                                                    }], ::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};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_trait_def_id)
                                                            as &dyn ::tracing::field::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: ty::PolyTraitRef<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let ty::Closure(_, args) =
                *self_ty.kind() else {
                    ::rustc_span::macros::bug_impl(None,
                        format_args!("expected closure, found {0}", self_ty),
                        Location::caller());
                };
            let closure_sig = args.as_closure().sig();
            closure_trait_ref_and_return_type(self.tcx(), fn_trait_def_id,
                    self_ty, closure_sig,
                    util::TupleArgumentsFlag::No).map_bound(|(trait_ref, _)|
                    trait_ref)
        }
    }
}#[instrument(skip(self), level = "debug")]
2676    fn closure_trait_ref_unnormalized(
2677        &mut self,
2678        self_ty: Ty<'tcx>,
2679        fn_trait_def_id: DefId,
2680    ) -> ty::PolyTraitRef<'tcx> {
2681        let ty::Closure(_, args) = *self_ty.kind() else {
2682            bug!("expected closure, found {self_ty}");
2683        };
2684        let closure_sig = args.as_closure().sig();
2685
2686        closure_trait_ref_and_return_type(
2687            self.tcx(),
2688            fn_trait_def_id,
2689            self_ty,
2690            closure_sig,
2691            util::TupleArgumentsFlag::No,
2692        )
2693        .map_bound(|(trait_ref, _)| trait_ref)
2694    }
2695
2696    /// Returns the obligations that are implied by instantiating an
2697    /// impl or trait. The obligations are instantiated and fully
2698    /// normalized. This is used when confirming an impl or default
2699    /// impl.
2700    {}
#[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("impl_or_trait_obligations",
                                    "rustc_trait_selection::traits::select",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2700u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("recursion_depth")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("recursion_depth");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("def_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("def_id");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("args")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("args");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("parent_trait_pred")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("parent_trait_pred");
                                                        NAME.as_str()
                                                    }], ::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};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&recursion_depth
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&parent_trait_pred)
                                                            as &dyn ::tracing::field::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: PredicateObligations<'tcx> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let tcx = self.tcx();
            let clauses = tcx.clauses_of(def_id);
            {
                match (&clauses.parent, &None) {
                    (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);
                        }
                    }
                }
            };
            let clauses = clauses.instantiate_own(tcx, args);
            let mut obligations =
                PredicateObligations::with_capacity(clauses.len());
            for (index, (clause, span)) in clauses.into_iter().enumerate() {
                let cause =
                    if tcx.is_lang_item(parent_trait_pred.def_id(),
                            LangItem::CoerceUnsized) {
                        cause.clone()
                    } else {
                        cause.clone().derived_cause(parent_trait_pred,
                            |derived|
                                {
                                    ObligationCauseCode::ImplDerived(Box::new(ImplDerivedCause {
                                                derived,
                                                impl_or_alias_def_id: def_id,
                                                impl_def_clause_index: Some(index),
                                                span,
                                            }))
                                })
                    };
                let clause =
                    normalize_with_depth_to(self, param_env, cause.clone(),
                        recursion_depth, clause, &mut obligations);
                obligations.push(Obligation {
                        cause,
                        recursion_depth,
                        param_env,
                        predicate: clause.as_predicate(),
                    });
            }
            if tcx.def_kind(def_id) == (DefKind::Impl { of_trait: true }) {
                for clause in
                    tcx.impl_super_outlives(def_id).iter_instantiated(tcx, args)
                    {
                    let clause =
                        normalize_with_depth_to(self, param_env, cause.clone(),
                            recursion_depth, clause, &mut obligations);
                    obligations.push(Obligation {
                            cause: cause.clone(),
                            recursion_depth,
                            param_env,
                            predicate: clause.as_predicate(),
                        });
                }
            }
            obligations
        }
    }
}#[instrument(level = "debug", skip(self, cause, param_env))]
2701    fn impl_or_trait_obligations(
2702        &mut self,
2703        cause: &ObligationCause<'tcx>,
2704        recursion_depth: usize,
2705        param_env: ty::ParamEnv<'tcx>,
2706        def_id: DefId,              // of impl or trait
2707        args: GenericArgsRef<'tcx>, // for impl or trait
2708        parent_trait_pred: ty::Binder<'tcx, ty::TraitClause<'tcx>>,
2709    ) -> PredicateObligations<'tcx> {
2710        let tcx = self.tcx();
2711
2712        // To allow for one-pass evaluation of the nested obligation,
2713        // each predicate must be preceded by the obligations required
2714        // to normalize it.
2715        // for example, if we have:
2716        //    impl<U: Iterator<Item: Copy>, V: Iterator<Item = U>> Foo for V
2717        // the impl will have the following predicates:
2718        //    <V as Iterator>::Item = U,
2719        //    U: Iterator, U: Sized,
2720        //    V: Iterator, V: Sized,
2721        //    <U as Iterator>::Item: Copy
2722        // When we instantiate, say, `V => IntoIter<u32>, U => $0`, the last
2723        // obligation will normalize to `<$0 as Iterator>::Item = $1` and
2724        // `$1: Copy`, so we must ensure the obligations are emitted in
2725        // that order.
2726        let clauses = tcx.clauses_of(def_id);
2727        assert_eq!(clauses.parent, None);
2728        let clauses = clauses.instantiate_own(tcx, args);
2729        let mut obligations = PredicateObligations::with_capacity(clauses.len());
2730        for (index, (clause, span)) in clauses.into_iter().enumerate() {
2731            let cause = if tcx.is_lang_item(parent_trait_pred.def_id(), LangItem::CoerceUnsized) {
2732                cause.clone()
2733            } else {
2734                cause.clone().derived_cause(parent_trait_pred, |derived| {
2735                    ObligationCauseCode::ImplDerived(Box::new(ImplDerivedCause {
2736                        derived,
2737                        impl_or_alias_def_id: def_id,
2738                        impl_def_clause_index: Some(index),
2739                        span,
2740                    }))
2741                })
2742            };
2743            let clause = normalize_with_depth_to(
2744                self,
2745                param_env,
2746                cause.clone(),
2747                recursion_depth,
2748                clause,
2749                &mut obligations,
2750            );
2751            obligations.push(Obligation {
2752                cause,
2753                recursion_depth,
2754                param_env,
2755                predicate: clause.as_predicate(),
2756            });
2757        }
2758
2759        // Register any outlives obligations from the trait here, cc #124336.
2760        if tcx.def_kind(def_id) == (DefKind::Impl { of_trait: true }) {
2761            for clause in tcx.impl_super_outlives(def_id).iter_instantiated(tcx, args) {
2762                let clause = normalize_with_depth_to(
2763                    self,
2764                    param_env,
2765                    cause.clone(),
2766                    recursion_depth,
2767                    clause,
2768                    &mut obligations,
2769                );
2770                obligations.push(Obligation {
2771                    cause: cause.clone(),
2772                    recursion_depth,
2773                    param_env,
2774                    predicate: clause.as_predicate(),
2775                });
2776            }
2777        }
2778
2779        obligations
2780    }
2781
2782    pub(super) fn should_stall_coroutine(&self, def_id: DefId) -> bool {
2783        match self.typing_mode() {
2784            TypingMode::Typeck { defining_opaque_types_and_generators: stalled_generators } => {
2785                def_id.as_local().is_some_and(|def_id| stalled_generators.contains(&def_id))
2786            }
2787            TypingMode::PostAnalysis
2788            | TypingMode::Reflection
2789            | TypingMode::Codegen
2790            | TypingMode::PostTypeckThroughBorrowck { defining_opaque_types: _ }
2791            | TypingMode::PostBorrowck { defined_opaque_types: _ } => false,
2792            TypingMode::Coherence => {
2793                {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("old solver coherence")));
}unreachable!("old solver coherence")
2794            }
2795        }
2796    }
2797}
2798
2799impl<'o, 'tcx> TraitObligationStack<'o, 'tcx> {
2800    fn list(&'o self) -> TraitObligationStackList<'o, 'tcx> {
2801        TraitObligationStackList::with(self)
2802    }
2803
2804    fn cache(&self) -> &'o ProvisionalEvaluationCache<'tcx> {
2805        self.previous.cache
2806    }
2807
2808    fn iter(&'o self) -> TraitObligationStackList<'o, 'tcx> {
2809        self.list()
2810    }
2811
2812    /// Indicates that attempting to evaluate this stack entry
2813    /// required accessing something from the stack at depth `reached_depth`.
2814    fn update_reached_depth(&self, reached_depth: usize) {
2815        if !(self.depth >= reached_depth) {
    {
        ::core::panicking::panic_fmt(format_args!("invoked `update_reached_depth` with something under this stack: self.depth={0} reached_depth={1}",
                self.depth, reached_depth));
    }
};assert!(
2816            self.depth >= reached_depth,
2817            "invoked `update_reached_depth` with something under this stack: \
2818             self.depth={} reached_depth={}",
2819            self.depth,
2820            reached_depth,
2821        );
2822        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:2822",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2822u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("reached_depth")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("reached_depth");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("update_reached_depth")
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&reached_depth as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(reached_depth, "update_reached_depth");
2823        let mut p = self;
2824        while reached_depth < p.depth {
2825            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:2825",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2825u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("p.fresh_trait_pred")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("p.fresh_trait_pred");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("update_reached_depth: marking as cycle participant")
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&p.fresh_trait_pred)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?p.fresh_trait_pred, "update_reached_depth: marking as cycle participant");
2826            p.reached_depth.set(p.reached_depth.get().min(reached_depth));
2827            p = p.previous.head.unwrap();
2828        }
2829    }
2830}
2831
2832/// The "provisional evaluation cache" is used to store intermediate cache results
2833/// when solving auto traits. Auto traits are unusual in that they can support
2834/// cycles. So, for example, a "proof tree" like this would be ok:
2835///
2836/// - `Foo<T>: Send` :-
2837///   - `Bar<T>: Send` :-
2838///     - `Foo<T>: Send` -- cycle, but ok
2839///   - `Baz<T>: Send`
2840///
2841/// Here, to prove `Foo<T>: Send`, we have to prove `Bar<T>: Send` and
2842/// `Baz<T>: Send`. Proving `Bar<T>: Send` in turn required `Foo<T>: Send`.
2843/// For non-auto traits, this cycle would be an error, but for auto traits (because
2844/// they are coinductive) it is considered ok.
2845///
2846/// However, there is a complication: at the point where we have
2847/// "proven" `Bar<T>: Send`, we have in fact only proven it
2848/// *provisionally*. In particular, we proved that `Bar<T>: Send`
2849/// *under the assumption* that `Foo<T>: Send`. But what if we later
2850/// find out this assumption is wrong?  Specifically, we could
2851/// encounter some kind of error proving `Baz<T>: Send`. In that case,
2852/// `Bar<T>: Send` didn't turn out to be true.
2853///
2854/// In Issue #60010, we found a bug in rustc where it would cache
2855/// these intermediate results. This was fixed in #60444 by disabling
2856/// *all* caching for things involved in a cycle -- in our example,
2857/// that would mean we don't cache that `Bar<T>: Send`. But this led
2858/// to large slowdowns.
2859///
2860/// Specifically, imagine this scenario, where proving `Baz<T>: Send`
2861/// first requires proving `Bar<T>: Send` (which is true:
2862///
2863/// - `Foo<T>: Send` :-
2864///   - `Bar<T>: Send` :-
2865///     - `Foo<T>: Send` -- cycle, but ok
2866///   - `Baz<T>: Send`
2867///     - `Bar<T>: Send` -- would be nice for this to be a cache hit!
2868///     - `*const T: Send` -- but what if we later encounter an error?
2869///
2870/// The *provisional evaluation cache* resolves this issue. It stores
2871/// cache results that we've proven but which were involved in a cycle
2872/// in some way. We track the minimal stack depth (i.e., the
2873/// farthest from the top of the stack) that we are dependent on.
2874/// The idea is that the cache results within are all valid -- so long as
2875/// none of the nodes in between the current node and the node at that minimum
2876/// depth result in an error (in which case the cached results are just thrown away).
2877///
2878/// During evaluation, we consult this provisional cache and rely on
2879/// it. Accessing a cached value is considered equivalent to accessing
2880/// a result at `reached_depth`, so it marks the *current* solution as
2881/// provisional as well. If an error is encountered, we toss out any
2882/// provisional results added from the subtree that encountered the
2883/// error. When we pop the node at `reached_depth` from the stack, we
2884/// can commit all the things that remain in the provisional cache.
2885struct ProvisionalEvaluationCache<'tcx> {
2886    /// next "depth first number" to issue -- just a counter
2887    dfn: Cell<usize>,
2888
2889    /// Map from cache key to the provisionally evaluated thing.
2890    /// The cache entries contain the result but also the DFN in which they
2891    /// were added. The DFN is used to clear out values on failure.
2892    ///
2893    /// Imagine we have a stack like:
2894    ///
2895    /// - `A B C` and we add a cache for the result of C (DFN 2)
2896    /// - Then we have a stack `A B D` where `D` has DFN 3
2897    /// - We try to solve D by evaluating E: `A B D E` (DFN 4)
2898    /// - `E` generates various cache entries which have cyclic dependencies on `B`
2899    ///   - `A B D E F` and so forth
2900    ///   - the DFN of `F` for example would be 5
2901    /// - then we determine that `E` is in error -- we will then clear
2902    ///   all cache values whose DFN is >= 4 -- in this case, that
2903    ///   means the cached value for `F`.
2904    map: RefCell<FxIndexMap<ty::PolyTraitClause<'tcx>, ProvisionalEvaluation>>,
2905
2906    /// The stack of terms that we assume to be well-formed because a `WF(term)` predicate
2907    /// is on the stack above (and because of wellformedness is coinductive).
2908    /// In an "ideal" world, this would share a stack with trait predicates in
2909    /// `TraitObligationStack`. However, trait predicates are *much* hotter than
2910    /// `WellFormed` predicates, and it's very likely that the additional matches
2911    /// will have a perf effect. The value here is the well-formed `GenericArg`
2912    /// and the depth of the trait predicate *above* that well-formed predicate.
2913    wf_args: RefCell<Vec<(ty::Term<'tcx>, usize)>>,
2914}
2915
2916/// A cache value for the provisional cache: contains the depth-first
2917/// number (DFN) and result.
2918#[derive(#[automatically_derived]
impl ::core::marker::Copy for ProvisionalEvaluation { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ProvisionalEvaluation { }
#[automatically_derived]
impl ::core::clone::Clone for ProvisionalEvaluation {
    #[inline]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<usize>;
        let _: ::core::clone::AssertParamIsClone<EvaluationResult>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for ProvisionalEvaluation {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f,
            "ProvisionalEvaluation", "from_dfn", &self.from_dfn,
            "reached_depth", &self.reached_depth, "result", &&self.result)
    }
}Debug)]
2919struct ProvisionalEvaluation {
2920    from_dfn: usize,
2921    reached_depth: usize,
2922    result: EvaluationResult,
2923}
2924
2925impl<'tcx> Default for ProvisionalEvaluationCache<'tcx> {
2926    fn default() -> Self {
2927        Self { dfn: Cell::new(0), map: Default::default(), wf_args: Default::default() }
2928    }
2929}
2930
2931impl<'tcx> ProvisionalEvaluationCache<'tcx> {
2932    /// Get the next DFN in sequence (basically a counter).
2933    fn next_dfn(&self) -> usize {
2934        let result = self.dfn.get();
2935        self.dfn.set(result + 1);
2936        result
2937    }
2938
2939    /// Check the provisional cache for any result for
2940    /// `fresh_trait_pred`. If there is a hit, then you must consider
2941    /// it an access to the stack slots at depth
2942    /// `reached_depth` (from the returned value).
2943    fn get_provisional(
2944        &self,
2945        fresh_trait_pred: ty::PolyTraitClause<'tcx>,
2946    ) -> Option<ProvisionalEvaluation> {
2947        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:2947",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2947u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("fresh_trait_pred")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("fresh_trait_pred");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("get_provisional = {0:#?}",
                                                    self.map.borrow().get(&fresh_trait_pred)) as
                                            &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fresh_trait_pred)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
2948            ?fresh_trait_pred,
2949            "get_provisional = {:#?}",
2950            self.map.borrow().get(&fresh_trait_pred),
2951        );
2952        Some(*self.map.borrow().get(&fresh_trait_pred)?)
2953    }
2954
2955    /// Insert a provisional result into the cache. The result came
2956    /// from the node with the given DFN. It accessed a minimum depth
2957    /// of `reached_depth` to compute. It evaluated `fresh_trait_pred`
2958    /// and resulted in `result`.
2959    fn insert_provisional(
2960        &self,
2961        from_dfn: usize,
2962        reached_depth: usize,
2963        fresh_trait_pred: ty::PolyTraitClause<'tcx>,
2964        result: EvaluationResult,
2965    ) {
2966        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:2966",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2966u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("from_dfn")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("from_dfn");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("fresh_trait_pred")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("fresh_trait_pred");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("result")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("result");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("insert_provisional")
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&from_dfn)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fresh_trait_pred)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&result)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?from_dfn, ?fresh_trait_pred, ?result, "insert_provisional");
2967
2968        let mut map = self.map.borrow_mut();
2969
2970        // Subtle: when we complete working on the DFN `from_dfn`, anything
2971        // that remains in the provisional cache must be dependent on some older
2972        // stack entry than `from_dfn`. We have to update their depth with our transitive
2973        // depth in that case or else it would be referring to some popped note.
2974        //
2975        // Example:
2976        // A (reached depth 0)
2977        //   ...
2978        //      B // depth 1 -- reached depth = 0
2979        //          C // depth 2 -- reached depth = 1 (should be 0)
2980        //              B
2981        //          A // depth 0
2982        //   D (reached depth 1)
2983        //      C (cache -- reached depth = 2)
2984        for (_k, v) in &mut *map {
2985            if v.from_dfn >= from_dfn {
2986                v.reached_depth = reached_depth.min(v.reached_depth);
2987            }
2988        }
2989
2990        map.insert(fresh_trait_pred, ProvisionalEvaluation { from_dfn, reached_depth, result });
2991    }
2992
2993    /// Invoked when the node with dfn `dfn` does not get a successful
2994    /// result. This will clear out any provisional cache entries
2995    /// originating from nodes visited before this node (`from_dfn < dfn`).
2996    /// This is because the provisional entries are things which must
2997    /// assume that the things on the stack at the time of their creation
2998    /// succeeded -- since the failing node is presently at the top of
2999    /// the stack, these provisional entries must either depend on it or
3000    /// some ancestor of it.
3001    fn on_failure(&self, dfn: usize) {
3002        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:3002",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(3002u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("dfn")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("dfn");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("on_failure")
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&dfn)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?dfn, "on_failure");
3003        self.map.borrow_mut().retain(|key, eval| {
3004            if eval.from_dfn < dfn {
3005                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:3005",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(3005u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("on_failure: removing {0:?}",
                                                    key) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("on_failure: removing {:?}", key);
3006                false
3007            } else {
3008                true
3009            }
3010        });
3011    }
3012
3013    /// Invoked when the node at depth `depth` completed without
3014    /// depending on anything higher in the stack (if that completion
3015    /// was a failure, then `on_failure` should have been invoked
3016    /// already).
3017    ///
3018    /// Note that we may still have provisional cache items remaining
3019    /// in the cache when this is done. For example, if there is a
3020    /// cycle:
3021    ///
3022    /// * A depends on...
3023    ///     * B depends on A
3024    ///     * C depends on...
3025    ///         * D depends on C
3026    ///     * ...
3027    ///
3028    /// Then as we complete the C node we will have a provisional cache
3029    /// with results for A, B, C, and D. This method would clear out
3030    /// the C and D results, but leave A and B provisional.
3031    ///
3032    /// This is determined based on the DFN: we remove any provisional
3033    /// results created since `dfn` started (e.g., in our example, dfn
3034    /// would be 2, representing the C node, and hence we would
3035    /// remove the result for D, which has DFN 3, but not the results for
3036    /// A and B, which have DFNs 0 and 1 respectively).
3037    ///
3038    /// Note that we *do not* attempt to cache these cycle participants
3039    /// in the evaluation cache. Doing so would require carefully computing
3040    /// the correct `DepNode` to store in the cache entry:
3041    /// cycle participants may implicitly depend on query results
3042    /// related to other participants in the cycle, due to our logic
3043    /// which examines the evaluation stack.
3044    ///
3045    /// We used to try to perform this caching,
3046    /// but it lead to multiple incremental compilation ICEs
3047    /// (see #92987 and #96319), and was very hard to understand.
3048    /// Fortunately, removing the caching didn't seem to
3049    /// have a performance impact in practice.
3050    fn on_completion(&self, dfn: usize) {
3051        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:3051",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(3051u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("dfn")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("dfn");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("on_completion")
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&dfn)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?dfn, "on_completion");
3052        self.map.borrow_mut().retain(|fresh_trait_pred, eval| {
3053            if eval.from_dfn >= dfn {
3054                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs:3054",
                        "rustc_trait_selection::traits::select",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/48f4b05538b8eca412137042d9647a61e692c6b3/compiler/rustc_trait_selection/src/traits/select/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(3054u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("fresh_trait_pred")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("fresh_trait_pred");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("eval")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("eval");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("on_completion")
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fresh_trait_pred)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&eval)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?fresh_trait_pred, ?eval, "on_completion");
3055                return false;
3056            }
3057            true
3058        });
3059    }
3060}
3061
3062#[derive(#[automatically_derived]
impl<'o, 'tcx> ::core::marker::Copy for TraitObligationStackList<'o, 'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'o, 'tcx> ::core::clone::TrivialClone for
    TraitObligationStackList<'o, 'tcx> {
}
#[automatically_derived]
impl<'o, 'tcx> ::core::clone::Clone for TraitObligationStackList<'o, 'tcx> {
    #[inline]
    fn clone(&self) -> Self {
        let _:
                ::core::clone::AssertParamIsClone<&'o ProvisionalEvaluationCache<'tcx>>;
        let _:
                ::core::clone::AssertParamIsClone<Option<&'o TraitObligationStack<'o,
                'tcx>>>;
        *self
    }
}Clone)]
3063struct TraitObligationStackList<'o, 'tcx> {
3064    cache: &'o ProvisionalEvaluationCache<'tcx>,
3065    head: Option<&'o TraitObligationStack<'o, 'tcx>>,
3066}
3067
3068impl<'o, 'tcx> TraitObligationStackList<'o, 'tcx> {
3069    fn empty(cache: &'o ProvisionalEvaluationCache<'tcx>) -> TraitObligationStackList<'o, 'tcx> {
3070        TraitObligationStackList { cache, head: None }
3071    }
3072
3073    fn with(r: &'o TraitObligationStack<'o, 'tcx>) -> TraitObligationStackList<'o, 'tcx> {
3074        TraitObligationStackList { cache: r.cache(), head: Some(r) }
3075    }
3076
3077    fn head(&self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
3078        self.head
3079    }
3080
3081    fn depth(&self) -> usize {
3082        if let Some(head) = self.head { head.depth } else { 0 }
3083    }
3084}
3085
3086impl<'o, 'tcx> Iterator for TraitObligationStackList<'o, 'tcx> {
3087    type Item = &'o TraitObligationStack<'o, 'tcx>;
3088
3089    fn next(&mut self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
3090        let o = self.head?;
3091        *self = o.previous;
3092        Some(o)
3093    }
3094}
3095
3096impl<'o, 'tcx> fmt::Debug for TraitObligationStack<'o, 'tcx> {
3097    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3098        f.write_fmt(format_args!("TraitObligationStack({0:?})", self.obligation))write!(f, "TraitObligationStack({:?})", self.obligation)
3099    }
3100}
3101
3102pub(crate) enum ProjectionMatchesProjection {
3103    Yes,
3104    Ambiguous,
3105    No,
3106}
3107
3108#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for AutoImplConstituents<'tcx> {
    #[inline]
    fn clone(&self) -> Self {
        AutoImplConstituents {
            types: ::core::clone::Clone::clone(&self.types),
            assumptions: ::core::clone::Clone::clone(&self.assumptions),
        }
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for AutoImplConstituents<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "AutoImplConstituents", "types", &self.types, "assumptions",
            &&self.assumptions)
    }
}Debug, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
            for AutoImplConstituents<'tcx> {
            fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        AutoImplConstituents {
                            types: __binding_0, assumptions: __binding_1 } => {
                            AutoImplConstituents {
                                types: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                assumptions: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    AutoImplConstituents {
                        types: __binding_0, assumptions: __binding_1 } => {
                        AutoImplConstituents {
                            types: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            assumptions: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
            for AutoImplConstituents<'tcx> {
            fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    AutoImplConstituents {
                        types: ref __binding_0, assumptions: ref __binding_1 } => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_middle::ty::VisitorResult>::output()
            }
        }
    };TypeVisitable)]
3109pub(crate) struct AutoImplConstituents<'tcx> {
3110    pub types: Vec<Ty<'tcx>>,
3111    pub assumptions: Vec<ty::ArgOutlivesClause<'tcx>>,
3112}