Skip to main content

rustc_trait_selection/traits/select/
confirmation.rs

1//! Confirmation.
2//!
3//! Confirmation unifies the output type parameters of the trait
4//! with the values found in the obligation, possibly yielding a
5//! type error. See the [rustc dev guide] for more details.
6//!
7//! [rustc dev guide]:
8//! https://rustc-dev-guide.rust-lang.org/traits/resolution.html#confirmation
9
10use std::ops::ControlFlow;
11
12use rustc_data_structures::stack::ensure_sufficient_stack;
13use rustc_hir::lang_items::LangItem;
14use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk};
15use rustc_infer::traits::ObligationCauseCode;
16use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData};
17use rustc_middle::ty::{
18    self, GenericArgsRef, Region, SizedTraitKind, Ty, TyCtxt, Unnormalized, Upcast,
19};
20use rustc_middle::{bug, span_bug};
21use rustc_span::def_id::DefId;
22use thin_vec::thin_vec;
23use tracing::{debug, instrument};
24
25use super::SelectionCandidate::{self, *};
26use super::{PredicateObligations, SelectionContext};
27use crate::traits::normalize::{normalize_with_depth, normalize_with_depth_to};
28use crate::traits::util::{self, closure_trait_ref_and_return_type};
29use crate::traits::{
30    ImplSource, ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause,
31    PolyTraitObligation, PredicateObligation, Selection, SelectionError, TraitObligation,
32};
33
34impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
35    #[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("confirm_candidate",
                                    "rustc_trait_selection::traits::select::confirmation",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                                    ::tracing_core::__macro_support::Option::Some(35u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                                    ::tracing_core::field::FieldSet::new(&["obligation",
                                                    "candidate"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return:
                    Result<Selection<'tcx>, SelectionError<'tcx>> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            Ok(match candidate {
                    SizedCandidate => {
                        let data = self.confirm_builtin_candidate(obligation);
                        ImplSource::Builtin(BuiltinImplSource::Misc, data)
                    }
                    BuiltinCandidate => {
                        let data = self.confirm_builtin_candidate(obligation);
                        ImplSource::Builtin(BuiltinImplSource::Misc, data)
                    }
                    TransmutabilityCandidate => {
                        let data =
                            self.confirm_transmutability_candidate(obligation)?;
                        ImplSource::Builtin(BuiltinImplSource::Misc, data)
                    }
                    ParamCandidate(param) => {
                        let obligations =
                            self.confirm_param_candidate(obligation,
                                param.map_bound(|t| t.trait_ref));
                        ImplSource::Param(obligations)
                    }
                    ImplCandidate(impl_def_id) => {
                        ImplSource::UserDefined(self.confirm_impl_candidate(obligation,
                                impl_def_id))
                    }
                    AutoImplCandidate => {
                        let data = self.confirm_auto_impl_candidate(obligation)?;
                        ImplSource::Builtin(BuiltinImplSource::Misc, data)
                    }
                    ProjectionCandidate { idx, .. } => {
                        let obligations =
                            self.confirm_projection_candidate(obligation, idx)?;
                        ImplSource::Param(obligations)
                    }
                    ObjectCandidate(idx) =>
                        self.confirm_object_candidate(obligation, idx)?,
                    ClosureCandidate { .. } => {
                        let vtable_closure =
                            self.confirm_closure_candidate(obligation)?;
                        ImplSource::Builtin(BuiltinImplSource::Misc, vtable_closure)
                    }
                    AsyncClosureCandidate => {
                        let vtable_closure =
                            self.confirm_async_closure_candidate(obligation)?;
                        ImplSource::Builtin(BuiltinImplSource::Misc, vtable_closure)
                    }
                    AsyncFnKindHelperCandidate => {
                        ImplSource::Builtin(BuiltinImplSource::Misc,
                            PredicateObligations::new())
                    }
                    CoroutineCandidate => {
                        let vtable_coroutine =
                            self.confirm_coroutine_candidate(obligation)?;
                        ImplSource::Builtin(BuiltinImplSource::Misc,
                            vtable_coroutine)
                    }
                    FutureCandidate => {
                        let vtable_future =
                            self.confirm_future_candidate(obligation)?;
                        ImplSource::Builtin(BuiltinImplSource::Misc, vtable_future)
                    }
                    IteratorCandidate => {
                        let vtable_iterator =
                            self.confirm_iterator_candidate(obligation)?;
                        ImplSource::Builtin(BuiltinImplSource::Misc,
                            vtable_iterator)
                    }
                    AsyncIteratorCandidate => {
                        let vtable_iterator =
                            self.confirm_async_iterator_candidate(obligation)?;
                        ImplSource::Builtin(BuiltinImplSource::Misc,
                            vtable_iterator)
                    }
                    FnPointerCandidate => {
                        let data = self.confirm_fn_pointer_candidate(obligation)?;
                        ImplSource::Builtin(BuiltinImplSource::Misc, data)
                    }
                    TraitAliasCandidate => {
                        let data = self.confirm_trait_alias_candidate(obligation);
                        ImplSource::Builtin(BuiltinImplSource::Misc, data)
                    }
                    BuiltinObjectCandidate => {
                        ImplSource::Builtin(BuiltinImplSource::Misc,
                            PredicateObligations::new())
                    }
                    BuiltinUnsizeCandidate =>
                        self.confirm_builtin_unsize_candidate(obligation)?,
                    TraitUpcastingUnsizeCandidate(idx) => {
                        self.confirm_trait_upcasting_unsize_candidate(obligation,
                                idx)?
                    }
                    BikeshedGuaranteedNoDropCandidate => {
                        self.confirm_bikeshed_guaranteed_no_drop_candidate(obligation)
                    }
                })
        }
    }
}#[instrument(level = "debug", skip(self))]
36    pub(super) fn confirm_candidate(
37        &mut self,
38        obligation: &PolyTraitObligation<'tcx>,
39        candidate: SelectionCandidate<'tcx>,
40    ) -> Result<Selection<'tcx>, SelectionError<'tcx>> {
41        Ok(match candidate {
42            SizedCandidate => {
43                let data = self.confirm_builtin_candidate(obligation);
44                ImplSource::Builtin(BuiltinImplSource::Misc, data)
45            }
46
47            BuiltinCandidate => {
48                let data = self.confirm_builtin_candidate(obligation);
49                ImplSource::Builtin(BuiltinImplSource::Misc, data)
50            }
51
52            TransmutabilityCandidate => {
53                let data = self.confirm_transmutability_candidate(obligation)?;
54                ImplSource::Builtin(BuiltinImplSource::Misc, data)
55            }
56
57            ParamCandidate(param) => {
58                let obligations =
59                    self.confirm_param_candidate(obligation, param.map_bound(|t| t.trait_ref));
60                ImplSource::Param(obligations)
61            }
62
63            ImplCandidate(impl_def_id) => {
64                ImplSource::UserDefined(self.confirm_impl_candidate(obligation, impl_def_id))
65            }
66
67            AutoImplCandidate => {
68                let data = self.confirm_auto_impl_candidate(obligation)?;
69                ImplSource::Builtin(BuiltinImplSource::Misc, data)
70            }
71
72            ProjectionCandidate { idx, .. } => {
73                let obligations = self.confirm_projection_candidate(obligation, idx)?;
74                ImplSource::Param(obligations)
75            }
76
77            ObjectCandidate(idx) => self.confirm_object_candidate(obligation, idx)?,
78
79            ClosureCandidate { .. } => {
80                let vtable_closure = self.confirm_closure_candidate(obligation)?;
81                ImplSource::Builtin(BuiltinImplSource::Misc, vtable_closure)
82            }
83
84            AsyncClosureCandidate => {
85                let vtable_closure = self.confirm_async_closure_candidate(obligation)?;
86                ImplSource::Builtin(BuiltinImplSource::Misc, vtable_closure)
87            }
88
89            // No nested obligations or confirmation process. The checks that we do in
90            // candidate assembly are sufficient.
91            AsyncFnKindHelperCandidate => {
92                ImplSource::Builtin(BuiltinImplSource::Misc, PredicateObligations::new())
93            }
94
95            CoroutineCandidate => {
96                let vtable_coroutine = self.confirm_coroutine_candidate(obligation)?;
97                ImplSource::Builtin(BuiltinImplSource::Misc, vtable_coroutine)
98            }
99
100            FutureCandidate => {
101                let vtable_future = self.confirm_future_candidate(obligation)?;
102                ImplSource::Builtin(BuiltinImplSource::Misc, vtable_future)
103            }
104
105            IteratorCandidate => {
106                let vtable_iterator = self.confirm_iterator_candidate(obligation)?;
107                ImplSource::Builtin(BuiltinImplSource::Misc, vtable_iterator)
108            }
109
110            AsyncIteratorCandidate => {
111                let vtable_iterator = self.confirm_async_iterator_candidate(obligation)?;
112                ImplSource::Builtin(BuiltinImplSource::Misc, vtable_iterator)
113            }
114
115            FnPointerCandidate => {
116                let data = self.confirm_fn_pointer_candidate(obligation)?;
117                ImplSource::Builtin(BuiltinImplSource::Misc, data)
118            }
119
120            TraitAliasCandidate => {
121                let data = self.confirm_trait_alias_candidate(obligation);
122                ImplSource::Builtin(BuiltinImplSource::Misc, data)
123            }
124
125            BuiltinObjectCandidate => {
126                // This indicates something like `Trait + Send: Send`. In this case, we know that
127                // this holds because that's what the object type is telling us, and there's really
128                // no additional obligations to prove and no types in particular to unify, etc.
129                ImplSource::Builtin(BuiltinImplSource::Misc, PredicateObligations::new())
130            }
131
132            BuiltinUnsizeCandidate => self.confirm_builtin_unsize_candidate(obligation)?,
133
134            TraitUpcastingUnsizeCandidate(idx) => {
135                self.confirm_trait_upcasting_unsize_candidate(obligation, idx)?
136            }
137
138            BikeshedGuaranteedNoDropCandidate => {
139                self.confirm_bikeshed_guaranteed_no_drop_candidate(obligation)
140            }
141        })
142    }
143
144    fn confirm_projection_candidate(
145        &mut self,
146        obligation: &PolyTraitObligation<'tcx>,
147        idx: usize,
148    ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
149        let placeholder_trait_predicate =
150            self.infcx.enter_forall_and_leak_universe(obligation.predicate).trait_ref;
151        let placeholder_self_ty = self.infcx.shallow_resolve(placeholder_trait_predicate.self_ty());
152        let candidate_predicate = self
153            .for_each_item_bound(
154                placeholder_self_ty,
155                |_, clause, clause_idx, _| {
156                    if clause_idx == idx {
157                        ControlFlow::Break(clause)
158                    } else {
159                        ControlFlow::Continue(())
160                    }
161                },
162                || ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
163            )
164            .break_value()
165            .expect("expected to index into clause that exists");
166        let candidate_predicate = candidate_predicate
167            .as_trait_clause()
168            .expect("projection candidate is not a trait predicate");
169        let candidate_predicate =
170            util::lazily_elaborate_sizedness_candidate(self.infcx, obligation, candidate_predicate);
171
172        let candidate = candidate_predicate.map_bound(|t| t.trait_ref);
173
174        let candidate = self.infcx.instantiate_binder_with_fresh_vars(
175            obligation.cause.span,
176            BoundRegionConversionTime::HigherRankedType,
177            candidate,
178        );
179        let mut obligations = PredicateObligations::new();
180        let candidate = normalize_with_depth_to(
181            self,
182            obligation.param_env,
183            obligation.cause.clone(),
184            obligation.recursion_depth + 1,
185            candidate,
186            &mut obligations,
187        );
188
189        obligations.extend(
190            self.infcx
191                .at(&obligation.cause, obligation.param_env)
192                .eq(DefineOpaqueTypes::No, placeholder_trait_predicate, candidate)
193                .map(|InferOk { obligations, .. }| obligations)
194                .map_err(|_| SelectionError::Unimplemented)?,
195        );
196
197        Ok(obligations)
198    }
199
200    fn confirm_param_candidate(
201        &mut self,
202        obligation: &PolyTraitObligation<'tcx>,
203        param: ty::PolyTraitRef<'tcx>,
204    ) -> PredicateObligations<'tcx> {
205        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:205",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(205u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "obligation", "param"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("confirm_param_candidate")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligation)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&param) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?obligation, ?param, "confirm_param_candidate");
206
207        let param = util::lazily_elaborate_sizedness_candidate(
208            self.infcx,
209            obligation,
210            param.upcast(self.infcx.tcx),
211        )
212        .map_bound(|p| p.trait_ref);
213
214        // During evaluation, we already checked that this
215        // where-clause trait-ref could be unified with the obligation
216        // trait-ref. Repeat that unification now without any
217        // transactional boundary; it should not fail.
218        match self.match_where_clause_trait_ref(obligation, param) {
219            Ok(obligations) => obligations,
220            Err(()) => {
221                ::rustc_middle::util::bug::bug_fmt(format_args!("Where clause `{0:?}` was applicable to `{1:?}` but now is not",
        param, obligation));bug!(
222                    "Where clause `{:?}` was applicable to `{:?}` but now is not",
223                    param,
224                    obligation
225                );
226            }
227        }
228    }
229
230    x;#[instrument(level = "debug", skip(self), ret)]
231    fn confirm_builtin_candidate(
232        &mut self,
233        obligation: &PolyTraitObligation<'tcx>,
234    ) -> PredicateObligations<'tcx> {
235        debug!(?obligation, "confirm_builtin_candidate");
236        let tcx = self.tcx();
237        let trait_def = obligation.predicate.def_id();
238        let self_ty = self.infcx.shallow_resolve(
239            self.infcx.enter_forall_and_leak_universe(obligation.predicate.self_ty()),
240        );
241        let types = match tcx.as_lang_item(trait_def) {
242            Some(LangItem::Sized) => self.sizedness_conditions(self_ty, SizedTraitKind::Sized),
243            Some(LangItem::MetaSized) => {
244                self.sizedness_conditions(self_ty, SizedTraitKind::MetaSized)
245            }
246            Some(LangItem::PointeeSized) => {
247                bug!("`PointeeSized` is removing during lowering");
248            }
249            Some(LangItem::Copy | LangItem::Clone | LangItem::TrivialClone) => {
250                self.copy_clone_conditions(self_ty)
251            }
252            Some(LangItem::FusedIterator) => {
253                if self.coroutine_is_gen(self_ty) {
254                    ty::Binder::dummy(vec![])
255                } else {
256                    unreachable!("tried to assemble `FusedIterator` for non-gen coroutine");
257                }
258            }
259            Some(
260                LangItem::Destruct
261                | LangItem::DiscriminantKind
262                | LangItem::Field
263                | LangItem::FnPtrTrait
264                | LangItem::PointeeTrait
265                | LangItem::Tuple
266                | LangItem::Unpin,
267            ) => ty::Binder::dummy(vec![]),
268            other => bug!("unexpected builtin trait {trait_def:?} ({other:?})"),
269        };
270        let types = self.infcx.enter_forall_and_leak_universe(types);
271
272        let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
273        self.collect_predicates_for_types(
274            obligation.param_env,
275            cause,
276            obligation.recursion_depth + 1,
277            trait_def,
278            types,
279        )
280    }
281
282    #[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("confirm_transmutability_candidate",
                                    "rustc_trait_selection::traits::select::confirmation",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                                    ::tracing_core::__macro_support::Option::Some(282u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                                    ::tracing_core::field::FieldSet::new(&["obligation"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return:
                    Result<PredicateObligations<'tcx>, SelectionError<'tcx>> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            use rustc_transmute::{Answer, Assume, Condition};
            #[doc =
            " Flatten the `Condition` tree into a conjunction of obligations."]
            fn flatten_answer_tree<'tcx>(tcx: TyCtxt<'tcx>,
                obligation: &PolyTraitObligation<'tcx>,
                cond: Condition<Region<'tcx>, Ty<'tcx>>, assume: Assume)
                -> PredicateObligations<'tcx> {
                {}

                #[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("flatten_answer_tree",
                                                    "rustc_trait_selection::traits::select::confirmation",
                                                    ::tracing::Level::DEBUG,
                                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(290u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                                                    ::tracing_core::field::FieldSet::new(&["cond", "assume"],
                                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                    ::tracing::metadata::Kind::SPAN)
                                            };
                                        ::tracing::callsite::DefaultCallsite::new(&META)
                                    };
                                let mut interest = ::tracing::subscriber::Interest::never();
                                if ::tracing::Level::DEBUG <=
                                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                ::tracing::Level::DEBUG <=
                                                    ::tracing::level_filters::LevelFilter::current() &&
                                            { interest = __CALLSITE.interest(); !interest.is_never() }
                                        &&
                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                            interest) {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Span::new(meta,
                                        &{
                                                #[allow(unused_imports)]
                                                use ::tracing::field::{debug, display, Value};
                                                let mut iter = meta.fields().iter();
                                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&cond)
                                                                            as &dyn Value)),
                                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assume)
                                                                            as &dyn Value))])
                                            })
                                } else {
                                    let span =
                                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                                    {};
                                    span
                                }
                            };
                        __tracing_attr_guard = __tracing_attr_span.enter();
                    }

                    #[warn(clippy :: suspicious_else_formatting)]
                    {

                        #[allow(unknown_lints, unreachable_code, clippy ::
                        diverging_sub_expression, clippy :: empty_loop, clippy ::
                        let_unit_value, clippy :: let_with_type_underscore, clippy
                        :: needless_return, clippy :: unreachable)]
                        if false {
                            let __tracing_attr_fake_return: PredicateObligations<'tcx> =
                                loop {};
                            return __tracing_attr_fake_return;
                        }
                        {
                            match cond {
                                Condition::IfAll(conds) | Condition::IfAny(conds) =>
                                    conds.into_iter().flat_map(|cond|
                                                flatten_answer_tree(tcx, obligation, cond,
                                                    assume)).collect(),
                                Condition::Immutable { ty } => {
                                    let trait_ref =
                                        ty::TraitRef::new(tcx,
                                            tcx.require_lang_item(LangItem::Freeze,
                                                obligation.cause.span), [ty::GenericArg::from(ty)]);
                                    {
                                        let len = [()].len();
                                        let mut vec = ::thin_vec::ThinVec::with_capacity(len);
                                        vec.push(Obligation::with_depth(tcx,
                                                obligation.cause.clone(), obligation.recursion_depth + 1,
                                                obligation.param_env, trait_ref));
                                        vec
                                    }
                                }
                                Condition::Outlives { long, short } => {
                                    let outlives = ty::OutlivesPredicate(long, short);
                                    {
                                        let len = [()].len();
                                        let mut vec = ::thin_vec::ThinVec::with_capacity(len);
                                        vec.push(Obligation::with_depth(tcx,
                                                obligation.cause.clone(), obligation.recursion_depth + 1,
                                                obligation.param_env, outlives));
                                        vec
                                    }
                                }
                                Condition::Transmutable { src, dst } => {
                                    let transmute_trait = obligation.predicate.def_id();
                                    let assume =
                                        obligation.predicate.skip_binder().trait_ref.args.const_at(2);
                                    let trait_ref =
                                        ty::TraitRef::new(tcx, transmute_trait,
                                            [ty::GenericArg::from(dst), ty::GenericArg::from(src),
                                                    ty::GenericArg::from(assume)]);
                                    {
                                        let len = [()].len();
                                        let mut vec = ::thin_vec::ThinVec::with_capacity(len);
                                        vec.push(Obligation::with_depth(tcx,
                                                obligation.cause.clone(), obligation.recursion_depth + 1,
                                                obligation.param_env, trait_ref));
                                        vec
                                    }
                                }
                            }
                        }
                    }
                }
            }
            let predicate =
                self.infcx.enter_forall_and_leak_universe(obligation.predicate);
            let mut assume = predicate.trait_ref.args.const_at(2);
            if self.tcx().features().generic_const_exprs() {
                assume =
                    crate::traits::evaluate_const(self.infcx, assume,
                        obligation.param_env)
            }
            let Some(assume) =
                rustc_transmute::Assume::from_const(self.infcx.tcx,
                    assume) else { return Err(SelectionError::Unimplemented); };
            let dst = predicate.trait_ref.args.type_at(0);
            let src = predicate.trait_ref.args.type_at(1);
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:364",
                                    "rustc_trait_selection::traits::select::confirmation",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                                    ::tracing_core::__macro_support::Option::Some(364u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                                    ::tracing_core::field::FieldSet::new(&["src", "dst"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&debug(&src) as
                                                        &dyn Value)),
                                            (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&debug(&dst) as
                                                        &dyn Value))])
                        });
                } else { ; }
            };
            let mut transmute_env =
                rustc_transmute::TransmuteTypeEnv::new(self.infcx.tcx);
            let maybe_transmutable =
                transmute_env.is_transmutable(src, dst, assume);
            let fully_flattened =
                match maybe_transmutable {
                    Answer::No(_) => Err(SelectionError::Unimplemented)?,
                    Answer::If(cond) =>
                        flatten_answer_tree(self.tcx(), obligation, cond, assume),
                    Answer::Yes => PredicateObligations::new(),
                };
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:374",
                                    "rustc_trait_selection::traits::select::confirmation",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                                    ::tracing_core::__macro_support::Option::Some(374u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                                    ::tracing_core::field::FieldSet::new(&["fully_flattened"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&debug(&fully_flattened)
                                                        as &dyn Value))])
                        });
                } else { ; }
            };
            Ok(fully_flattened)
        }
    }
}#[instrument(level = "debug", skip(self))]
283    fn confirm_transmutability_candidate(
284        &mut self,
285        obligation: &PolyTraitObligation<'tcx>,
286    ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
287        use rustc_transmute::{Answer, Assume, Condition};
288
289        /// Flatten the `Condition` tree into a conjunction of obligations.
290        #[instrument(level = "debug", skip(tcx, obligation))]
291        fn flatten_answer_tree<'tcx>(
292            tcx: TyCtxt<'tcx>,
293            obligation: &PolyTraitObligation<'tcx>,
294            cond: Condition<Region<'tcx>, Ty<'tcx>>,
295            assume: Assume,
296        ) -> PredicateObligations<'tcx> {
297            match cond {
298                // FIXME(bryangarza): Add separate `IfAny` case, instead of treating as `IfAll`
299                // Not possible until the trait solver supports disjunctions of obligations
300                Condition::IfAll(conds) | Condition::IfAny(conds) => conds
301                    .into_iter()
302                    .flat_map(|cond| flatten_answer_tree(tcx, obligation, cond, assume))
303                    .collect(),
304                Condition::Immutable { ty } => {
305                    let trait_ref = ty::TraitRef::new(
306                        tcx,
307                        tcx.require_lang_item(LangItem::Freeze, obligation.cause.span),
308                        [ty::GenericArg::from(ty)],
309                    );
310                    thin_vec![Obligation::with_depth(
311                        tcx,
312                        obligation.cause.clone(),
313                        obligation.recursion_depth + 1,
314                        obligation.param_env,
315                        trait_ref,
316                    )]
317                }
318                Condition::Outlives { long, short } => {
319                    let outlives = ty::OutlivesPredicate(long, short);
320                    thin_vec![Obligation::with_depth(
321                        tcx,
322                        obligation.cause.clone(),
323                        obligation.recursion_depth + 1,
324                        obligation.param_env,
325                        outlives,
326                    )]
327                }
328                Condition::Transmutable { src, dst } => {
329                    let transmute_trait = obligation.predicate.def_id();
330                    let assume = obligation.predicate.skip_binder().trait_ref.args.const_at(2);
331                    let trait_ref = ty::TraitRef::new(
332                        tcx,
333                        transmute_trait,
334                        [
335                            ty::GenericArg::from(dst),
336                            ty::GenericArg::from(src),
337                            ty::GenericArg::from(assume),
338                        ],
339                    );
340                    thin_vec![Obligation::with_depth(
341                        tcx,
342                        obligation.cause.clone(),
343                        obligation.recursion_depth + 1,
344                        obligation.param_env,
345                        trait_ref,
346                    )]
347                }
348            }
349        }
350
351        let predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
352
353        let mut assume = predicate.trait_ref.args.const_at(2);
354        if self.tcx().features().generic_const_exprs() {
355            assume = crate::traits::evaluate_const(self.infcx, assume, obligation.param_env)
356        }
357        let Some(assume) = rustc_transmute::Assume::from_const(self.infcx.tcx, assume) else {
358            return Err(SelectionError::Unimplemented);
359        };
360
361        let dst = predicate.trait_ref.args.type_at(0);
362        let src = predicate.trait_ref.args.type_at(1);
363
364        debug!(?src, ?dst);
365        let mut transmute_env = rustc_transmute::TransmuteTypeEnv::new(self.infcx.tcx);
366        let maybe_transmutable = transmute_env.is_transmutable(src, dst, assume);
367
368        let fully_flattened = match maybe_transmutable {
369            Answer::No(_) => Err(SelectionError::Unimplemented)?,
370            Answer::If(cond) => flatten_answer_tree(self.tcx(), obligation, cond, assume),
371            Answer::Yes => PredicateObligations::new(),
372        };
373
374        debug!(?fully_flattened);
375        Ok(fully_flattened)
376    }
377
378    /// This handles the case where an `auto trait Foo` impl is being used.
379    /// The idea is that the impl applies to `X : Foo` if the following conditions are met:
380    ///
381    /// 1. For each constituent type `Y` in `X`, `Y : Foo` holds
382    /// 2. For each where-clause `C` declared on `Foo`, `[Self => X] C` holds.
383    fn confirm_auto_impl_candidate(
384        &mut self,
385        obligation: &PolyTraitObligation<'tcx>,
386    ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
387        ensure_sufficient_stack(|| {
388            match (&obligation.predicate.polarity(), &ty::PredicatePolarity::Positive) {
    (left_val, right_val) => {
        if !(*left_val == *right_val) {
            let kind = ::core::panicking::AssertKind::Eq;
            ::core::panicking::assert_failed(kind, &*left_val, &*right_val,
                ::core::option::Option::None);
        }
    }
};assert_eq!(obligation.predicate.polarity(), ty::PredicatePolarity::Positive);
389
390            let self_ty =
391                obligation.predicate.self_ty().map_bound(|ty| self.infcx.shallow_resolve(ty));
392            let self_ty = self.infcx.enter_forall_and_leak_universe(self_ty);
393
394            let constituents = self.constituent_types_for_auto_trait(self_ty)?;
395            let constituents = self.infcx.enter_forall_and_leak_universe(constituents);
396
397            let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
398            let mut obligations = self.collect_predicates_for_types(
399                obligation.param_env,
400                cause.clone(),
401                obligation.recursion_depth + 1,
402                obligation.predicate.def_id(),
403                constituents.types,
404            );
405
406            // Only normalize these goals if `-Zhigher-ranked-assumptions` is enabled, since
407            // we don't want to cause ourselves to do extra work if we're not even able to
408            // take advantage of these assumption clauses.
409            if self.tcx().sess.opts.unstable_opts.higher_ranked_assumptions {
410                // FIXME(coroutine_clone): We could uplift this into `collect_predicates_for_types`
411                // and do this for `Copy`/`Clone` too, but that's feature-gated so it doesn't really
412                // matter yet.
413                for assumption in constituents.assumptions {
414                    let assumption = normalize_with_depth_to(
415                        self,
416                        obligation.param_env,
417                        cause.clone(),
418                        obligation.recursion_depth + 1,
419                        assumption,
420                        &mut obligations,
421                    );
422                    self.infcx.register_region_assumption(assumption);
423                }
424            }
425
426            Ok(obligations)
427        })
428    }
429
430    fn confirm_impl_candidate(
431        &mut self,
432        obligation: &PolyTraitObligation<'tcx>,
433        impl_def_id: DefId,
434    ) -> ImplSourceUserDefinedData<'tcx, PredicateObligation<'tcx>> {
435        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:435",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(435u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "obligation", "impl_def_id"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("confirm_impl_candidate")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligation)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&impl_def_id)
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(?obligation, ?impl_def_id, "confirm_impl_candidate");
436
437        // First, create the generic parameters by matching the impl again,
438        // this time not in a probe.
439        let args = self.rematch_impl(impl_def_id, obligation);
440        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:440",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(440u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message", "args"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("impl args")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&args) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?args, "impl args");
441        ensure_sufficient_stack(|| {
442            self.vtable_impl(
443                impl_def_id,
444                args,
445                &obligation.cause,
446                obligation.recursion_depth + 1,
447                obligation.param_env,
448                obligation.predicate,
449            )
450        })
451    }
452
453    fn vtable_impl(
454        &mut self,
455        impl_def_id: DefId,
456        args: Normalized<'tcx, GenericArgsRef<'tcx>>,
457        cause: &ObligationCause<'tcx>,
458        recursion_depth: usize,
459        param_env: ty::ParamEnv<'tcx>,
460        parent_trait_pred: ty::Binder<'tcx, ty::TraitPredicate<'tcx>>,
461    ) -> ImplSourceUserDefinedData<'tcx, PredicateObligation<'tcx>> {
462        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:462",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(462u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "impl_def_id", "args", "recursion_depth"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("vtable_impl")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&impl_def_id)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&args) as
                                            &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&recursion_depth)
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(?impl_def_id, ?args, ?recursion_depth, "vtable_impl");
463
464        let mut impl_obligations = self.impl_or_trait_obligations(
465            cause,
466            recursion_depth,
467            param_env,
468            impl_def_id,
469            args.value,
470            parent_trait_pred,
471        );
472
473        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:473",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(473u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "impl_obligations"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("vtable_impl")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&impl_obligations)
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(?impl_obligations, "vtable_impl");
474
475        // Because of RFC447, the impl-trait-ref and obligations
476        // are sufficient to determine the impl args, without
477        // relying on projections in the impl-trait-ref.
478        //
479        // e.g., `impl<U: Tr, V: Iterator<Item=U>> Foo<<U as Tr>::T> for V`
480        impl_obligations.extend(args.obligations);
481
482        ImplSourceUserDefinedData { impl_def_id, args: args.value, nested: impl_obligations }
483    }
484
485    fn confirm_object_candidate(
486        &mut self,
487        obligation: &PolyTraitObligation<'tcx>,
488        index: usize,
489    ) -> Result<ImplSource<'tcx, PredicateObligation<'tcx>>, SelectionError<'tcx>> {
490        let tcx = self.tcx();
491        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:491",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(491u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "obligation", "index"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("confirm_object_candidate")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligation)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&index) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?obligation, ?index, "confirm_object_candidate");
492
493        let trait_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
494        let self_ty = self.infcx.shallow_resolve(trait_predicate.self_ty());
495        let ty::Dynamic(data, ..) = *self_ty.kind() else {
496            ::rustc_middle::util::bug::span_bug_fmt(obligation.cause.span,
    format_args!("object candidate with non-object"));span_bug!(obligation.cause.span, "object candidate with non-object");
497        };
498
499        let object_trait_ref = data.principal().unwrap_or_else(|| {
500            ::rustc_middle::util::bug::span_bug_fmt(obligation.cause.span,
    format_args!("object candidate with no principal"))span_bug!(obligation.cause.span, "object candidate with no principal")
501        });
502        let object_trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
503            obligation.cause.span,
504            BoundRegionConversionTime::HigherRankedType,
505            object_trait_ref,
506        );
507        let object_trait_ref = object_trait_ref.with_self_ty(self.tcx(), self_ty);
508
509        let mut nested = PredicateObligations::new();
510
511        let mut supertraits = util::supertraits(tcx, ty::Binder::dummy(object_trait_ref));
512        let unnormalized_upcast_trait_ref =
513            supertraits.nth(index).expect("supertraits iterator no longer has as many elements");
514
515        let upcast_trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
516            obligation.cause.span,
517            BoundRegionConversionTime::HigherRankedType,
518            unnormalized_upcast_trait_ref,
519        );
520        let upcast_trait_ref = normalize_with_depth_to(
521            self,
522            obligation.param_env,
523            obligation.cause.clone(),
524            obligation.recursion_depth + 1,
525            upcast_trait_ref,
526            &mut nested,
527        );
528
529        nested.extend(
530            self.infcx
531                .at(&obligation.cause, obligation.param_env)
532                .eq(DefineOpaqueTypes::No, trait_predicate.trait_ref, upcast_trait_ref)
533                .map(|InferOk { obligations, .. }| obligations)
534                .map_err(|_| SelectionError::Unimplemented)?,
535        );
536
537        // Check supertraits hold. This is so that their associated type bounds
538        // will be checked in the code below.
539        for (supertrait, _) in tcx
540            .explicit_super_predicates_of(trait_predicate.def_id())
541            .iter_instantiated_copied(tcx, trait_predicate.trait_ref.args)
542            .map(Unnormalized::skip_norm_wip)
543        {
544            let normalized_supertrait = normalize_with_depth_to(
545                self,
546                obligation.param_env,
547                obligation.cause.clone(),
548                obligation.recursion_depth + 1,
549                supertrait,
550                &mut nested,
551            );
552            nested.push(obligation.with(tcx, normalized_supertrait));
553        }
554
555        let assoc_types: Vec<_> = tcx
556            .associated_items(trait_predicate.def_id())
557            .in_definition_order()
558            // Associated types that require `Self: Sized` do not show up in the built-in
559            // implementation of `Trait for dyn Trait`, and can be dropped here.
560            .filter(|item| !tcx.generics_require_sized_self(item.def_id))
561            .filter_map(|item| if item.is_type() { Some(item.def_id) } else { None })
562            .collect();
563
564        for assoc_type in assoc_types {
565            let defs: &ty::Generics = tcx.generics_of(assoc_type);
566
567            if !defs.own_params.is_empty() {
568                tcx.dcx().span_delayed_bug(
569                    obligation.cause.span,
570                    "GATs in trait object shouldn't have been considered",
571                );
572                return Err(SelectionError::TraitDynIncompatible(trait_predicate.trait_ref.def_id));
573            }
574
575            // This maybe belongs in wf, but that can't (doesn't) handle
576            // higher-ranked things.
577            // Prevent, e.g., `dyn Iterator<Item = str>`.
578            for bound in self.tcx().item_bounds(assoc_type).transpose_iter() {
579                let normalized_bound = normalize_with_depth_to(
580                    self,
581                    obligation.param_env,
582                    obligation.cause.clone(),
583                    obligation.recursion_depth + 1,
584                    bound.instantiate(tcx, trait_predicate.trait_ref.args).skip_norm_wip(),
585                    &mut nested,
586                );
587                nested.push(obligation.with(tcx, normalized_bound));
588            }
589        }
590
591        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:591",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(591u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message", "nested"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("object nested obligations")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&nested) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?nested, "object nested obligations");
592
593        Ok(ImplSource::Builtin(BuiltinImplSource::Object(index), nested))
594    }
595
596    fn confirm_fn_pointer_candidate(
597        &mut self,
598        obligation: &PolyTraitObligation<'tcx>,
599    ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
600        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:600",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(600u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "obligation"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("confirm_fn_pointer_candidate")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligation)
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(?obligation, "confirm_fn_pointer_candidate");
601        let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
602        let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
603
604        let tcx = self.tcx();
605        let sig = self_ty.fn_sig(tcx);
606        let trait_ref = closure_trait_ref_and_return_type(
607            tcx,
608            obligation.predicate.def_id(),
609            self_ty,
610            sig,
611            util::TupleArgumentsFlag::Yes,
612        )
613        .map_bound(|(trait_ref, _)| trait_ref);
614
615        let mut nested =
616            self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?;
617        let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
618
619        // Confirm the `type Output: Sized;` bound that is present on `FnOnce`
620        let output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
621        let output_ty = normalize_with_depth_to(
622            self,
623            obligation.param_env,
624            cause.clone(),
625            obligation.recursion_depth,
626            output_ty,
627            &mut nested,
628        );
629        let tr = ty::TraitRef::new(
630            self.tcx(),
631            self.tcx().require_lang_item(LangItem::Sized, cause.span),
632            [output_ty],
633        );
634        nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, tr));
635
636        Ok(nested)
637    }
638
639    fn confirm_trait_alias_candidate(
640        &mut self,
641        obligation: &PolyTraitObligation<'tcx>,
642    ) -> PredicateObligations<'tcx> {
643        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:643",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(643u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "obligation"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("confirm_trait_alias_candidate")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligation)
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(?obligation, "confirm_trait_alias_candidate");
644
645        let predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
646        let trait_ref = predicate.trait_ref;
647        let trait_def_id = trait_ref.def_id;
648        let args = trait_ref.args;
649
650        let trait_obligations = self.impl_or_trait_obligations(
651            &obligation.cause,
652            obligation.recursion_depth,
653            obligation.param_env,
654            trait_def_id,
655            args,
656            obligation.predicate,
657        );
658
659        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:659",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(659u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "trait_def_id", "trait_obligations"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("trait alias obligations")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&trait_def_id)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&trait_obligations)
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(?trait_def_id, ?trait_obligations, "trait alias obligations");
660
661        trait_obligations
662    }
663
664    fn confirm_coroutine_candidate(
665        &mut self,
666        obligation: &PolyTraitObligation<'tcx>,
667    ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
668        let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
669        let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
670        let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else {
671            ::rustc_middle::util::bug::bug_fmt(format_args!("closure candidate for non-closure {0:?}",
        obligation));bug!("closure candidate for non-closure {:?}", obligation);
672        };
673
674        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:674",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(674u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "obligation", "coroutine_def_id", "args"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("confirm_coroutine_candidate")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligation)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&coroutine_def_id)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&args) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?obligation, ?coroutine_def_id, ?args, "confirm_coroutine_candidate");
675
676        let coroutine_sig = args.as_coroutine().sig();
677
678        let (trait_ref, _, _) = super::util::coroutine_trait_ref_and_outputs(
679            self.tcx(),
680            obligation.predicate.def_id(),
681            self_ty,
682            coroutine_sig,
683        );
684
685        let nested = self.equate_trait_refs(
686            obligation.with(self.tcx(), placeholder_predicate),
687            ty::Binder::dummy(trait_ref),
688        )?;
689        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:689",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(689u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "trait_ref", "nested"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("coroutine candidate obligations")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&trait_ref)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&nested) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?trait_ref, ?nested, "coroutine candidate obligations");
690
691        Ok(nested)
692    }
693
694    fn confirm_future_candidate(
695        &mut self,
696        obligation: &PolyTraitObligation<'tcx>,
697    ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
698        let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
699        let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
700        let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else {
701            ::rustc_middle::util::bug::bug_fmt(format_args!("closure candidate for non-closure {0:?}",
        obligation));bug!("closure candidate for non-closure {:?}", obligation);
702        };
703
704        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:704",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(704u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "obligation", "coroutine_def_id", "args"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("confirm_future_candidate")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligation)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&coroutine_def_id)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&args) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?obligation, ?coroutine_def_id, ?args, "confirm_future_candidate");
705
706        let coroutine_sig = args.as_coroutine().sig();
707
708        let (trait_ref, _) = super::util::future_trait_ref_and_outputs(
709            self.tcx(),
710            obligation.predicate.def_id(),
711            self_ty,
712            coroutine_sig,
713        );
714
715        let nested = self.equate_trait_refs(
716            obligation.with(self.tcx(), placeholder_predicate),
717            ty::Binder::dummy(trait_ref),
718        )?;
719        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:719",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(719u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "trait_ref", "nested"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("future candidate obligations")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&trait_ref)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&nested) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?trait_ref, ?nested, "future candidate obligations");
720
721        Ok(nested)
722    }
723
724    fn confirm_iterator_candidate(
725        &mut self,
726        obligation: &PolyTraitObligation<'tcx>,
727    ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
728        let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
729        let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
730        let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else {
731            ::rustc_middle::util::bug::bug_fmt(format_args!("closure candidate for non-closure {0:?}",
        obligation));bug!("closure candidate for non-closure {:?}", obligation);
732        };
733
734        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:734",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(734u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "obligation", "coroutine_def_id", "args"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("confirm_iterator_candidate")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligation)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&coroutine_def_id)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&args) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?obligation, ?coroutine_def_id, ?args, "confirm_iterator_candidate");
735
736        let gen_sig = args.as_coroutine().sig();
737
738        let (trait_ref, _) = super::util::iterator_trait_ref_and_outputs(
739            self.tcx(),
740            obligation.predicate.def_id(),
741            self_ty,
742            gen_sig,
743        );
744
745        let nested = self.equate_trait_refs(
746            obligation.with(self.tcx(), placeholder_predicate),
747            ty::Binder::dummy(trait_ref),
748        )?;
749        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:749",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(749u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "trait_ref", "nested"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("iterator candidate obligations")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&trait_ref)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&nested) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?trait_ref, ?nested, "iterator candidate obligations");
750
751        Ok(nested)
752    }
753
754    fn confirm_async_iterator_candidate(
755        &mut self,
756        obligation: &PolyTraitObligation<'tcx>,
757    ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
758        let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
759        let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
760        let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else {
761            ::rustc_middle::util::bug::bug_fmt(format_args!("closure candidate for non-closure {0:?}",
        obligation));bug!("closure candidate for non-closure {:?}", obligation);
762        };
763
764        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:764",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(764u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "obligation", "coroutine_def_id", "args"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("confirm_async_iterator_candidate")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligation)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&coroutine_def_id)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&args) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?obligation, ?coroutine_def_id, ?args, "confirm_async_iterator_candidate");
765
766        let gen_sig = args.as_coroutine().sig();
767
768        let (trait_ref, _) = super::util::async_iterator_trait_ref_and_outputs(
769            self.tcx(),
770            obligation.predicate.def_id(),
771            self_ty,
772            gen_sig,
773        );
774
775        let nested = self.equate_trait_refs(
776            obligation.with(self.tcx(), placeholder_predicate),
777            ty::Binder::dummy(trait_ref),
778        )?;
779        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:779",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(779u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "trait_ref", "nested"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("iterator candidate obligations")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&trait_ref)
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&nested) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?trait_ref, ?nested, "iterator candidate obligations");
780
781        Ok(nested)
782    }
783
784    #[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("confirm_closure_candidate",
                                    "rustc_trait_selection::traits::select::confirmation",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                                    ::tracing_core::__macro_support::Option::Some(784u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                                    ::tracing_core::field::FieldSet::new(&["obligation"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return:
                    Result<PredicateObligations<'tcx>, SelectionError<'tcx>> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let placeholder_predicate =
                self.infcx.enter_forall_and_leak_universe(obligation.predicate);
            let self_ty: Ty<'_> =
                self.infcx.shallow_resolve(placeholder_predicate.self_ty());
            let trait_ref =
                match *self_ty.kind() {
                    ty::Closure(..) => {
                        self.closure_trait_ref_unnormalized(self_ty,
                            obligation.predicate.def_id())
                    }
                    ty::CoroutineClosure(_, args) => {
                        args.as_coroutine_closure().coroutine_closure_sig().map_bound(|sig|
                                {
                                    ty::TraitRef::new(self.tcx(), obligation.predicate.def_id(),
                                        [self_ty, sig.tupled_inputs_ty])
                                })
                    }
                    _ => {
                        ::rustc_middle::util::bug::bug_fmt(format_args!("closure candidate for non-closure {0:?}",
                                obligation));
                    }
                };
            self.equate_trait_refs(obligation.with(self.tcx(),
                    placeholder_predicate), trait_ref)
        }
    }
}#[instrument(skip(self), level = "debug")]
785    fn confirm_closure_candidate(
786        &mut self,
787        obligation: &PolyTraitObligation<'tcx>,
788    ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
789        let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
790        let self_ty: Ty<'_> = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
791
792        let trait_ref = match *self_ty.kind() {
793            ty::Closure(..) => {
794                self.closure_trait_ref_unnormalized(self_ty, obligation.predicate.def_id())
795            }
796            ty::CoroutineClosure(_, args) => {
797                args.as_coroutine_closure().coroutine_closure_sig().map_bound(|sig| {
798                    ty::TraitRef::new(
799                        self.tcx(),
800                        obligation.predicate.def_id(),
801                        [self_ty, sig.tupled_inputs_ty],
802                    )
803                })
804            }
805            _ => {
806                bug!("closure candidate for non-closure {:?}", obligation);
807            }
808        };
809
810        self.equate_trait_refs(obligation.with(self.tcx(), placeholder_predicate), trait_ref)
811    }
812
813    #[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("confirm_async_closure_candidate",
                                    "rustc_trait_selection::traits::select::confirmation",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                                    ::tracing_core::__macro_support::Option::Some(813u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                                    ::tracing_core::field::FieldSet::new(&["obligation"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return:
                    Result<PredicateObligations<'tcx>, SelectionError<'tcx>> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let placeholder_predicate =
                self.infcx.enter_forall_and_leak_universe(obligation.predicate);
            let self_ty =
                self.infcx.shallow_resolve(placeholder_predicate.self_ty());
            let tcx = self.tcx();
            let mut nested = PredicateObligations::new();
            let (trait_ref, kind_ty) =
                match *self_ty.kind() {
                    ty::CoroutineClosure(_, args) => {
                        let args = args.as_coroutine_closure();
                        let trait_ref =
                            args.coroutine_closure_sig().map_bound(|sig|
                                    {
                                        ty::TraitRef::new(self.tcx(), obligation.predicate.def_id(),
                                            [self_ty, sig.tupled_inputs_ty])
                                    });
                        (trait_ref, args.kind_ty())
                    }
                    ty::FnDef(..) | ty::FnPtr(..) => {
                        let sig = self_ty.fn_sig(tcx);
                        let trait_ref =
                            sig.map_bound(|sig|
                                    {
                                        ty::TraitRef::new(self.tcx(), obligation.predicate.def_id(),
                                            [self_ty, Ty::new_tup(tcx, sig.inputs())])
                                    });
                        let future_trait_def_id =
                            tcx.require_lang_item(LangItem::Future,
                                obligation.cause.span);
                        nested.push(obligation.with(tcx,
                                sig.output().map_bound(|output_ty|
                                        {
                                            ty::TraitRef::new(tcx, future_trait_def_id, [output_ty])
                                        })));
                        let sized_trait_def_id =
                            tcx.require_lang_item(LangItem::Sized,
                                obligation.cause.span);
                        nested.push(obligation.with(tcx,
                                sig.output().map_bound(|output_ty|
                                        {
                                            ty::TraitRef::new(tcx, sized_trait_def_id, [output_ty])
                                        })));
                        (trait_ref, Ty::from_closure_kind(tcx, ty::ClosureKind::Fn))
                    }
                    ty::Closure(_, args) => {
                        let args = args.as_closure();
                        let sig = args.sig();
                        let trait_ref =
                            sig.map_bound(|sig|
                                    {
                                        ty::TraitRef::new(self.tcx(), obligation.predicate.def_id(),
                                            [self_ty, sig.inputs()[0]])
                                    });
                        let future_trait_def_id =
                            tcx.require_lang_item(LangItem::Future,
                                obligation.cause.span);
                        let placeholder_output_ty =
                            self.infcx.enter_forall_and_leak_universe(sig.output());
                        nested.push(obligation.with(tcx,
                                ty::TraitRef::new(tcx, future_trait_def_id,
                                    [placeholder_output_ty])));
                        let sized_trait_def_id =
                            tcx.require_lang_item(LangItem::Sized,
                                obligation.cause.span);
                        nested.push(obligation.with(tcx,
                                sig.output().map_bound(|output_ty|
                                        {
                                            ty::TraitRef::new(tcx, sized_trait_def_id, [output_ty])
                                        })));
                        (trait_ref, args.kind_ty())
                    }
                    _ =>
                        ::rustc_middle::util::bug::bug_fmt(format_args!("expected callable type for AsyncFn candidate")),
                };
            nested.extend(self.equate_trait_refs(obligation.with(tcx,
                            placeholder_predicate), trait_ref)?);
            let goal_kind =
                self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
            if let Some(closure_kind) =
                    self.infcx.shallow_resolve(kind_ty).to_opt_closure_kind() {
                if !closure_kind.extends(goal_kind) {
                    return Err(SelectionError::Unimplemented);
                }
            } else {
                nested.push(Obligation::new(self.tcx(),
                        obligation.derived_cause(ObligationCauseCode::BuiltinDerived),
                        obligation.param_env,
                        ty::TraitRef::new(self.tcx(),
                            self.tcx().require_lang_item(LangItem::AsyncFnKindHelper,
                                obligation.cause.span),
                            [kind_ty, Ty::from_closure_kind(self.tcx(), goal_kind)])));
            }
            Ok(nested)
        }
    }
}#[instrument(skip(self), level = "debug")]
814    fn confirm_async_closure_candidate(
815        &mut self,
816        obligation: &PolyTraitObligation<'tcx>,
817    ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
818        let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
819        let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
820
821        let tcx = self.tcx();
822
823        let mut nested = PredicateObligations::new();
824        let (trait_ref, kind_ty) = match *self_ty.kind() {
825            ty::CoroutineClosure(_, args) => {
826                let args = args.as_coroutine_closure();
827                let trait_ref = args.coroutine_closure_sig().map_bound(|sig| {
828                    ty::TraitRef::new(
829                        self.tcx(),
830                        obligation.predicate.def_id(),
831                        [self_ty, sig.tupled_inputs_ty],
832                    )
833                });
834
835                // Note that unlike below, we don't need to check `Future + Sized` for
836                // the output coroutine because they are `Future + Sized` by construction.
837
838                (trait_ref, args.kind_ty())
839            }
840            ty::FnDef(..) | ty::FnPtr(..) => {
841                let sig = self_ty.fn_sig(tcx);
842                let trait_ref = sig.map_bound(|sig| {
843                    ty::TraitRef::new(
844                        self.tcx(),
845                        obligation.predicate.def_id(),
846                        [self_ty, Ty::new_tup(tcx, sig.inputs())],
847                    )
848                });
849
850                // We must additionally check that the return type impls `Future + Sized`.
851                let future_trait_def_id =
852                    tcx.require_lang_item(LangItem::Future, obligation.cause.span);
853                nested.push(obligation.with(
854                    tcx,
855                    sig.output().map_bound(|output_ty| {
856                        ty::TraitRef::new(tcx, future_trait_def_id, [output_ty])
857                    }),
858                ));
859                let sized_trait_def_id =
860                    tcx.require_lang_item(LangItem::Sized, obligation.cause.span);
861                nested.push(obligation.with(
862                    tcx,
863                    sig.output().map_bound(|output_ty| {
864                        ty::TraitRef::new(tcx, sized_trait_def_id, [output_ty])
865                    }),
866                ));
867
868                (trait_ref, Ty::from_closure_kind(tcx, ty::ClosureKind::Fn))
869            }
870            ty::Closure(_, args) => {
871                let args = args.as_closure();
872                let sig = args.sig();
873                let trait_ref = sig.map_bound(|sig| {
874                    ty::TraitRef::new(
875                        self.tcx(),
876                        obligation.predicate.def_id(),
877                        [self_ty, sig.inputs()[0]],
878                    )
879                });
880
881                // We must additionally check that the return type impls `Future + Sized`.
882                let future_trait_def_id =
883                    tcx.require_lang_item(LangItem::Future, obligation.cause.span);
884                let placeholder_output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
885                nested.push(obligation.with(
886                    tcx,
887                    ty::TraitRef::new(tcx, future_trait_def_id, [placeholder_output_ty]),
888                ));
889                let sized_trait_def_id =
890                    tcx.require_lang_item(LangItem::Sized, obligation.cause.span);
891                nested.push(obligation.with(
892                    tcx,
893                    sig.output().map_bound(|output_ty| {
894                        ty::TraitRef::new(tcx, sized_trait_def_id, [output_ty])
895                    }),
896                ));
897
898                (trait_ref, args.kind_ty())
899            }
900            _ => bug!("expected callable type for AsyncFn candidate"),
901        };
902
903        nested.extend(
904            self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?,
905        );
906
907        let goal_kind =
908            self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
909
910        // If we have not yet determined the `ClosureKind` of the closure or coroutine-closure,
911        // then additionally register an `AsyncFnKindHelper` goal which will fail if the kind
912        // is constrained to an insufficient type later on.
913        if let Some(closure_kind) = self.infcx.shallow_resolve(kind_ty).to_opt_closure_kind() {
914            if !closure_kind.extends(goal_kind) {
915                return Err(SelectionError::Unimplemented);
916            }
917        } else {
918            nested.push(Obligation::new(
919                self.tcx(),
920                obligation.derived_cause(ObligationCauseCode::BuiltinDerived),
921                obligation.param_env,
922                ty::TraitRef::new(
923                    self.tcx(),
924                    self.tcx()
925                        .require_lang_item(LangItem::AsyncFnKindHelper, obligation.cause.span),
926                    [kind_ty, Ty::from_closure_kind(self.tcx(), goal_kind)],
927                ),
928            ));
929        }
930
931        Ok(nested)
932    }
933
934    /// In the case of closure types and fn pointers,
935    /// we currently treat the input type parameters on the trait as
936    /// outputs. This means that when we have a match we have only
937    /// considered the self type, so we have to go back and make sure
938    /// to relate the argument types too. This is kind of wrong, but
939    /// since we control the full set of impls, also not that wrong,
940    /// and it DOES yield better error messages (since we don't report
941    /// errors as if there is no applicable impl, but rather report
942    /// errors are about mismatched argument types.
943    ///
944    /// Here is an example. Imagine we have a closure expression
945    /// and we desugared it so that the type of the expression is
946    /// `Closure`, and `Closure` expects `i32` as argument. Then it
947    /// is "as if" the compiler generated this impl:
948    /// ```ignore (illustrative)
949    /// impl Fn(i32) for Closure { ... }
950    /// ```
951    /// Now imagine our obligation is `Closure: Fn(usize)`. So far
952    /// we have matched the self type `Closure`. At this point we'll
953    /// compare the `i32` to `usize` and generate an error.
954    ///
955    /// Note that this checking occurs *after* the impl has selected,
956    /// because these output type parameters should not affect the
957    /// selection of the impl. Therefore, if there is a mismatch, we
958    /// report an error to the user.
959    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("equate_trait_refs",
                                    "rustc_trait_selection::traits::select::confirmation",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                                    ::tracing_core::__macro_support::Option::Some(959u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                                    ::tracing_core::field::FieldSet::new(&["obligation",
                                                    "found_trait_ref"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&found_trait_ref)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return:
                    Result<PredicateObligations<'tcx>, SelectionError<'tcx>> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let found_trait_ref =
                self.infcx.instantiate_binder_with_fresh_vars(obligation.cause.span,
                    BoundRegionConversionTime::HigherRankedType,
                    found_trait_ref);
            let Normalized {
                    obligations: nested,
                    value: (obligation_trait_ref, found_trait_ref) } =
                ensure_sufficient_stack(||
                        {
                            normalize_with_depth(self, obligation.param_env,
                                obligation.cause.clone(), obligation.recursion_depth + 1,
                                (obligation.predicate.trait_ref, found_trait_ref))
                        });
            self.infcx.at(&obligation.cause,
                            obligation.param_env).eq(DefineOpaqueTypes::Yes,
                        obligation_trait_ref,
                        found_trait_ref).map(|InferOk { mut obligations, .. }|
                        {
                            obligations.extend(nested);
                            obligations
                        }).map_err(|terr|
                    {
                        SelectionError::SignatureMismatch(Box::new(SignatureMismatchData {
                                    expected_trait_ref: obligation_trait_ref,
                                    found_trait_ref,
                                    terr,
                                }))
                    })
        }
    }
}#[instrument(skip(self), level = "trace")]
960    fn equate_trait_refs(
961        &mut self,
962        obligation: TraitObligation<'tcx>,
963        found_trait_ref: ty::PolyTraitRef<'tcx>,
964    ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
965        let found_trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
966            obligation.cause.span,
967            BoundRegionConversionTime::HigherRankedType,
968            found_trait_ref,
969        );
970        // Normalize the obligation and expected trait refs together, because why not
971        let Normalized { obligations: nested, value: (obligation_trait_ref, found_trait_ref) } =
972            ensure_sufficient_stack(|| {
973                normalize_with_depth(
974                    self,
975                    obligation.param_env,
976                    obligation.cause.clone(),
977                    obligation.recursion_depth + 1,
978                    (obligation.predicate.trait_ref, found_trait_ref),
979                )
980            });
981
982        // needed to define opaque types for tests/ui/type-alias-impl-trait/assoc-projection-ice.rs
983        self.infcx
984            .at(&obligation.cause, obligation.param_env)
985            .eq(DefineOpaqueTypes::Yes, obligation_trait_ref, found_trait_ref)
986            .map(|InferOk { mut obligations, .. }| {
987                obligations.extend(nested);
988                obligations
989            })
990            .map_err(|terr| {
991                SelectionError::SignatureMismatch(Box::new(SignatureMismatchData {
992                    expected_trait_ref: obligation_trait_ref,
993                    found_trait_ref,
994                    terr,
995                }))
996            })
997    }
998
999    fn confirm_trait_upcasting_unsize_candidate(
1000        &mut self,
1001        obligation: &PolyTraitObligation<'tcx>,
1002        idx: usize,
1003    ) -> Result<ImplSource<'tcx, PredicateObligation<'tcx>>, SelectionError<'tcx>> {
1004        let tcx = self.tcx();
1005
1006        // `assemble_candidates_for_unsizing` should ensure there are no late-bound
1007        // regions here. See the comment there for more details.
1008        let predicate = obligation.predicate.no_bound_vars().unwrap();
1009        let a_ty = self.infcx.shallow_resolve(predicate.self_ty());
1010        let b_ty = self.infcx.shallow_resolve(predicate.trait_ref.args.type_at(1));
1011
1012        let ty::Dynamic(a_data, a_region) = *a_ty.kind() else {
1013            ::rustc_middle::util::bug::bug_fmt(format_args!("expected `dyn` type in `confirm_trait_upcasting_unsize_candidate`"))bug!("expected `dyn` type in `confirm_trait_upcasting_unsize_candidate`")
1014        };
1015        let ty::Dynamic(b_data, b_region) = *b_ty.kind() else {
1016            ::rustc_middle::util::bug::bug_fmt(format_args!("expected `dyn` type in `confirm_trait_upcasting_unsize_candidate`"))bug!("expected `dyn` type in `confirm_trait_upcasting_unsize_candidate`")
1017        };
1018
1019        let source_principal = a_data.principal().unwrap().with_self_ty(tcx, a_ty);
1020        let unnormalized_upcast_principal =
1021            util::supertraits(tcx, source_principal).nth(idx).unwrap();
1022
1023        let nested = self
1024            .match_upcast_principal(
1025                obligation,
1026                unnormalized_upcast_principal,
1027                a_data,
1028                b_data,
1029                a_region,
1030                b_region,
1031            )?
1032            .expect("did not expect ambiguity during confirmation");
1033
1034        Ok(ImplSource::Builtin(BuiltinImplSource::TraitUpcasting(idx), nested))
1035    }
1036
1037    fn confirm_builtin_unsize_candidate(
1038        &mut self,
1039        obligation: &PolyTraitObligation<'tcx>,
1040    ) -> Result<ImplSource<'tcx, PredicateObligation<'tcx>>, SelectionError<'tcx>> {
1041        let tcx = self.tcx();
1042
1043        // `assemble_candidates_for_unsizing` should ensure there are no late-bound
1044        // regions here. See the comment there for more details.
1045        let source = self.infcx.shallow_resolve(obligation.self_ty().no_bound_vars().unwrap());
1046        let target = obligation.predicate.skip_binder().trait_ref.args.type_at(1);
1047        let target = self.infcx.shallow_resolve(target);
1048        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:1048",
                        "rustc_trait_selection::traits::select::confirmation",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
                        ::tracing_core::__macro_support::Option::Some(1048u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
                        ::tracing_core::field::FieldSet::new(&["message", "source",
                                        "target"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("confirm_builtin_unsize_candidate")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&source) as
                                            &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&target) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?source, ?target, "confirm_builtin_unsize_candidate");
1049
1050        Ok(match (source.kind(), target.kind()) {
1051            // `dyn Trait + Kx + 'a` -> `dyn Trait + Ky + 'b` (auto traits and lifetime subtyping).
1052            (&ty::Dynamic(data_a, r_a), &ty::Dynamic(data_b, r_b)) => {
1053                // See `assemble_candidates_for_unsizing` for more info.
1054                // We already checked the compatibility of auto traits within `assemble_candidates_for_unsizing`.
1055                let existential_predicates = if data_b.principal().is_some() {
1056                    tcx.mk_poly_existential_predicates_from_iter(
1057                        data_a
1058                            .principal()
1059                            .map(|b| b.map_bound(ty::ExistentialPredicate::Trait))
1060                            .into_iter()
1061                            .chain(
1062                                data_a
1063                                    .projection_bounds()
1064                                    .map(|b| b.map_bound(ty::ExistentialPredicate::Projection)),
1065                            )
1066                            .chain(
1067                                data_b
1068                                    .auto_traits()
1069                                    .map(ty::ExistentialPredicate::AutoTrait)
1070                                    .map(ty::Binder::dummy),
1071                            ),
1072                    )
1073                } else {
1074                    // If we're unsizing to a dyn type that has no principal, then drop
1075                    // the principal and projections from the type. We use the auto traits
1076                    // from the RHS type since as we noted that we've checked for auto
1077                    // trait compatibility during unsizing.
1078                    tcx.mk_poly_existential_predicates_from_iter(
1079                        data_b
1080                            .auto_traits()
1081                            .map(ty::ExistentialPredicate::AutoTrait)
1082                            .map(ty::Binder::dummy),
1083                    )
1084                };
1085                let source_trait = Ty::new_dynamic(tcx, existential_predicates, r_b);
1086
1087                // Require that the traits involved in this upcast are **equal**;
1088                // only the **lifetime bound** is changed.
1089                let InferOk { mut obligations, .. } = self
1090                    .infcx
1091                    .at(&obligation.cause, obligation.param_env)
1092                    .sup(DefineOpaqueTypes::Yes, target, source_trait)
1093                    .map_err(|_| SelectionError::Unimplemented)?;
1094
1095                // Register one obligation for 'a: 'b.
1096                let outlives = ty::OutlivesPredicate(r_a, r_b);
1097                obligations.push(Obligation::with_depth(
1098                    tcx,
1099                    obligation.cause.clone(),
1100                    obligation.recursion_depth + 1,
1101                    obligation.param_env,
1102                    obligation.predicate.rebind(outlives),
1103                ));
1104
1105                ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
1106            }
1107
1108            // `T` -> `dyn Trait`
1109            (_, &ty::Dynamic(data, r)) => {
1110                let mut object_dids = data.auto_traits().chain(data.principal_def_id());
1111                if let Some(did) = object_dids.find(|did| !tcx.is_dyn_compatible(*did)) {
1112                    return Err(SelectionError::TraitDynIncompatible(did));
1113                }
1114
1115                let predicate_to_obligation = |predicate| {
1116                    Obligation::with_depth(
1117                        tcx,
1118                        obligation.cause.clone(),
1119                        obligation.recursion_depth + 1,
1120                        obligation.param_env,
1121                        predicate,
1122                    )
1123                };
1124
1125                // Create obligations:
1126                //  - Casting `T` to `Trait`
1127                //  - For all the various builtin bounds attached to the object cast. (In other
1128                //  words, if the object type is `Foo + Send`, this would create an obligation for
1129                //  the `Send` check.)
1130                //  - Projection predicates
1131                let mut nested: PredicateObligations<'_> = data
1132                    .iter()
1133                    .map(|predicate| predicate_to_obligation(predicate.with_self_ty(tcx, source)))
1134                    .collect();
1135
1136                // We can only make objects from sized types.
1137                let tr = ty::TraitRef::new(
1138                    tcx,
1139                    tcx.require_lang_item(LangItem::Sized, obligation.cause.span),
1140                    [source],
1141                );
1142                nested.push(predicate_to_obligation(tr.upcast(tcx)));
1143
1144                // If the type is `Foo + 'a`, ensure that the type
1145                // being cast to `Foo + 'a` outlives `'a`:
1146                let outlives = ty::OutlivesPredicate(source, r);
1147                nested.push(predicate_to_obligation(
1148                    ty::ClauseKind::TypeOutlives(outlives).upcast(tcx),
1149                ));
1150
1151                ImplSource::Builtin(BuiltinImplSource::Misc, nested)
1152            }
1153
1154            // `[T; n]` -> `[T]`
1155            (&ty::Array(a, _), &ty::Slice(b)) => {
1156                let InferOk { obligations, .. } = self
1157                    .infcx
1158                    .at(&obligation.cause, obligation.param_env)
1159                    .eq(DefineOpaqueTypes::Yes, b, a)
1160                    .map_err(|_| SelectionError::Unimplemented)?;
1161
1162                ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
1163            }
1164
1165            // `Struct<T>` -> `Struct<U>`
1166            (&ty::Adt(def, args_a), &ty::Adt(_, args_b)) => {
1167                let unsizing_params = tcx.unsizing_params_for_adt(def.did());
1168                if unsizing_params.is_empty() {
1169                    return Err(SelectionError::Unimplemented);
1170                }
1171
1172                let tail_field = def.non_enum_variant().tail();
1173                let tail_field_ty = tcx.type_of(tail_field.did);
1174
1175                let mut nested = PredicateObligations::new();
1176
1177                // Extract `TailField<T>` and `TailField<U>` from `Struct<T>` and `Struct<U>`,
1178                // normalizing in the process, since `type_of` returns something directly from
1179                // HIR ty lowering (which means it's un-normalized).
1180                let source_tail = normalize_with_depth_to(
1181                    self,
1182                    obligation.param_env,
1183                    obligation.cause.clone(),
1184                    obligation.recursion_depth + 1,
1185                    tail_field_ty.instantiate(tcx, args_a).skip_norm_wip(),
1186                    &mut nested,
1187                );
1188                let target_tail = normalize_with_depth_to(
1189                    self,
1190                    obligation.param_env,
1191                    obligation.cause.clone(),
1192                    obligation.recursion_depth + 1,
1193                    tail_field_ty.instantiate(tcx, args_b).skip_norm_wip(),
1194                    &mut nested,
1195                );
1196
1197                // Check that the source struct with the target's
1198                // unsizing parameters is equal to the target.
1199                let args =
1200                    tcx.mk_args_from_iter(args_a.iter().enumerate().map(|(i, k)| {
1201                        if unsizing_params.contains(i as u32) { args_b[i] } else { k }
1202                    }));
1203                let new_struct = Ty::new_adt(tcx, def, args);
1204                let InferOk { obligations, .. } = self
1205                    .infcx
1206                    .at(&obligation.cause, obligation.param_env)
1207                    .eq(DefineOpaqueTypes::Yes, target, new_struct)
1208                    .map_err(|_| SelectionError::Unimplemented)?;
1209                nested.extend(obligations);
1210
1211                // Construct the nested `TailField<T>: Unsize<TailField<U>>` predicate.
1212                let tail_unsize_obligation = obligation.with(
1213                    tcx,
1214                    ty::TraitRef::new(
1215                        tcx,
1216                        obligation.predicate.def_id(),
1217                        [source_tail, target_tail],
1218                    ),
1219                );
1220                nested.push(tail_unsize_obligation);
1221
1222                ImplSource::Builtin(BuiltinImplSource::Misc, nested)
1223            }
1224
1225            _ => ::rustc_middle::util::bug::bug_fmt(format_args!("source: {0}, target: {1}",
        source, target))bug!("source: {source}, target: {target}"),
1226        })
1227    }
1228
1229    /// This trait is indirectly exposed on stable, so do *not* extend the set of types that
1230    /// implement the trait without FCP!
1231    fn confirm_bikeshed_guaranteed_no_drop_candidate(
1232        &mut self,
1233        obligation: &PolyTraitObligation<'tcx>,
1234    ) -> ImplSource<'tcx, PredicateObligation<'tcx>> {
1235        let mut obligations = ::thin_vec::ThinVec::new()thin_vec![];
1236
1237        let tcx = self.tcx();
1238        let self_ty = obligation.predicate.self_ty();
1239        match *self_ty.skip_binder().kind() {
1240            // `&mut T` and `&T` always implement `BikeshedGuaranteedNoDrop`.
1241            ty::Ref(..) => {}
1242            // `ManuallyDrop<T>` always implements `BikeshedGuaranteedNoDrop`.
1243            ty::Adt(def, _) if def.is_manually_drop() => {}
1244            // Arrays and tuples implement `BikeshedGuaranteedNoDrop` only if
1245            // their constituent types implement `BikeshedGuaranteedNoDrop`.
1246            ty::Tuple(tys) => {
1247                obligations.extend(tys.iter().map(|elem_ty| {
1248                    obligation.with(
1249                        tcx,
1250                        self_ty.rebind(ty::TraitRef::new(
1251                            tcx,
1252                            obligation.predicate.def_id(),
1253                            [elem_ty],
1254                        )),
1255                    )
1256                }));
1257            }
1258            ty::Array(elem_ty, _) => {
1259                obligations.push(obligation.with(
1260                    tcx,
1261                    self_ty.rebind(ty::TraitRef::new(
1262                        tcx,
1263                        obligation.predicate.def_id(),
1264                        [elem_ty],
1265                    )),
1266                ));
1267            }
1268
1269            // All other types implement `BikeshedGuaranteedNoDrop` only if
1270            // they implement `Copy`. We could be smart here and short-circuit
1271            // some trivially `Copy`/`!Copy` types, but there's no benefit.
1272            ty::FnDef(..)
1273            | ty::FnPtr(..)
1274            | ty::Error(_)
1275            | ty::Uint(_)
1276            | ty::Int(_)
1277            | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1278            | ty::Bool
1279            | ty::Float(_)
1280            | ty::Char
1281            | ty::RawPtr(..)
1282            | ty::Never
1283            | ty::Pat(..)
1284            | ty::Dynamic(..)
1285            | ty::Str
1286            | ty::Slice(_)
1287            | ty::Foreign(..)
1288            | ty::Adt(..)
1289            | ty::Alias(..)
1290            | ty::Param(_)
1291            | ty::Placeholder(..)
1292            | ty::Closure(..)
1293            | ty::CoroutineClosure(..)
1294            | ty::Coroutine(..)
1295            | ty::UnsafeBinder(_)
1296            | ty::CoroutineWitness(..)
1297            | ty::Bound(..) => {
1298                obligations.push(obligation.with(
1299                    tcx,
1300                    self_ty.map_bound(|ty| {
1301                        ty::TraitRef::new(
1302                            tcx,
1303                            tcx.require_lang_item(LangItem::Copy, obligation.cause.span),
1304                            [ty],
1305                        )
1306                    }),
1307                ));
1308            }
1309
1310            ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1311                {
    ::core::panicking::panic_fmt(format_args!("unexpected type `{0:?}`",
            self_ty));
}panic!("unexpected type `{self_ty:?}`")
1312            }
1313        }
1314
1315        ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
1316    }
1317}