Skip to main content

rustc_trait_selection/traits/select/
candidate_assembly.rs

1//! Candidate assembly.
2//!
3//! The selection process begins by examining all in-scope impls,
4//! caller obligations, and so forth and assembling a list of
5//! candidates. See the [rustc dev guide] for more details.
6//!
7//! [rustc dev guide]:https://rustc-dev-guide.rust-lang.org/traits/resolution.html#candidate-assembly
8
9use std::ops::ControlFlow;
10
11use hir::LangItem;
12use hir::def_id::DefId;
13use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
14use rustc_hir::{self as hir, CoroutineDesugaring, CoroutineKind};
15use rustc_infer::traits::{Obligation, PolyTraitObligation, PredicateObligation, SelectionError};
16use rustc_middle::ty::fast_reject::DeepRejectCtxt;
17use rustc_middle::ty::{
18    self, FieldInfo, SizedTraitKind, TraitRef, Ty, TypeVisitableExt, elaborate,
19};
20use rustc_middle::{bug, span_bug};
21use rustc_span::DUMMY_SP;
22use tracing::{debug, instrument, trace};
23
24use super::SelectionCandidate::*;
25use super::{SelectionCandidateSet, SelectionContext, TraitObligationStack};
26use crate::traits::query::evaluate_obligation::InferCtxtExt;
27use crate::traits::util;
28
29impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
30    #[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("assemble_candidates",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(30u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{ meta.fields().value_set(&[]) })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return:
                    Result<SelectionCandidateSet<'tcx>, SelectionError<'tcx>> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let TraitObligationStack { obligation, .. } = *stack;
            let obligation =
                &Obligation {
                        param_env: obligation.param_env,
                        cause: obligation.cause.clone(),
                        recursion_depth: obligation.recursion_depth,
                        predicate: self.infcx.resolve_vars_if_possible(obligation.predicate),
                    };
            if obligation.predicate.skip_binder().self_ty().is_ty_var() {
                {
                    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/candidate_assembly.rs:44",
                                        "rustc_trait_selection::traits::select::candidate_assembly",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                        ::tracing_core::__macro_support::Option::Some(44u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                        ::tracing_core::field::FieldSet::new(&["message", "ty"],
                                            ::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!("ambiguous inference var or opaque type")
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&debug(&obligation.predicate.skip_binder().self_ty())
                                                            as &dyn Value))])
                            });
                    } else { ; }
                };
                return Ok(SelectionCandidateSet {
                            vec: ::alloc::vec::Vec::new(),
                            ambiguous: true,
                        });
            }
            let mut candidates =
                SelectionCandidateSet { vec: Vec::new(), ambiguous: false };
            if obligation.polarity() == ty::PredicatePolarity::Negative {
                self.assemble_candidates_for_trait_alias(obligation,
                    &mut candidates);
                self.assemble_candidates_from_impls(obligation,
                    &mut candidates);
                self.assemble_candidates_from_caller_bounds(stack,
                        &mut candidates)?;
            } else {
                self.assemble_candidates_for_trait_alias(obligation,
                    &mut candidates);
                let def_id = obligation.predicate.def_id();
                let tcx = self.tcx();
                let lang_item = tcx.as_lang_item(def_id);
                match lang_item {
                    Some(LangItem::Copy | LangItem::Clone |
                        LangItem::TrivialClone) => {
                        {
                            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/candidate_assembly.rs:75",
                                                "rustc_trait_selection::traits::select::candidate_assembly",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                                ::tracing_core::__macro_support::Option::Some(75u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                                ::tracing_core::field::FieldSet::new(&["obligation_self_ty"],
                                                    ::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(&obligation.predicate.skip_binder().self_ty())
                                                                    as &dyn Value))])
                                    });
                            } else { ; }
                        };
                        self.assemble_candidates_from_impls(obligation,
                            &mut candidates);
                        self.assemble_builtin_copy_clone_candidate(obligation.predicate.self_ty().skip_binder(),
                            &mut candidates);
                    }
                    Some(LangItem::DiscriminantKind) => {
                        candidates.vec.push(BuiltinCandidate);
                    }
                    Some(LangItem::PointeeTrait) => {
                        candidates.vec.push(BuiltinCandidate);
                    }
                    Some(LangItem::Sized) => {
                        self.assemble_builtin_sized_candidate(obligation.predicate.self_ty().skip_binder(),
                            &mut candidates, SizedTraitKind::Sized);
                    }
                    Some(LangItem::MetaSized) => {
                        self.assemble_builtin_sized_candidate(obligation.predicate.self_ty().skip_binder(),
                            &mut candidates, SizedTraitKind::MetaSized);
                    }
                    Some(LangItem::PointeeSized) => {
                        ::rustc_middle::util::bug::bug_fmt(format_args!("`PointeeSized` is removed during lowering"));
                    }
                    Some(LangItem::Unsize) => {
                        self.assemble_candidates_for_unsizing(obligation,
                            &mut candidates);
                    }
                    Some(LangItem::Destruct) => {
                        self.assemble_const_destruct_candidates(obligation,
                            &mut candidates);
                    }
                    Some(LangItem::TransmuteTrait) => {
                        self.assemble_candidates_from_impls(obligation,
                            &mut candidates);
                        self.assemble_candidates_for_transmutability(obligation,
                            &mut candidates);
                    }
                    Some(LangItem::Tuple) => {
                        self.assemble_candidate_for_tuple(obligation,
                            &mut candidates);
                    }
                    Some(LangItem::FnPtrTrait) => {
                        self.assemble_candidates_for_fn_ptr_trait(obligation,
                            &mut candidates);
                    }
                    Some(LangItem::BikeshedGuaranteedNoDrop) => {
                        self.assemble_candidates_for_bikeshed_guaranteed_no_drop_trait(obligation,
                            &mut candidates);
                    }
                    Some(LangItem::Field) => {
                        self.assemble_candidates_for_field_trait(obligation,
                            &mut candidates);
                    }
                    _ => {
                        match lang_item {
                            Some(LangItem::Coroutine) => {
                                self.assemble_coroutine_candidates(obligation,
                                    &mut candidates);
                            }
                            Some(LangItem::Future) => {
                                self.assemble_future_candidates(obligation,
                                    &mut candidates);
                            }
                            Some(LangItem::Iterator) => {
                                self.assemble_iterator_candidates(obligation,
                                    &mut candidates);
                            }
                            Some(LangItem::FusedIterator) => {
                                self.assemble_fused_iterator_candidates(obligation,
                                    &mut candidates);
                            }
                            Some(LangItem::AsyncIterator) => {
                                self.assemble_async_iterator_candidates(obligation,
                                    &mut candidates);
                            }
                            Some(LangItem::AsyncFnKindHelper) => {
                                self.assemble_async_fn_kind_helper_candidates(obligation,
                                    &mut candidates);
                            }
                            Some(LangItem::AsyncFn | LangItem::AsyncFnMut |
                                LangItem::AsyncFnOnce) => {
                                self.assemble_async_closure_candidates(obligation,
                                    &mut candidates);
                            }
                            Some(LangItem::Fn | LangItem::FnMut | LangItem::FnOnce) => {
                                self.assemble_closure_candidates(obligation,
                                    &mut candidates);
                                self.assemble_fn_pointer_candidates(obligation,
                                    &mut candidates);
                            }
                            _ => {}
                        }
                        self.assemble_candidates_from_impls(obligation,
                            &mut candidates);
                        self.assemble_candidates_from_object_ty(obligation,
                            &mut candidates);
                    }
                }
                self.assemble_candidates_from_projected_tys(obligation,
                    &mut candidates);
                self.assemble_candidates_from_caller_bounds(stack,
                        &mut candidates)?;
                self.assemble_candidates_from_auto_impls(obligation,
                    &mut candidates);
            }
            {
                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/candidate_assembly.rs:183",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(183u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&format_args!("candidate list size: {0}",
                                                                candidates.vec.len()) as &dyn Value))])
                        });
                } else { ; }
            };
            Ok(candidates)
        }
    }
}#[instrument(skip(self, stack), level = "debug")]
31    pub(super) fn assemble_candidates<'o>(
32        &mut self,
33        stack: &TraitObligationStack<'o, 'tcx>,
34    ) -> Result<SelectionCandidateSet<'tcx>, SelectionError<'tcx>> {
35        let TraitObligationStack { obligation, .. } = *stack;
36        let obligation = &Obligation {
37            param_env: obligation.param_env,
38            cause: obligation.cause.clone(),
39            recursion_depth: obligation.recursion_depth,
40            predicate: self.infcx.resolve_vars_if_possible(obligation.predicate),
41        };
42
43        if obligation.predicate.skip_binder().self_ty().is_ty_var() {
44            debug!(ty = ?obligation.predicate.skip_binder().self_ty(), "ambiguous inference var or opaque type");
45            // Self is a type variable (e.g., `_: AsRef<str>`).
46            //
47            // This is somewhat problematic, as the current scheme can't really
48            // handle it turning to be a projection. This does end up as truly
49            // ambiguous in most cases anyway.
50            //
51            // Take the fast path out - this also improves
52            // performance by preventing assemble_candidates_from_impls from
53            // matching every impl for this trait.
54            return Ok(SelectionCandidateSet { vec: vec![], ambiguous: true });
55        }
56
57        let mut candidates = SelectionCandidateSet { vec: Vec::new(), ambiguous: false };
58
59        // Negative trait predicates have different rules than positive trait predicates.
60        if obligation.polarity() == ty::PredicatePolarity::Negative {
61            self.assemble_candidates_for_trait_alias(obligation, &mut candidates);
62            self.assemble_candidates_from_impls(obligation, &mut candidates);
63            self.assemble_candidates_from_caller_bounds(stack, &mut candidates)?;
64        } else {
65            self.assemble_candidates_for_trait_alias(obligation, &mut candidates);
66
67            // Other bounds. Consider both in-scope bounds from fn decl
68            // and applicable impls. There is a certain set of precedence rules here.
69            let def_id = obligation.predicate.def_id();
70            let tcx = self.tcx();
71
72            let lang_item = tcx.as_lang_item(def_id);
73            match lang_item {
74                Some(LangItem::Copy | LangItem::Clone | LangItem::TrivialClone) => {
75                    debug!(obligation_self_ty = ?obligation.predicate.skip_binder().self_ty());
76
77                    // User-defined copy impls are permitted, but only for
78                    // structs and enums.
79                    self.assemble_candidates_from_impls(obligation, &mut candidates);
80
81                    // For other types, we'll use the builtin rules.
82                    self.assemble_builtin_copy_clone_candidate(
83                        obligation.predicate.self_ty().skip_binder(),
84                        &mut candidates,
85                    );
86                }
87                Some(LangItem::DiscriminantKind) => {
88                    // `DiscriminantKind` is automatically implemented for every type.
89                    candidates.vec.push(BuiltinCandidate);
90                }
91                Some(LangItem::PointeeTrait) => {
92                    // `Pointee` is automatically implemented for every type.
93                    candidates.vec.push(BuiltinCandidate);
94                }
95                Some(LangItem::Sized) => {
96                    self.assemble_builtin_sized_candidate(
97                        obligation.predicate.self_ty().skip_binder(),
98                        &mut candidates,
99                        SizedTraitKind::Sized,
100                    );
101                }
102                Some(LangItem::MetaSized) => {
103                    self.assemble_builtin_sized_candidate(
104                        obligation.predicate.self_ty().skip_binder(),
105                        &mut candidates,
106                        SizedTraitKind::MetaSized,
107                    );
108                }
109                Some(LangItem::PointeeSized) => {
110                    bug!("`PointeeSized` is removed during lowering");
111                }
112                Some(LangItem::Unsize) => {
113                    self.assemble_candidates_for_unsizing(obligation, &mut candidates);
114                }
115                Some(LangItem::Destruct) => {
116                    self.assemble_const_destruct_candidates(obligation, &mut candidates);
117                }
118                Some(LangItem::TransmuteTrait) => {
119                    // User-defined transmutability impls are permitted.
120                    self.assemble_candidates_from_impls(obligation, &mut candidates);
121                    self.assemble_candidates_for_transmutability(obligation, &mut candidates);
122                }
123                Some(LangItem::Tuple) => {
124                    self.assemble_candidate_for_tuple(obligation, &mut candidates);
125                }
126                Some(LangItem::FnPtrTrait) => {
127                    self.assemble_candidates_for_fn_ptr_trait(obligation, &mut candidates);
128                }
129                Some(LangItem::BikeshedGuaranteedNoDrop) => {
130                    self.assemble_candidates_for_bikeshed_guaranteed_no_drop_trait(
131                        obligation,
132                        &mut candidates,
133                    );
134                }
135                Some(LangItem::Field) => {
136                    self.assemble_candidates_for_field_trait(obligation, &mut candidates);
137                }
138                _ => {
139                    // We re-match here for traits that can have both builtin impls and user written impls.
140                    // After the builtin impls we need to also add user written impls, which we do not want to
141                    // do in general because just checking if there are any is expensive.
142                    match lang_item {
143                        Some(LangItem::Coroutine) => {
144                            self.assemble_coroutine_candidates(obligation, &mut candidates);
145                        }
146                        Some(LangItem::Future) => {
147                            self.assemble_future_candidates(obligation, &mut candidates);
148                        }
149                        Some(LangItem::Iterator) => {
150                            self.assemble_iterator_candidates(obligation, &mut candidates);
151                        }
152                        Some(LangItem::FusedIterator) => {
153                            self.assemble_fused_iterator_candidates(obligation, &mut candidates);
154                        }
155                        Some(LangItem::AsyncIterator) => {
156                            self.assemble_async_iterator_candidates(obligation, &mut candidates);
157                        }
158                        Some(LangItem::AsyncFnKindHelper) => {
159                            self.assemble_async_fn_kind_helper_candidates(
160                                obligation,
161                                &mut candidates,
162                            );
163                        }
164                        Some(LangItem::AsyncFn | LangItem::AsyncFnMut | LangItem::AsyncFnOnce) => {
165                            self.assemble_async_closure_candidates(obligation, &mut candidates);
166                        }
167                        Some(LangItem::Fn | LangItem::FnMut | LangItem::FnOnce) => {
168                            self.assemble_closure_candidates(obligation, &mut candidates);
169                            self.assemble_fn_pointer_candidates(obligation, &mut candidates);
170                        }
171                        _ => {}
172                    }
173
174                    self.assemble_candidates_from_impls(obligation, &mut candidates);
175                    self.assemble_candidates_from_object_ty(obligation, &mut candidates);
176                }
177            }
178
179            self.assemble_candidates_from_projected_tys(obligation, &mut candidates);
180            self.assemble_candidates_from_caller_bounds(stack, &mut candidates)?;
181            self.assemble_candidates_from_auto_impls(obligation, &mut candidates);
182        }
183        debug!("candidate list size: {}", candidates.vec.len());
184        Ok(candidates)
185    }
186
187    #[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("assemble_candidates_from_projected_tys",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(187u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::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: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            match obligation.predicate.skip_binder().trait_ref.self_ty().kind()
                {
                ty::Alias(ty::AliasTy {
                    kind: ty::Projection { .. } | ty::Opaque { .. }, .. }) => {}
                ty::Infer(ty::TyVar(_)) => {
                    ::rustc_middle::util::bug::span_bug_fmt(obligation.cause.span,
                        format_args!("Self=_ should have been handled by assemble_candidates"));
                }
                _ => return,
            }
            self.infcx.probe(|_|
                    {
                        let poly_trait_predicate =
                            self.infcx.resolve_vars_if_possible(obligation.predicate);
                        let placeholder_trait_predicate =
                            self.infcx.enter_forall_and_leak_universe(poly_trait_predicate);
                        let mut distinct_normalized_bounds = FxHashSet::default();
                        let _ =
                            self.for_each_item_bound::<!>(placeholder_trait_predicate.self_ty(),
                                |selcx, bound, idx, alias_bound_kind|
                                    {
                                        let Some(bound) =
                                            bound.as_trait_clause() else {
                                                return ControlFlow::Continue(());
                                            };
                                        if bound.polarity() != placeholder_trait_predicate.polarity
                                            {
                                            return ControlFlow::Continue(());
                                        }
                                        selcx.infcx.probe(|_|
                                                {
                                                    let bound =
                                                        util::lazily_elaborate_sizedness_candidate(selcx.infcx,
                                                            obligation, bound);
                                                    match selcx.match_normalize_trait_ref(obligation,
                                                            placeholder_trait_predicate.trait_ref,
                                                            bound.map_bound(|pred| pred.trait_ref)) {
                                                        Ok(None) => {
                                                            candidates.vec.push(ProjectionCandidate {
                                                                    idx,
                                                                    kind: alias_bound_kind,
                                                                });
                                                        }
                                                        Ok(Some(normalized_trait)) if
                                                            distinct_normalized_bounds.insert(normalized_trait) => {
                                                            candidates.vec.push(ProjectionCandidate {
                                                                    idx,
                                                                    kind: alias_bound_kind,
                                                                });
                                                        }
                                                        _ => {}
                                                    }
                                                });
                                        ControlFlow::Continue(())
                                    }, || candidates.ambiguous = true);
                    });
        }
    }
}#[instrument(level = "debug", skip(self, candidates))]
188    fn assemble_candidates_from_projected_tys(
189        &mut self,
190        obligation: &PolyTraitObligation<'tcx>,
191        candidates: &mut SelectionCandidateSet<'tcx>,
192    ) {
193        // Before we go into the whole placeholder thing, just
194        // quickly check if the self-type is a projection at all.
195        match obligation.predicate.skip_binder().trait_ref.self_ty().kind() {
196            // Excluding IATs and type aliases here as they don't have meaningful item bounds.
197            ty::Alias(ty::AliasTy { kind: ty::Projection { .. } | ty::Opaque { .. }, .. }) => {}
198            ty::Infer(ty::TyVar(_)) => {
199                span_bug!(
200                    obligation.cause.span,
201                    "Self=_ should have been handled by assemble_candidates"
202                );
203            }
204            _ => return,
205        }
206
207        self.infcx.probe(|_| {
208            let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
209            let placeholder_trait_predicate =
210                self.infcx.enter_forall_and_leak_universe(poly_trait_predicate);
211
212            // The bounds returned by `item_bounds` may contain duplicates after
213            // normalization, so try to deduplicate when possible to avoid
214            // unnecessary ambiguity.
215            let mut distinct_normalized_bounds = FxHashSet::default();
216            let _ = self.for_each_item_bound::<!>(
217                placeholder_trait_predicate.self_ty(),
218                |selcx, bound, idx, alias_bound_kind| {
219                    let Some(bound) = bound.as_trait_clause() else {
220                        return ControlFlow::Continue(());
221                    };
222                    if bound.polarity() != placeholder_trait_predicate.polarity {
223                        return ControlFlow::Continue(());
224                    }
225
226                    selcx.infcx.probe(|_| {
227                        let bound = util::lazily_elaborate_sizedness_candidate(
228                            selcx.infcx,
229                            obligation,
230                            bound,
231                        );
232
233                        // We checked the polarity already
234                        match selcx.match_normalize_trait_ref(
235                            obligation,
236                            placeholder_trait_predicate.trait_ref,
237                            bound.map_bound(|pred| pred.trait_ref),
238                        ) {
239                            Ok(None) => {
240                                candidates
241                                    .vec
242                                    .push(ProjectionCandidate { idx, kind: alias_bound_kind });
243                            }
244                            Ok(Some(normalized_trait))
245                                if distinct_normalized_bounds.insert(normalized_trait) =>
246                            {
247                                candidates
248                                    .vec
249                                    .push(ProjectionCandidate { idx, kind: alias_bound_kind });
250                            }
251                            _ => {}
252                        }
253                    });
254
255                    ControlFlow::Continue(())
256                },
257                // On ambiguity.
258                || candidates.ambiguous = true,
259            );
260        });
261    }
262
263    /// Given an obligation like `<SomeTrait for T>`, searches the obligations that the caller
264    /// supplied to find out whether it is listed among them.
265    ///
266    /// Never affects the inference environment.
267    #[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("assemble_candidates_from_caller_bounds",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(267u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{ meta.fields().value_set(&[]) })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: Result<(), SelectionError<'tcx>> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs:273",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(273u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::tracing_core::field::FieldSet::new(&["stack.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(&debug(&stack.obligation)
                                                        as &dyn Value))])
                        });
                } else { ; }
            };
            let bounds =
                stack.obligation.param_env.caller_bounds().iter().filter_map(|p|
                            p.as_trait_clause()).filter(|p|
                        p.polarity() == stack.obligation.predicate.polarity());
            let drcx = DeepRejectCtxt::relate_rigid_rigid(self.tcx());
            let obligation_args =
                stack.obligation.predicate.skip_binder().trait_ref.args;
            for bound in bounds {
                let bound =
                    util::lazily_elaborate_sizedness_candidate(self.infcx,
                        stack.obligation, bound);
                if bound.def_id() != stack.obligation.predicate.def_id() {
                    continue;
                }
                let bound_trait_ref = bound.map_bound(|t| t.trait_ref);
                if !drcx.args_may_unify(obligation_args,
                            bound_trait_ref.skip_binder().args) {
                    continue;
                }
                let wc = self.where_clause_may_apply(stack, bound_trait_ref)?;
                if wc.may_apply() {
                    candidates.vec.push(ParamCandidate(bound));
                }
            }
            Ok(())
        }
    }
}#[instrument(level = "debug", skip(self, stack, candidates))]
268    fn assemble_candidates_from_caller_bounds<'o>(
269        &mut self,
270        stack: &TraitObligationStack<'o, 'tcx>,
271        candidates: &mut SelectionCandidateSet<'tcx>,
272    ) -> Result<(), SelectionError<'tcx>> {
273        debug!(?stack.obligation);
274
275        let bounds = stack
276            .obligation
277            .param_env
278            .caller_bounds()
279            .iter()
280            .filter_map(|p| p.as_trait_clause())
281            // Micro-optimization: filter out predicates with different polarities.
282            .filter(|p| p.polarity() == stack.obligation.predicate.polarity());
283
284        let drcx = DeepRejectCtxt::relate_rigid_rigid(self.tcx());
285        let obligation_args = stack.obligation.predicate.skip_binder().trait_ref.args;
286        // Keep only those bounds which may apply, and propagate overflow if it occurs.
287        for bound in bounds {
288            let bound =
289                util::lazily_elaborate_sizedness_candidate(self.infcx, stack.obligation, bound);
290
291            // Micro-optimization: filter out predicates relating to different traits.
292            if bound.def_id() != stack.obligation.predicate.def_id() {
293                continue;
294            }
295
296            let bound_trait_ref = bound.map_bound(|t| t.trait_ref);
297            if !drcx.args_may_unify(obligation_args, bound_trait_ref.skip_binder().args) {
298                continue;
299            }
300            let wc = self.where_clause_may_apply(stack, bound_trait_ref)?;
301            if wc.may_apply() {
302                candidates.vec.push(ParamCandidate(bound));
303            }
304        }
305
306        Ok(())
307    }
308
309    fn assemble_coroutine_candidates(
310        &mut self,
311        obligation: &PolyTraitObligation<'tcx>,
312        candidates: &mut SelectionCandidateSet<'tcx>,
313    ) {
314        // Okay to skip binder because the args on coroutine types never
315        // touch bound regions, they just capture the in-scope
316        // type/region parameters.
317        let self_ty = obligation.self_ty().skip_binder();
318        match self_ty.kind() {
319            // `async`/`gen` constructs get lowered to a special kind of coroutine that
320            // should *not* `impl Coroutine`.
321            ty::Coroutine(did, ..) if self.tcx().is_general_coroutine(*did) => {
322                {
    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/candidate_assembly.rs:322",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(322u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message", "self_ty",
                                        "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!("assemble_coroutine_candidates")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&self_ty) 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!(?self_ty, ?obligation, "assemble_coroutine_candidates");
323
324                candidates.vec.push(CoroutineCandidate);
325            }
326            ty::Infer(ty::TyVar(_)) => {
327                {
    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/candidate_assembly.rs:327",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(327u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("assemble_coroutine_candidates: ambiguous self-type")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("assemble_coroutine_candidates: ambiguous self-type");
328                candidates.ambiguous = true;
329            }
330            _ => {}
331        }
332    }
333
334    fn assemble_future_candidates(
335        &mut self,
336        obligation: &PolyTraitObligation<'tcx>,
337        candidates: &mut SelectionCandidateSet<'tcx>,
338    ) {
339        let self_ty = obligation.self_ty().skip_binder();
340        if let ty::Coroutine(did, ..) = self_ty.kind() {
341            // async constructs get lowered to a special kind of coroutine that
342            // should directly `impl Future`.
343            if self.tcx().coroutine_is_async(*did) {
344                {
    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/candidate_assembly.rs:344",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(344u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message", "self_ty",
                                        "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!("assemble_future_candidates")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&self_ty) 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!(?self_ty, ?obligation, "assemble_future_candidates");
345
346                candidates.vec.push(FutureCandidate);
347            }
348        }
349    }
350
351    fn assemble_iterator_candidates(
352        &mut self,
353        obligation: &PolyTraitObligation<'tcx>,
354        candidates: &mut SelectionCandidateSet<'tcx>,
355    ) {
356        let self_ty = obligation.self_ty().skip_binder();
357        // gen constructs get lowered to a special kind of coroutine that
358        // should directly `impl Iterator`.
359        if let ty::Coroutine(did, ..) = self_ty.kind()
360            && self.tcx().coroutine_is_gen(*did)
361        {
362            {
    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/candidate_assembly.rs:362",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(362u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message", "self_ty",
                                        "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!("assemble_iterator_candidates")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&self_ty) 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!(?self_ty, ?obligation, "assemble_iterator_candidates");
363
364            candidates.vec.push(IteratorCandidate);
365        }
366    }
367
368    fn assemble_fused_iterator_candidates(
369        &mut self,
370        obligation: &PolyTraitObligation<'tcx>,
371        candidates: &mut SelectionCandidateSet<'tcx>,
372    ) {
373        if self.coroutine_is_gen(obligation.self_ty().skip_binder()) {
374            candidates.vec.push(BuiltinCandidate);
375        }
376    }
377
378    fn assemble_async_iterator_candidates(
379        &mut self,
380        obligation: &PolyTraitObligation<'tcx>,
381        candidates: &mut SelectionCandidateSet<'tcx>,
382    ) {
383        let self_ty = obligation.self_ty().skip_binder();
384        if let ty::Coroutine(did, args) = *self_ty.kind() {
385            // gen constructs get lowered to a special kind of coroutine that
386            // should directly `impl AsyncIterator`.
387            if self.tcx().coroutine_is_async_gen(did) {
388                {
    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/candidate_assembly.rs:388",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(388u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message", "self_ty",
                                        "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!("assemble_iterator_candidates")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&self_ty) 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!(?self_ty, ?obligation, "assemble_iterator_candidates");
389
390                // Can only confirm this candidate if we have constrained
391                // the `Yield` type to at least `Poll<Option<?0>>`..
392                let ty::Adt(_poll_def, args) = *args.as_coroutine().yield_ty().kind() else {
393                    candidates.ambiguous = true;
394                    return;
395                };
396                let ty::Adt(_option_def, _) = *args.type_at(0).kind() else {
397                    candidates.ambiguous = true;
398                    return;
399                };
400
401                candidates.vec.push(AsyncIteratorCandidate);
402            }
403        }
404    }
405
406    /// Checks for the artificial impl that the compiler will create for an obligation like `X :
407    /// FnMut<..>` where `X` is a closure type.
408    ///
409    /// Note: the type parameters on a closure candidate are modeled as *output* type
410    /// parameters and hence do not affect whether this trait is a match or not. They will be
411    /// unified during the confirmation step.
412    fn assemble_closure_candidates(
413        &mut self,
414        obligation: &PolyTraitObligation<'tcx>,
415        candidates: &mut SelectionCandidateSet<'tcx>,
416    ) {
417        let kind = self.tcx().fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
418
419        // Okay to skip binder because the args on closure types never
420        // touch bound regions, they just capture the in-scope
421        // type/region parameters
422        let self_ty = obligation.self_ty().skip_binder();
423        match *self_ty.kind() {
424            ty::Closure(def_id, _) => {
425                let is_const = self.tcx().is_const_fn(def_id);
426                {
    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/candidate_assembly.rs:426",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(426u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message", "kind",
                                        "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!("assemble_unboxed_candidates")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&kind) 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!(?kind, ?obligation, "assemble_unboxed_candidates");
427                match self.infcx.closure_kind(self_ty) {
428                    Some(closure_kind) => {
429                        {
    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/candidate_assembly.rs:429",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(429u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "closure_kind"],
                            ::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!("assemble_unboxed_candidates")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&closure_kind)
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(?closure_kind, "assemble_unboxed_candidates");
430                        if closure_kind.extends(kind) {
431                            candidates.vec.push(ClosureCandidate { is_const });
432                        }
433                    }
434                    None => {
435                        if kind == ty::ClosureKind::FnOnce {
436                            candidates.vec.push(ClosureCandidate { is_const });
437                        } else {
438                            candidates.ambiguous = true;
439                        }
440                    }
441                }
442            }
443            ty::CoroutineClosure(def_id, args) => {
444                let args = args.as_coroutine_closure();
445                let is_const = self.tcx().is_const_fn(def_id);
446                if let Some(closure_kind) = self.infcx.closure_kind(self_ty)
447                    // Ambiguity if upvars haven't been constrained yet
448                    && !args.tupled_upvars_ty().is_ty_var()
449                {
450                    // A coroutine-closure implements `FnOnce` *always*, since it may
451                    // always be called once. It additionally implements `Fn`/`FnMut`
452                    // only if it has no upvars referencing the closure-env lifetime,
453                    // and if the closure kind permits it.
454                    if closure_kind.extends(kind) && !args.has_self_borrows() {
455                        candidates.vec.push(ClosureCandidate { is_const });
456                    } else if kind == ty::ClosureKind::FnOnce {
457                        candidates.vec.push(ClosureCandidate { is_const });
458                    }
459                } else if kind == ty::ClosureKind::FnOnce {
460                    candidates.vec.push(ClosureCandidate { is_const });
461                } else {
462                    // This stays ambiguous until kind+upvars are determined.
463                    candidates.ambiguous = true;
464                }
465            }
466            ty::Infer(ty::TyVar(_)) => {
467                {
    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/candidate_assembly.rs:467",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(467u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("assemble_unboxed_closure_candidates: ambiguous self-type")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("assemble_unboxed_closure_candidates: ambiguous self-type");
468                candidates.ambiguous = true;
469            }
470            _ => {}
471        }
472    }
473
474    #[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("assemble_async_closure_candidates",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(474u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::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: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let goal_kind =
                self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
            {
                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/candidate_assembly.rs:483",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(483u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&format_args!("self_ty = {0:?}",
                                                                obligation.self_ty().skip_binder().kind()) as &dyn Value))])
                        });
                } else { ; }
            };
            match *obligation.self_ty().skip_binder().kind() {
                ty::CoroutineClosure(def_id, args) => {
                    if let Some(closure_kind) =
                                args.as_coroutine_closure().kind_ty().to_opt_closure_kind()
                            && !closure_kind.extends(goal_kind) {
                        return;
                    }
                    let Some(coroutine_kind) =
                        self.tcx().coroutine_kind(self.tcx().coroutine_for_closure(def_id)) else {
                            ::rustc_middle::util::bug::bug_fmt(format_args!("coroutine with no kind"));
                        };
                    {
                        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/candidate_assembly.rs:500",
                                            "rustc_trait_selection::traits::select::candidate_assembly",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                            ::tracing_core::__macro_support::Option::Some(500u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                            ::tracing_core::field::FieldSet::new(&["coroutine_kind"],
                                                ::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(&coroutine_kind)
                                                                as &dyn Value))])
                                });
                        } else { ; }
                    };
                    match coroutine_kind {
                        CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => {
                            candidates.vec.push(AsyncClosureCandidate);
                        }
                        _ => (),
                    }
                }
                ty::Closure(_, args) => {
                    if let Some(closure_kind) =
                                args.as_closure().kind_ty().to_opt_closure_kind() &&
                            !closure_kind.extends(goal_kind) {
                        return;
                    }
                    candidates.vec.push(AsyncClosureCandidate);
                }
                ty::FnPtr(sig_tys, hdr) => {
                    if sig_tys.with(hdr).is_fn_trait_compatible() {
                        candidates.vec.push(AsyncClosureCandidate);
                    }
                }
                ty::FnDef(def_id, _) => {
                    let tcx = self.tcx();
                    if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
                            && tcx.codegen_fn_attrs(def_id).target_features.is_empty() {
                        candidates.vec.push(AsyncClosureCandidate);
                    }
                }
                _ => {}
            }
        }
    }
}#[instrument(level = "debug", skip(self, candidates))]
475    fn assemble_async_closure_candidates(
476        &mut self,
477        obligation: &PolyTraitObligation<'tcx>,
478        candidates: &mut SelectionCandidateSet<'tcx>,
479    ) {
480        let goal_kind =
481            self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
482
483        debug!("self_ty = {:?}", obligation.self_ty().skip_binder().kind());
484        match *obligation.self_ty().skip_binder().kind() {
485            ty::CoroutineClosure(def_id, args) => {
486                if let Some(closure_kind) =
487                    args.as_coroutine_closure().kind_ty().to_opt_closure_kind()
488                    && !closure_kind.extends(goal_kind)
489                {
490                    return;
491                }
492
493                // Make sure this is actually an async closure.
494                let Some(coroutine_kind) =
495                    self.tcx().coroutine_kind(self.tcx().coroutine_for_closure(def_id))
496                else {
497                    bug!("coroutine with no kind");
498                };
499
500                debug!(?coroutine_kind);
501                match coroutine_kind {
502                    CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => {
503                        candidates.vec.push(AsyncClosureCandidate);
504                    }
505                    _ => (),
506                }
507            }
508            // Closures and fn pointers implement `AsyncFn*` if their return types
509            // implement `Future`, which is checked later.
510            ty::Closure(_, args) => {
511                if let Some(closure_kind) = args.as_closure().kind_ty().to_opt_closure_kind()
512                    && !closure_kind.extends(goal_kind)
513                {
514                    return;
515                }
516                candidates.vec.push(AsyncClosureCandidate);
517            }
518            // Provide an impl, but only for suitable `fn` pointers.
519            ty::FnPtr(sig_tys, hdr) => {
520                if sig_tys.with(hdr).is_fn_trait_compatible() {
521                    candidates.vec.push(AsyncClosureCandidate);
522                }
523            }
524            // Provide an impl for suitable functions, rejecting `#[target_feature]` functions (RFC 2396).
525            ty::FnDef(def_id, _) => {
526                let tcx = self.tcx();
527                if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
528                    && tcx.codegen_fn_attrs(def_id).target_features.is_empty()
529                {
530                    candidates.vec.push(AsyncClosureCandidate);
531                }
532            }
533            _ => {}
534        }
535    }
536
537    fn assemble_async_fn_kind_helper_candidates(
538        &mut self,
539        obligation: &PolyTraitObligation<'tcx>,
540        candidates: &mut SelectionCandidateSet<'tcx>,
541    ) {
542        let self_ty = obligation.self_ty().skip_binder();
543        let target_kind_ty = obligation.predicate.skip_binder().trait_ref.args.type_at(1);
544
545        // `to_opt_closure_kind` is kind of ICEy when it sees non-int types.
546        if !(self_ty.is_integral() || self_ty.is_ty_var()) {
547            return;
548        }
549        if !(target_kind_ty.is_integral() || self_ty.is_ty_var()) {
550            return;
551        }
552
553        // Check that the self kind extends the goal kind. If it does,
554        // then there's nothing else to check.
555        if let Some(closure_kind) = self_ty.to_opt_closure_kind()
556            && let Some(goal_kind) = target_kind_ty.to_opt_closure_kind()
557            && closure_kind.extends(goal_kind)
558        {
559            candidates.vec.push(AsyncFnKindHelperCandidate);
560        }
561    }
562
563    /// Implements one of the `Fn()` family for a fn pointer.
564    fn assemble_fn_pointer_candidates(
565        &mut self,
566        obligation: &PolyTraitObligation<'tcx>,
567        candidates: &mut SelectionCandidateSet<'tcx>,
568    ) {
569        // Keep this function in sync with extract_tupled_inputs_and_output_from_callable
570        // until the old solver (and thus this function) is removed.
571
572        // Okay to skip binder because what we are inspecting doesn't involve bound regions.
573        let self_ty = obligation.self_ty().skip_binder();
574        match *self_ty.kind() {
575            ty::Infer(ty::TyVar(_)) => {
576                {
    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/candidate_assembly.rs:576",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(576u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("assemble_fn_pointer_candidates: ambiguous self-type")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("assemble_fn_pointer_candidates: ambiguous self-type");
577                candidates.ambiguous = true; // Could wind up being a fn() type.
578            }
579            // Provide an impl, but only for suitable `fn` pointers.
580            ty::FnPtr(sig_tys, hdr) => {
581                if sig_tys.with(hdr).is_fn_trait_compatible() {
582                    candidates.vec.push(FnPointerCandidate);
583                }
584            }
585            // Provide an impl for suitable functions, rejecting `#[target_feature]` functions (RFC 2396).
586            ty::FnDef(def_id, _) => {
587                let tcx = self.tcx();
588                if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
589                    && tcx.codegen_fn_attrs(def_id).target_features.is_empty()
590                {
591                    candidates.vec.push(FnPointerCandidate);
592                }
593            }
594            _ => {}
595        }
596    }
597
598    /// Searches for impls that might apply to `obligation`.
599    #[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("assemble_candidates_from_impls",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(599u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::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: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let drcx = DeepRejectCtxt::relate_rigid_infer(self.tcx());
            let obligation_args =
                obligation.predicate.skip_binder().trait_ref.args;
            self.tcx().for_each_relevant_impl(obligation.predicate.def_id(),
                obligation.predicate.skip_binder().trait_ref.self_ty(),
                |impl_def_id|
                    {
                        let impl_trait_header =
                            self.tcx().impl_trait_header(impl_def_id);
                        if !drcx.args_may_unify(obligation_args,
                                    impl_trait_header.trait_ref.skip_binder().args) {
                            return;
                        }
                        if self.tcx().defaultness(impl_def_id).is_default() {
                            return;
                        }
                        if self.reject_fn_ptr_impls(impl_def_id, obligation,
                                impl_trait_header.trait_ref.skip_binder().self_ty()) {
                            return;
                        }
                        self.infcx.probe(|_|
                                {
                                    if let Ok(_args) =
                                            self.match_impl(impl_def_id, impl_trait_header, obligation)
                                        {
                                        candidates.vec.push(ImplCandidate(impl_def_id));
                                    }
                                });
                    });
        }
    }
}#[instrument(level = "debug", skip(self, candidates))]
600    fn assemble_candidates_from_impls(
601        &mut self,
602        obligation: &PolyTraitObligation<'tcx>,
603        candidates: &mut SelectionCandidateSet<'tcx>,
604    ) {
605        let drcx = DeepRejectCtxt::relate_rigid_infer(self.tcx());
606        let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
607        self.tcx().for_each_relevant_impl(
608            obligation.predicate.def_id(),
609            obligation.predicate.skip_binder().trait_ref.self_ty(),
610            |impl_def_id| {
611                // Before we create the generic parameters and everything, first
612                // consider a "quick reject". This avoids creating more types
613                // and so forth that we need to.
614                let impl_trait_header = self.tcx().impl_trait_header(impl_def_id);
615                if !drcx
616                    .args_may_unify(obligation_args, impl_trait_header.trait_ref.skip_binder().args)
617                {
618                    return;
619                }
620
621                // For every `default impl`, there's always a non-default `impl`
622                // that will *also* apply. There's no reason to register a candidate
623                // for this impl, since it is *not* proof that the trait goal holds.
624                if self.tcx().defaultness(impl_def_id).is_default() {
625                    return;
626                }
627
628                if self.reject_fn_ptr_impls(
629                    impl_def_id,
630                    obligation,
631                    impl_trait_header.trait_ref.skip_binder().self_ty(),
632                ) {
633                    return;
634                }
635
636                self.infcx.probe(|_| {
637                    if let Ok(_args) = self.match_impl(impl_def_id, impl_trait_header, obligation) {
638                        candidates.vec.push(ImplCandidate(impl_def_id));
639                    }
640                });
641            },
642        );
643    }
644
645    /// The various `impl<T: FnPtr> Trait for T` in libcore are more like builtin impls for all function items
646    /// and function pointers and less like blanket impls. Rejecting them when they can't possibly apply (because
647    /// the obligation's self-type does not implement `FnPtr`) avoids reporting that the self type does not implement
648    /// `FnPtr`, when we wanted to report that it doesn't implement `Trait`.
649    x;#[instrument(level = "trace", skip(self), ret)]
650    fn reject_fn_ptr_impls(
651        &mut self,
652        impl_def_id: DefId,
653        obligation: &PolyTraitObligation<'tcx>,
654        impl_self_ty: Ty<'tcx>,
655    ) -> bool {
656        // Let `impl<T: FnPtr> Trait for Vec<T>` go through the normal rejection path.
657        if !matches!(impl_self_ty.kind(), ty::Param(..)) {
658            return false;
659        }
660        let Some(fn_ptr_trait) = self.tcx().lang_items().fn_ptr_trait() else {
661            return false;
662        };
663
664        for &(predicate, _) in self.tcx().predicates_of(impl_def_id).predicates {
665            let ty::ClauseKind::Trait(pred) = predicate.kind().skip_binder() else { continue };
666            if fn_ptr_trait != pred.trait_ref.def_id {
667                continue;
668            }
669            trace!(?pred);
670            // Not the bound we're looking for
671            if pred.self_ty() != impl_self_ty {
672                continue;
673            }
674
675            let self_ty = obligation.self_ty().skip_binder();
676            match self_ty.kind() {
677                // Fast path to avoid evaluating an obligation that trivially holds.
678                // There may be more bounds, but these are checked by the regular path.
679                ty::FnPtr(..) => return false,
680
681                // These may potentially implement `FnPtr`
682                ty::Placeholder(..)
683                | ty::Dynamic(_, _)
684                | ty::Alias(_)
685                | ty::Infer(_)
686                | ty::Param(..)
687                | ty::Bound(_, _) => {}
688
689                // These can't possibly implement `FnPtr` as they are concrete types
690                // and not `FnPtr`
691                ty::Bool
692                | ty::Char
693                | ty::Int(_)
694                | ty::Uint(_)
695                | ty::Float(_)
696                | ty::Adt(_, _)
697                | ty::Foreign(_)
698                | ty::Str
699                | ty::Array(_, _)
700                | ty::Pat(_, _)
701                | ty::Slice(_)
702                | ty::RawPtr(_, _)
703                | ty::Ref(_, _, _)
704                | ty::Closure(..)
705                | ty::CoroutineClosure(..)
706                | ty::Coroutine(_, _)
707                | ty::CoroutineWitness(..)
708                | ty::UnsafeBinder(_)
709                | ty::Never
710                | ty::Tuple(_)
711                | ty::Error(_) => return true,
712                // FIXME: Function definitions could actually implement `FnPtr` by
713                // casting the ZST function def to a function pointer.
714                ty::FnDef(_, _) => return true,
715            }
716
717            // Generic params can implement `FnPtr` if the predicate
718            // holds within its own environment.
719            let obligation = Obligation::new(
720                self.tcx(),
721                obligation.cause.clone(),
722                obligation.param_env,
723                self.tcx().mk_predicate(obligation.predicate.map_bound(|mut pred| {
724                    pred.trait_ref =
725                        ty::TraitRef::new(self.tcx(), fn_ptr_trait, [pred.trait_ref.self_ty()]);
726                    ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred))
727                })),
728            );
729            if let Ok(r) = self.evaluate_root_obligation(&obligation) {
730                if !r.may_apply() {
731                    return true;
732                }
733            }
734        }
735        false
736    }
737
738    fn assemble_candidates_from_auto_impls(
739        &mut self,
740        obligation: &PolyTraitObligation<'tcx>,
741        candidates: &mut SelectionCandidateSet<'tcx>,
742    ) {
743        // Okay to skip binder here because the tests we do below do not involve bound regions.
744        let self_ty = obligation.self_ty().skip_binder();
745        {
    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/candidate_assembly.rs:745",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(745u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "self_ty"],
                            ::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!("assemble_candidates_from_auto_impls")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&self_ty) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?self_ty, "assemble_candidates_from_auto_impls");
746
747        let def_id = obligation.predicate.def_id();
748
749        let mut check_impls = || {
750            // Only consider auto impls if there are no manual impls for the root of `self_ty`.
751            //
752            // For example, we only consider auto candidates for `&i32: Auto` if no explicit impl
753            // for `&SomeType: Auto` exists. Due to E0321 the only crate where impls
754            // for `&SomeType: Auto` can be defined is the crate where `Auto` has been defined.
755            //
756            // Generally, we have to guarantee that for all `SimplifiedType`s the only crate
757            // which may define impls for that type is either the crate defining the type
758            // or the trait. This should be guaranteed by the orphan check.
759            let mut has_impl = false;
760            self.tcx().for_each_relevant_impl(def_id, self_ty, |_| has_impl = true);
761            if !has_impl {
762                candidates.vec.push(AutoImplCandidate)
763            }
764        };
765
766        if self.tcx().trait_is_auto(def_id) {
767            match *self_ty.kind() {
768                ty::Dynamic(..) => {
769                    // For object types, we don't know what the closed
770                    // over types are. This means we conservatively
771                    // say nothing; a candidate may be added by
772                    // `assemble_candidates_from_object_ty`.
773                }
774                ty::Foreign(..) => {
775                    // Since the contents of foreign types is unknown,
776                    // we don't add any `..` impl. Default traits could
777                    // still be provided by a manual implementation for
778                    // this trait and type.
779
780                    // Backward compatibility for default auto traits.
781                    // Test: ui/traits/default_auto_traits/extern-types.rs
782                    if self.tcx().is_default_trait(def_id) {
783                        check_impls()
784                    }
785                }
786                ty::Param(..)
787                | ty::Alias(ty::AliasTy {
788                    kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. },
789                    ..
790                })
791                | ty::Placeholder(..)
792                | ty::Bound(..) => {
793                    // In these cases, we don't know what the actual
794                    // type is. Therefore, we cannot break it down
795                    // into its constituent types. So we don't
796                    // consider the `..` impl but instead just add no
797                    // candidates: this means that typeck will only
798                    // succeed if there is another reason to believe
799                    // that this obligation holds. That could be a
800                    // where-clause or, in the case of an object type,
801                    // it could be that the object type lists the
802                    // trait (e.g., `Foo+Send : Send`). See
803                    // `ui/typeck/typeck-default-trait-impl-send-param.rs`
804                    // for an example of a test case that exercises
805                    // this path.
806                }
807                ty::Infer(ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_)) => {
808                    // The auto impl might apply; we don't know.
809                    candidates.ambiguous = true;
810                }
811                ty::Coroutine(coroutine_def_id, _) => {
812                    if self.tcx().is_lang_item(def_id, LangItem::Unpin) {
813                        match self.tcx().coroutine_movability(coroutine_def_id) {
814                            hir::Movability::Static => {
815                                // Immovable coroutines are never `Unpin`, so
816                                // suppress the normal auto-impl candidate for it.
817                            }
818                            hir::Movability::Movable => {
819                                // Movable coroutines are always `Unpin`, so add an
820                                // unconditional builtin candidate with no sub-obligations.
821                                candidates.vec.push(BuiltinCandidate);
822                            }
823                        }
824                    } else {
825                        if self.should_stall_coroutine(coroutine_def_id) {
826                            candidates.ambiguous = true;
827                        } else {
828                            // Coroutines implement all other auto traits normally.
829                            candidates.vec.push(AutoImplCandidate);
830                        }
831                    }
832                }
833
834                ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
835                    ::rustc_middle::util::bug::bug_fmt(format_args!("asked to assemble auto trait candidates of unexpected type: {0:?}",
        self_ty));bug!(
836                        "asked to assemble auto trait candidates of unexpected type: {:?}",
837                        self_ty
838                    );
839                }
840
841                ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => {
842                    if candidates.vec.iter().any(|c| #[allow(non_exhaustive_omitted_patterns)] match c {
    ProjectionCandidate { .. } => true,
    _ => false,
}matches!(c, ProjectionCandidate { .. })) {
843                        // We do not generate an auto impl candidate for `impl Trait`s which already
844                        // reference our auto trait.
845                        //
846                        // For example during candidate assembly for `impl Send: Send`, we don't have
847                        // to look at the constituent types for this opaque types to figure out that this
848                        // trivially holds.
849                        //
850                        // Note that this is only sound as projection candidates of opaque types
851                        // are always applicable for auto traits.
852                    } else if self.infcx.typing_mode().is_coherence() {
853                        // We do not emit auto trait candidates for opaque types in coherence.
854                        // Doing so can result in weird dependency cycles.
855                        candidates.ambiguous = true;
856                    } else if self.infcx.can_define_opaque_ty(def_id) {
857                        // We do not emit auto trait candidates for opaque types in their defining scope, as
858                        // we need to know the hidden type first, which we can't reliably know within the defining
859                        // scope.
860                        candidates.ambiguous = true;
861                    } else {
862                        candidates.vec.push(AutoImplCandidate)
863                    }
864                }
865
866                ty::CoroutineWitness(..) => {
867                    candidates.vec.push(AutoImplCandidate);
868                }
869
870                ty::Bool
871                | ty::Char
872                | ty::Int(_)
873                | ty::Uint(_)
874                | ty::Float(_)
875                | ty::Str
876                | ty::Array(_, _)
877                | ty::Pat(_, _)
878                | ty::Slice(_)
879                | ty::Adt(..)
880                | ty::RawPtr(_, _)
881                | ty::Ref(..)
882                | ty::FnDef(..)
883                | ty::FnPtr(..)
884                | ty::Closure(..)
885                | ty::CoroutineClosure(..)
886                | ty::Never
887                | ty::Tuple(_)
888                | ty::UnsafeBinder(_) => {
889                    // Only consider auto impls of unsafe traits when there are
890                    // no unsafe fields.
891                    if self.tcx().trait_def(def_id).safety.is_unsafe()
892                        && self_ty.has_unsafe_fields()
893                    {
894                        return;
895                    }
896
897                    check_impls();
898                }
899                ty::Error(_) => {
900                    candidates.vec.push(AutoImplCandidate);
901                }
902            }
903        }
904    }
905
906    /// Searches for impls that might apply to `obligation`.
907    fn assemble_candidates_from_object_ty(
908        &mut self,
909        obligation: &PolyTraitObligation<'tcx>,
910        candidates: &mut SelectionCandidateSet<'tcx>,
911    ) {
912        {
    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/candidate_assembly.rs:912",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(912u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "self_ty"],
                            ::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!("assemble_candidates_from_object_ty")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligation.self_ty().skip_binder())
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(
913            self_ty = ?obligation.self_ty().skip_binder(),
914            "assemble_candidates_from_object_ty",
915        );
916
917        if self.tcx().is_sizedness_trait(obligation.predicate.def_id()) {
918            // `dyn MetaSized` is valid, but should get its `MetaSized` impl from
919            // being `dyn` (SizedCandidate), not from the object candidate.
920            return;
921        }
922
923        self.infcx.probe(|_snapshot| {
924            let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
925            self.infcx.enter_forall(poly_trait_predicate, |placeholder_trait_predicate| {
926                let self_ty = placeholder_trait_predicate.self_ty();
927                let principal_trait_ref = match self_ty.kind() {
928                    ty::Dynamic(data, ..) => {
929                        if data.auto_traits().any(|did| did == obligation.predicate.def_id()) {
930                            {
    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/candidate_assembly.rs:930",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(930u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_object_ty: matched builtin bound, pushing candidate")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(
931                                "assemble_candidates_from_object_ty: matched builtin bound, \
932                             pushing candidate"
933                            );
934                            candidates.vec.push(BuiltinObjectCandidate);
935                            return;
936                        }
937
938                        if let Some(principal) = data.principal() {
939                            principal.with_self_ty(self.tcx(), self_ty)
940                        } else {
941                            // Only auto trait bounds exist.
942                            return;
943                        }
944                    }
945                    ty::Infer(ty::TyVar(_)) => {
946                        {
    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/candidate_assembly.rs:946",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(946u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_object_ty: ambiguous")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("assemble_candidates_from_object_ty: ambiguous");
947                        candidates.ambiguous = true; // could wind up being an object type
948                        return;
949                    }
950                    _ => return,
951                };
952
953                {
    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/candidate_assembly.rs:953",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(953u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        "principal_trait_ref"],
                            ::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!("assemble_candidates_from_object_ty")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&principal_trait_ref)
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(?principal_trait_ref, "assemble_candidates_from_object_ty");
954
955                // Count only those upcast versions that match the trait-ref
956                // we are looking for. Specifically, do not only check for the
957                // correct trait, but also the correct type parameters.
958                // For example, we may be trying to upcast `Foo` to `Bar<i32>`,
959                // but `Foo` is declared as `trait Foo: Bar<u32>`.
960                let candidate_supertraits = util::supertraits(self.tcx(), principal_trait_ref)
961                    .enumerate()
962                    .filter(|&(_, upcast_trait_ref)| {
963                        self.infcx.probe(|_| {
964                            self.match_normalize_trait_ref(
965                                obligation,
966                                placeholder_trait_predicate.trait_ref,
967                                upcast_trait_ref,
968                            )
969                            .is_ok()
970                        })
971                    })
972                    .map(|(idx, _)| ObjectCandidate(idx));
973
974                candidates.vec.extend(candidate_supertraits);
975            })
976        })
977    }
978
979    /// Searches for unsizing that might apply to `obligation`.
980    fn assemble_candidates_for_unsizing(
981        &mut self,
982        obligation: &PolyTraitObligation<'tcx>,
983        candidates: &mut SelectionCandidateSet<'tcx>,
984    ) {
985        // We currently never consider higher-ranked obligations e.g.
986        // `for<'a> &'a T: Unsize<Trait+'a>` to be implemented. This is not
987        // because they are a priori invalid, and we could potentially add support
988        // for them later, it's just that there isn't really a strong need for it.
989        // A `T: Unsize<U>` obligation is always used as part of a `T: CoerceUnsize<U>`
990        // impl, and those are generally applied to concrete types.
991        //
992        // That said, one might try to write a fn with a where clause like
993        //     for<'a> Foo<'a, T>: Unsize<Foo<'a, Trait>>
994        // where the `'a` is kind of orthogonal to the relevant part of the `Unsize`.
995        // Still, you'd be more likely to write that where clause as
996        //     T: Trait
997        // so it seems ok if we (conservatively) fail to accept that `Unsize`
998        // obligation above. Should be possible to extend this in the future.
999        let Some(trait_pred) = obligation.predicate.no_bound_vars() else {
1000            // Don't add any candidates if there are bound regions.
1001            return;
1002        };
1003        let source = trait_pred.self_ty();
1004        let target = trait_pred.trait_ref.args.type_at(1);
1005
1006        {
    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/candidate_assembly.rs:1006",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(1006u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::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!("assemble_candidates_for_unsizing")
                                            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, "assemble_candidates_for_unsizing");
1007
1008        match (source.kind(), target.kind()) {
1009            // Trait+Kx+'a -> Trait+Ky+'b (upcasts).
1010            (&ty::Dynamic(a_data, a_region), &ty::Dynamic(b_data, b_region)) => {
1011                // Upcast coercions permit several things:
1012                //
1013                // 1. Dropping auto traits, e.g., `Foo + Send` to `Foo`
1014                // 2. Tightening the region bound, e.g., `Foo + 'a` to `Foo + 'b` if `'a: 'b`
1015                // 3. Tightening trait to its super traits, eg. `Foo` to `Bar` if `Foo: Bar`
1016                //
1017                // Note that neither of the first two of these changes requires any
1018                // change at runtime. The third needs to change pointer metadata at runtime.
1019                //
1020                // We always perform upcasting coercions when we can because of reason
1021                // #2 (region bounds).
1022                let principal_def_id_a = a_data.principal_def_id();
1023                let principal_def_id_b = b_data.principal_def_id();
1024                if principal_def_id_a == principal_def_id_b || principal_def_id_b.is_none() {
1025                    // We may upcast to auto traits that are either explicitly listed in
1026                    // the object type's bounds, or implied by the principal trait ref's
1027                    // supertraits.
1028                    let a_auto_traits: FxIndexSet<DefId> = a_data
1029                        .auto_traits()
1030                        .chain(principal_def_id_a.into_iter().flat_map(|principal_def_id| {
1031                            elaborate::supertrait_def_ids(self.tcx(), principal_def_id)
1032                                .filter(|def_id| self.tcx().trait_is_auto(*def_id))
1033                        }))
1034                        .collect();
1035                    let auto_traits_compatible = b_data
1036                        .auto_traits()
1037                        // All of a's auto traits need to be in b's auto traits.
1038                        .all(|b| a_auto_traits.contains(&b));
1039                    if auto_traits_compatible {
1040                        candidates.vec.push(BuiltinUnsizeCandidate);
1041                    }
1042                } else if principal_def_id_a.is_some() && principal_def_id_b.is_some() {
1043                    // not casual unsizing, now check whether this is trait upcasting coercion.
1044                    let principal_a = a_data.principal().unwrap();
1045                    let target_trait_did = principal_def_id_b.unwrap();
1046                    let source_trait_ref = principal_a.with_self_ty(self.tcx(), source);
1047
1048                    for (idx, upcast_trait_ref) in
1049                        util::supertraits(self.tcx(), source_trait_ref).enumerate()
1050                    {
1051                        self.infcx.probe(|_| {
1052                            if upcast_trait_ref.def_id() == target_trait_did
1053                                && let Ok(nested) = self.match_upcast_principal(
1054                                    obligation,
1055                                    upcast_trait_ref,
1056                                    a_data,
1057                                    b_data,
1058                                    a_region,
1059                                    b_region,
1060                                )
1061                            {
1062                                if nested.is_none() {
1063                                    candidates.ambiguous = true;
1064                                }
1065                                candidates.vec.push(TraitUpcastingUnsizeCandidate(idx));
1066                            }
1067                        })
1068                    }
1069                }
1070            }
1071
1072            // `T` -> `Trait`
1073            (_, &ty::Dynamic(_, _)) => {
1074                candidates.vec.push(BuiltinUnsizeCandidate);
1075            }
1076
1077            // Ambiguous handling is below `T` -> `Trait`, because inference
1078            // variables can still implement `Unsize<Trait>` and nested
1079            // obligations will have the final say (likely deferred).
1080            (&ty::Infer(ty::TyVar(_)), _) | (_, &ty::Infer(ty::TyVar(_))) => {
1081                {
    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/candidate_assembly.rs:1081",
                        "rustc_trait_selection::traits::select::candidate_assembly",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                        ::tracing_core::__macro_support::Option::Some(1081u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_for_unsizing: ambiguous")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("assemble_candidates_for_unsizing: ambiguous");
1082                candidates.ambiguous = true;
1083            }
1084
1085            // `[T; n]` -> `[T]`
1086            (&ty::Array(..), &ty::Slice(_)) => {
1087                candidates.vec.push(BuiltinUnsizeCandidate);
1088            }
1089
1090            // `Struct<T>` -> `Struct<U>`
1091            (&ty::Adt(def_id_a, _), &ty::Adt(def_id_b, _)) if def_id_a.is_struct() => {
1092                if def_id_a == def_id_b {
1093                    candidates.vec.push(BuiltinUnsizeCandidate);
1094                }
1095            }
1096
1097            _ => {}
1098        };
1099    }
1100
1101    #[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("assemble_candidates_for_transmutability",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1101u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{ meta.fields().value_set(&[]) })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if obligation.predicate.has_non_region_param() { return; }
            if obligation.has_non_region_infer() {
                candidates.ambiguous = true;
                return;
            }
            candidates.vec.push(TransmutabilityCandidate);
        }
    }
}#[instrument(level = "debug", skip(self, obligation, candidates))]
1102    fn assemble_candidates_for_transmutability(
1103        &mut self,
1104        obligation: &PolyTraitObligation<'tcx>,
1105        candidates: &mut SelectionCandidateSet<'tcx>,
1106    ) {
1107        if obligation.predicate.has_non_region_param() {
1108            return;
1109        }
1110
1111        if obligation.has_non_region_infer() {
1112            candidates.ambiguous = true;
1113            return;
1114        }
1115
1116        candidates.vec.push(TransmutabilityCandidate);
1117    }
1118
1119    #[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("assemble_candidates_for_trait_alias",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1119u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{ meta.fields().value_set(&[]) })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let self_ty = obligation.self_ty().skip_binder();
            {
                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/candidate_assembly.rs:1127",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1127u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::tracing_core::field::FieldSet::new(&["self_ty"],
                                        ::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(&self_ty) as
                                                        &dyn Value))])
                        });
                } else { ; }
            };
            let def_id = obligation.predicate.def_id();
            if self.tcx().is_trait_alias(def_id) {
                candidates.vec.push(TraitAliasCandidate);
            }
        }
    }
}#[instrument(level = "debug", skip(self, obligation, candidates))]
1120    fn assemble_candidates_for_trait_alias(
1121        &mut self,
1122        obligation: &PolyTraitObligation<'tcx>,
1123        candidates: &mut SelectionCandidateSet<'tcx>,
1124    ) {
1125        // Okay to skip binder here because the tests we do below do not involve bound regions.
1126        let self_ty = obligation.self_ty().skip_binder();
1127        debug!(?self_ty);
1128
1129        let def_id = obligation.predicate.def_id();
1130
1131        if self.tcx().is_trait_alias(def_id) {
1132            candidates.vec.push(TraitAliasCandidate);
1133        }
1134    }
1135
1136    /// Assembles `Copy` and `Clone` candidates for built-in types with no libcore-defined
1137    /// `Copy` or `Clone` impls.
1138    #[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("assemble_builtin_copy_clone_candidate",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1138u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::tracing_core::field::FieldSet::new(&["self_ty"],
                                        ::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(&self_ty)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            match *self_ty.kind() {
                ty::FnDef(..) | ty::FnPtr(..) | ty::Error(_) | ty::Tuple(..) |
                    ty::Pat(..) => {
                    candidates.vec.push(BuiltinCandidate);
                }
                ty::Uint(_) | ty::Int(_) |
                    ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | ty::Bool |
                    ty::Float(_) | ty::Char | ty::RawPtr(..) | ty::Never |
                    ty::Ref(_, _, hir::Mutability::Not) | ty::Array(..) => {}
                ty::UnsafeBinder(_) => {}
                ty::Dynamic(..) | ty::Str | ty::Slice(..) | ty::Foreign(..) =>
                    {}
                ty::Ref(_, _, hir::Mutability::Mut) => {}
                ty::Coroutine(coroutine_def_id, args) => {
                    if self.should_stall_coroutine(coroutine_def_id) {
                        candidates.ambiguous = true;
                        return;
                    }
                    match self.tcx().coroutine_movability(coroutine_def_id) {
                        hir::Movability::Static => {}
                        hir::Movability::Movable => {
                            if self.tcx().features().coroutine_clone() {
                                let resolved_upvars =
                                    self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
                                if resolved_upvars.is_ty_var() {
                                    candidates.ambiguous = true;
                                } else { candidates.vec.push(BuiltinCandidate); }
                            }
                        }
                    }
                }
                ty::Closure(_, args) => {
                    let resolved_upvars =
                        self.infcx.shallow_resolve(args.as_closure().tupled_upvars_ty());
                    if resolved_upvars.is_ty_var() {
                        candidates.ambiguous = true;
                    } else { candidates.vec.push(BuiltinCandidate); }
                }
                ty::CoroutineClosure(_, args) => {
                    let resolved_upvars =
                        self.infcx.shallow_resolve(args.as_coroutine_closure().tupled_upvars_ty());
                    if resolved_upvars.is_ty_var() {
                        candidates.ambiguous = true;
                    } else { candidates.vec.push(BuiltinCandidate); }
                }
                ty::CoroutineWitness(..) => {
                    candidates.vec.push(SizedCandidate);
                }
                ty::Adt(..) | ty::Alias(..) | ty::Param(..) |
                    ty::Placeholder(..) => {}
                ty::Infer(ty::TyVar(_)) => { candidates.ambiguous = true; }
                ty::Bound(..) => {}
                ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) |
                    ty::FreshFloatTy(_)) => {
                    ::rustc_middle::util::bug::bug_fmt(format_args!("asked to assemble builtin bounds of unexpected type: {0:?}",
                            self_ty));
                }
            }
        }
    }
}#[instrument(level = "debug", skip(self, candidates))]
1139    fn assemble_builtin_copy_clone_candidate(
1140        &mut self,
1141        self_ty: Ty<'tcx>,
1142        candidates: &mut SelectionCandidateSet<'tcx>,
1143    ) {
1144        match *self_ty.kind() {
1145            // These impls are built-in because we cannot express sufficiently
1146            // generic impls in libcore.
1147            ty::FnDef(..) | ty::FnPtr(..) | ty::Error(_) | ty::Tuple(..) | ty::Pat(..) => {
1148                candidates.vec.push(BuiltinCandidate);
1149            }
1150
1151            // Implementations provided in libcore.
1152            ty::Uint(_)
1153            | ty::Int(_)
1154            | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1155            | ty::Bool
1156            | ty::Float(_)
1157            | ty::Char
1158            | ty::RawPtr(..)
1159            | ty::Never
1160            | ty::Ref(_, _, hir::Mutability::Not)
1161            | ty::Array(..) => {}
1162
1163            // FIXME(unsafe_binder): Should we conditionally
1164            // (i.e. universally) implement copy/clone?
1165            ty::UnsafeBinder(_) => {}
1166
1167            // Not `Sized`, which is a supertrait of `Copy`/`Clone`.
1168            ty::Dynamic(..) | ty::Str | ty::Slice(..) | ty::Foreign(..) => {}
1169
1170            // Not `Copy` or `Clone` by design.
1171            ty::Ref(_, _, hir::Mutability::Mut) => {}
1172
1173            ty::Coroutine(coroutine_def_id, args) => {
1174                if self.should_stall_coroutine(coroutine_def_id) {
1175                    candidates.ambiguous = true;
1176                    return;
1177                }
1178
1179                match self.tcx().coroutine_movability(coroutine_def_id) {
1180                    hir::Movability::Static => {}
1181                    hir::Movability::Movable => {
1182                        if self.tcx().features().coroutine_clone() {
1183                            let resolved_upvars =
1184                                self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
1185                            if resolved_upvars.is_ty_var() {
1186                                // Not yet resolved.
1187                                candidates.ambiguous = true;
1188                            } else {
1189                                candidates.vec.push(BuiltinCandidate);
1190                            }
1191                        }
1192                    }
1193                }
1194            }
1195
1196            ty::Closure(_, args) => {
1197                let resolved_upvars =
1198                    self.infcx.shallow_resolve(args.as_closure().tupled_upvars_ty());
1199                if resolved_upvars.is_ty_var() {
1200                    // Not yet resolved.
1201                    candidates.ambiguous = true;
1202                } else {
1203                    candidates.vec.push(BuiltinCandidate);
1204                }
1205            }
1206
1207            ty::CoroutineClosure(_, args) => {
1208                let resolved_upvars =
1209                    self.infcx.shallow_resolve(args.as_coroutine_closure().tupled_upvars_ty());
1210                if resolved_upvars.is_ty_var() {
1211                    // Not yet resolved.
1212                    candidates.ambiguous = true;
1213                } else {
1214                    candidates.vec.push(BuiltinCandidate);
1215                }
1216            }
1217
1218            ty::CoroutineWitness(..) => {
1219                candidates.vec.push(SizedCandidate);
1220            }
1221
1222            // Fallback to whatever user-defined impls or param-env clauses exist in this case.
1223            ty::Adt(..) | ty::Alias(..) | ty::Param(..) | ty::Placeholder(..) => {}
1224
1225            ty::Infer(ty::TyVar(_)) => {
1226                candidates.ambiguous = true;
1227            }
1228
1229            // Only appears when assembling higher-ranked `for<T> T: Clone`.
1230            ty::Bound(..) => {}
1231
1232            ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1233                bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
1234            }
1235        }
1236    }
1237
1238    /// Assembles the `Sized` and `MetaSized` traits which are built-in to the language itself.
1239    #[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("assemble_builtin_sized_candidate",
                                    "rustc_trait_selection::traits::select::candidate_assembly",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1239u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
                                    ::tracing_core::field::FieldSet::new(&["self_ty",
                                                    "sizedness"],
                                        ::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(&self_ty)
                                                            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(&sizedness)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            match *self_ty.kind() {
                ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | ty::Uint(_) |
                    ty::Int(_) | ty::Bool | ty::Float(_) | ty::FnDef(..) |
                    ty::FnPtr(..) | ty::RawPtr(..) | ty::Char | ty::Ref(..) |
                    ty::Array(..) | ty::Closure(..) | ty::CoroutineClosure(..) |
                    ty::Never | ty::Error(_) => {
                    candidates.vec.push(SizedCandidate);
                }
                ty::Coroutine(coroutine_def_id, _) => {
                    if self.should_stall_coroutine(coroutine_def_id) {
                        candidates.ambiguous = true;
                    } else { candidates.vec.push(SizedCandidate); }
                }
                ty::CoroutineWitness(..) => {
                    candidates.vec.push(SizedCandidate);
                }
                ty::Tuple(..) | ty::Pat(..) | ty::Adt(..) |
                    ty::UnsafeBinder(_) => {
                    candidates.vec.push(SizedCandidate);
                }
                ty::Str | ty::Slice(_) | ty::Dynamic(..) =>
                    match sizedness {
                        SizedTraitKind::Sized => {}
                        SizedTraitKind::MetaSized => {
                            candidates.vec.push(SizedCandidate);
                        }
                    },
                ty::Foreign(..) => {}
                ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => {}
                ty::Infer(ty::TyVar(_)) => { candidates.ambiguous = true; }
                ty::Bound(..) => {}
                ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) |
                    ty::FreshFloatTy(_)) => {
                    ::rustc_middle::util::bug::bug_fmt(format_args!("asked to assemble builtin bounds of unexpected type: {0:?}",
                            self_ty));
                }
            }
        }
    }
}#[instrument(level = "debug", skip(self, candidates))]
1240    fn assemble_builtin_sized_candidate(
1241        &mut self,
1242        self_ty: Ty<'tcx>,
1243        candidates: &mut SelectionCandidateSet<'tcx>,
1244        sizedness: SizedTraitKind,
1245    ) {
1246        match *self_ty.kind() {
1247            // Always sized.
1248            ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1249            | ty::Uint(_)
1250            | ty::Int(_)
1251            | ty::Bool
1252            | ty::Float(_)
1253            | ty::FnDef(..)
1254            | ty::FnPtr(..)
1255            | ty::RawPtr(..)
1256            | ty::Char
1257            | ty::Ref(..)
1258            | ty::Array(..)
1259            | ty::Closure(..)
1260            | ty::CoroutineClosure(..)
1261            | ty::Never
1262            | ty::Error(_) => {
1263                candidates.vec.push(SizedCandidate);
1264            }
1265
1266            ty::Coroutine(coroutine_def_id, _) => {
1267                if self.should_stall_coroutine(coroutine_def_id) {
1268                    candidates.ambiguous = true;
1269                } else {
1270                    candidates.vec.push(SizedCandidate);
1271                }
1272            }
1273
1274            ty::CoroutineWitness(..) => {
1275                candidates.vec.push(SizedCandidate);
1276            }
1277
1278            // Conditionally `Sized`.
1279            ty::Tuple(..) | ty::Pat(..) | ty::Adt(..) | ty::UnsafeBinder(_) => {
1280                candidates.vec.push(SizedCandidate);
1281            }
1282
1283            // `MetaSized` but not `Sized`.
1284            ty::Str | ty::Slice(_) | ty::Dynamic(..) => match sizedness {
1285                SizedTraitKind::Sized => {}
1286                SizedTraitKind::MetaSized => {
1287                    candidates.vec.push(SizedCandidate);
1288                }
1289            },
1290
1291            // Not `MetaSized` or `Sized`.
1292            ty::Foreign(..) => {}
1293
1294            ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => {}
1295
1296            ty::Infer(ty::TyVar(_)) => {
1297                candidates.ambiguous = true;
1298            }
1299
1300            // Only appears when assembling higher-ranked `for<T> T: Sized`.
1301            ty::Bound(..) => {}
1302
1303            ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1304                bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
1305            }
1306        }
1307    }
1308
1309    fn assemble_const_destruct_candidates(
1310        &mut self,
1311        _obligation: &PolyTraitObligation<'tcx>,
1312        candidates: &mut SelectionCandidateSet<'tcx>,
1313    ) {
1314        candidates.vec.push(BuiltinCandidate);
1315    }
1316
1317    fn assemble_candidate_for_tuple(
1318        &mut self,
1319        obligation: &PolyTraitObligation<'tcx>,
1320        candidates: &mut SelectionCandidateSet<'tcx>,
1321    ) {
1322        let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
1323        match self_ty.kind() {
1324            ty::Tuple(_) => {
1325                candidates.vec.push(BuiltinCandidate);
1326            }
1327            ty::Infer(ty::TyVar(_)) => {
1328                candidates.ambiguous = true;
1329            }
1330            ty::Bool
1331            | ty::Char
1332            | ty::Int(_)
1333            | ty::Uint(_)
1334            | ty::Float(_)
1335            | ty::Adt(_, _)
1336            | ty::Foreign(_)
1337            | ty::Str
1338            | ty::Array(_, _)
1339            | ty::Slice(_)
1340            | ty::RawPtr(_, _)
1341            | ty::Ref(_, _, _)
1342            | ty::FnDef(_, _)
1343            | ty::Pat(_, _)
1344            | ty::FnPtr(..)
1345            | ty::UnsafeBinder(_)
1346            | ty::Dynamic(_, _)
1347            | ty::Closure(..)
1348            | ty::CoroutineClosure(..)
1349            | ty::Coroutine(_, _)
1350            | ty::CoroutineWitness(..)
1351            | ty::Never
1352            | ty::Alias(..)
1353            | ty::Param(_)
1354            | ty::Bound(_, _)
1355            | ty::Error(_)
1356            | ty::Infer(_)
1357            | ty::Placeholder(_) => {}
1358        }
1359    }
1360
1361    fn assemble_candidates_for_fn_ptr_trait(
1362        &mut self,
1363        obligation: &PolyTraitObligation<'tcx>,
1364        candidates: &mut SelectionCandidateSet<'tcx>,
1365    ) {
1366        let self_ty = self.infcx.resolve_vars_if_possible(obligation.self_ty());
1367
1368        match self_ty.skip_binder().kind() {
1369            ty::FnPtr(..) => candidates.vec.push(BuiltinCandidate),
1370            ty::Bool
1371            | ty::Char
1372            | ty::Int(_)
1373            | ty::Uint(_)
1374            | ty::Float(_)
1375            | ty::Adt(..)
1376            | ty::Foreign(..)
1377            | ty::Str
1378            | ty::Array(..)
1379            | ty::Pat(..)
1380            | ty::Slice(_)
1381            | ty::RawPtr(_, _)
1382            | ty::Ref(..)
1383            | ty::FnDef(..)
1384            | ty::Placeholder(..)
1385            | ty::Dynamic(..)
1386            | ty::Closure(..)
1387            | ty::CoroutineClosure(..)
1388            | ty::Coroutine(..)
1389            | ty::CoroutineWitness(..)
1390            | ty::UnsafeBinder(_)
1391            | ty::Never
1392            | ty::Tuple(..)
1393            | ty::Alias(..)
1394            | ty::Param(..)
1395            | ty::Bound(..)
1396            | ty::Error(_)
1397            | ty::Infer(
1398                ty::InferTy::IntVar(_)
1399                | ty::InferTy::FloatVar(_)
1400                | ty::InferTy::FreshIntTy(_)
1401                | ty::InferTy::FreshFloatTy(_),
1402            ) => {}
1403            ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)) => {
1404                candidates.ambiguous = true;
1405            }
1406        }
1407    }
1408
1409    fn assemble_candidates_for_bikeshed_guaranteed_no_drop_trait(
1410        &mut self,
1411        obligation: &PolyTraitObligation<'tcx>,
1412        candidates: &mut SelectionCandidateSet<'tcx>,
1413    ) {
1414        match obligation.predicate.self_ty().skip_binder().kind() {
1415            ty::Ref(..)
1416            | ty::Adt(..)
1417            | ty::Tuple(_)
1418            | ty::Array(..)
1419            | ty::FnDef(..)
1420            | ty::FnPtr(..)
1421            | ty::Error(_)
1422            | ty::Uint(_)
1423            | ty::Int(_)
1424            | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1425            | ty::Bool
1426            | ty::Float(_)
1427            | ty::Char
1428            | ty::RawPtr(..)
1429            | ty::Never
1430            | ty::Pat(..)
1431            | ty::Dynamic(..)
1432            | ty::Str
1433            | ty::Slice(_)
1434            | ty::Foreign(..)
1435            | ty::Alias(..)
1436            | ty::Param(_)
1437            | ty::Placeholder(..)
1438            | ty::Closure(..)
1439            | ty::CoroutineClosure(..)
1440            | ty::Coroutine(..)
1441            | ty::UnsafeBinder(_)
1442            | ty::CoroutineWitness(..)
1443            | ty::Bound(..) => {
1444                candidates.vec.push(BikeshedGuaranteedNoDropCandidate);
1445            }
1446
1447            ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1448                candidates.ambiguous = true;
1449            }
1450        }
1451    }
1452
1453    fn assemble_candidates_for_field_trait(
1454        &mut self,
1455        obligation: &PolyTraitObligation<'tcx>,
1456        candidates: &mut SelectionCandidateSet<'tcx>,
1457    ) {
1458        if let ty::Adt(def, args) = obligation.predicate.self_ty().skip_binder().kind()
1459            && let Some(FieldInfo { base, ty, .. }) =
1460                def.field_representing_type_info(self.tcx(), args)
1461            // NOTE: these bounds have to be kept in sync with the definition of the `Field` trait
1462            // in `library/core/src/field.rs` as well as the new trait solver `fn
1463            // consider_builtin_field_candidate` in
1464            // `compiler/rustc_next_trait_solver/src/solve/trait_goals.rs`.
1465            && match self.infcx.evaluate_obligation(&PredicateObligation::new(
1466                self.tcx(),
1467                obligation.cause.clone(),
1468                obligation.param_env,
1469                TraitRef::new(
1470                    self.tcx(),
1471                    self.tcx().require_lang_item(LangItem::Sized, DUMMY_SP),
1472                    [base],
1473                ),
1474            )) {
1475                Ok(res) if res.must_apply_modulo_regions() => true,
1476                _ => false,
1477            }
1478            && match self.infcx.evaluate_obligation(&PredicateObligation::new(
1479                self.tcx(),
1480                obligation.cause.clone(),
1481                obligation.param_env,
1482                TraitRef::new(
1483                    self.tcx(),
1484                    self.tcx().require_lang_item(LangItem::Sized, DUMMY_SP),
1485                    [ty],
1486                ),
1487            )) {
1488                Ok(res) if res.must_apply_modulo_regions() => true,
1489                _ => false,
1490            }
1491            && match base.kind() {
1492                ty::Adt(def, _) => def.is_struct() && !def.repr().packed(),
1493                ty::Tuple(..) => true,
1494                _ => false,
1495            }
1496        {
1497            candidates.vec.push(BuiltinCandidate);
1498        }
1499    }
1500}