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, TypingMode, 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::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::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::Projection | ty::Inherent | ty::Free, ..)
788                | ty::Placeholder(..)
789                | ty::Bound(..) => {
790                    // In these cases, we don't know what the actual
791                    // type is. Therefore, we cannot break it down
792                    // into its constituent types. So we don't
793                    // consider the `..` impl but instead just add no
794                    // candidates: this means that typeck will only
795                    // succeed if there is another reason to believe
796                    // that this obligation holds. That could be a
797                    // where-clause or, in the case of an object type,
798                    // it could be that the object type lists the
799                    // trait (e.g., `Foo+Send : Send`). See
800                    // `ui/typeck/typeck-default-trait-impl-send-param.rs`
801                    // for an example of a test case that exercises
802                    // this path.
803                }
804                ty::Infer(ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_)) => {
805                    // The auto impl might apply; we don't know.
806                    candidates.ambiguous = true;
807                }
808                ty::Coroutine(coroutine_def_id, _) => {
809                    if self.tcx().is_lang_item(def_id, LangItem::Unpin) {
810                        match self.tcx().coroutine_movability(coroutine_def_id) {
811                            hir::Movability::Static => {
812                                // Immovable coroutines are never `Unpin`, so
813                                // suppress the normal auto-impl candidate for it.
814                            }
815                            hir::Movability::Movable => {
816                                // Movable coroutines are always `Unpin`, so add an
817                                // unconditional builtin candidate with no sub-obligations.
818                                candidates.vec.push(BuiltinCandidate);
819                            }
820                        }
821                    } else {
822                        if self.should_stall_coroutine(coroutine_def_id) {
823                            candidates.ambiguous = true;
824                        } else {
825                            // Coroutines implement all other auto traits normally.
826                            candidates.vec.push(AutoImplCandidate);
827                        }
828                    }
829                }
830
831                ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
832                    ::rustc_middle::util::bug::bug_fmt(format_args!("asked to assemble auto trait candidates of unexpected type: {0:?}",
        self_ty));bug!(
833                        "asked to assemble auto trait candidates of unexpected type: {:?}",
834                        self_ty
835                    );
836                }
837
838                ty::Alias(ty::Opaque, alias) => {
839                    if candidates.vec.iter().any(|c| #[allow(non_exhaustive_omitted_patterns)] match c {
    ProjectionCandidate { .. } => true,
    _ => false,
}matches!(c, ProjectionCandidate { .. })) {
840                        // We do not generate an auto impl candidate for `impl Trait`s which already
841                        // reference our auto trait.
842                        //
843                        // For example during candidate assembly for `impl Send: Send`, we don't have
844                        // to look at the constituent types for this opaque types to figure out that this
845                        // trivially holds.
846                        //
847                        // Note that this is only sound as projection candidates of opaque types
848                        // are always applicable for auto traits.
849                    } else if let TypingMode::Coherence = self.infcx.typing_mode() {
850                        // We do not emit auto trait candidates for opaque types in coherence.
851                        // Doing so can result in weird dependency cycles.
852                        candidates.ambiguous = true;
853                    } else if self.infcx.can_define_opaque_ty(alias.def_id) {
854                        // We do not emit auto trait candidates for opaque types in their defining scope, as
855                        // we need to know the hidden type first, which we can't reliably know within the defining
856                        // scope.
857                        candidates.ambiguous = true;
858                    } else {
859                        candidates.vec.push(AutoImplCandidate)
860                    }
861                }
862
863                ty::CoroutineWitness(..) => {
864                    candidates.vec.push(AutoImplCandidate);
865                }
866
867                ty::Bool
868                | ty::Char
869                | ty::Int(_)
870                | ty::Uint(_)
871                | ty::Float(_)
872                | ty::Str
873                | ty::Array(_, _)
874                | ty::Pat(_, _)
875                | ty::Slice(_)
876                | ty::Adt(..)
877                | ty::RawPtr(_, _)
878                | ty::Ref(..)
879                | ty::FnDef(..)
880                | ty::FnPtr(..)
881                | ty::Closure(..)
882                | ty::CoroutineClosure(..)
883                | ty::Never
884                | ty::Tuple(_)
885                | ty::UnsafeBinder(_) => {
886                    // Only consider auto impls of unsafe traits when there are
887                    // no unsafe fields.
888                    if self.tcx().trait_def(def_id).safety.is_unsafe()
889                        && self_ty.has_unsafe_fields()
890                    {
891                        return;
892                    }
893
894                    check_impls();
895                }
896                ty::Error(_) => {
897                    candidates.vec.push(AutoImplCandidate);
898                }
899            }
900        }
901    }
902
903    /// Searches for impls that might apply to `obligation`.
904    fn assemble_candidates_from_object_ty(
905        &mut self,
906        obligation: &PolyTraitObligation<'tcx>,
907        candidates: &mut SelectionCandidateSet<'tcx>,
908    ) {
909        {
    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:909",
                        "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(909u32),
                        ::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!(
910            self_ty = ?obligation.self_ty().skip_binder(),
911            "assemble_candidates_from_object_ty",
912        );
913
914        if self.tcx().is_sizedness_trait(obligation.predicate.def_id()) {
915            // `dyn MetaSized` is valid, but should get its `MetaSized` impl from
916            // being `dyn` (SizedCandidate), not from the object candidate.
917            return;
918        }
919
920        self.infcx.probe(|_snapshot| {
921            let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
922            self.infcx.enter_forall(poly_trait_predicate, |placeholder_trait_predicate| {
923                let self_ty = placeholder_trait_predicate.self_ty();
924                let principal_trait_ref = match self_ty.kind() {
925                    ty::Dynamic(data, ..) => {
926                        if data.auto_traits().any(|did| did == obligation.predicate.def_id()) {
927                            {
    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:927",
                        "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(927u32),
                        ::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!(
928                                "assemble_candidates_from_object_ty: matched builtin bound, \
929                             pushing candidate"
930                            );
931                            candidates.vec.push(BuiltinObjectCandidate);
932                            return;
933                        }
934
935                        if let Some(principal) = data.principal() {
936                            principal.with_self_ty(self.tcx(), self_ty)
937                        } else {
938                            // Only auto trait bounds exist.
939                            return;
940                        }
941                    }
942                    ty::Infer(ty::TyVar(_)) => {
943                        {
    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:943",
                        "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(943u32),
                        ::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");
944                        candidates.ambiguous = true; // could wind up being an object type
945                        return;
946                    }
947                    _ => return,
948                };
949
950                {
    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:950",
                        "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(950u32),
                        ::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");
951
952                // Count only those upcast versions that match the trait-ref
953                // we are looking for. Specifically, do not only check for the
954                // correct trait, but also the correct type parameters.
955                // For example, we may be trying to upcast `Foo` to `Bar<i32>`,
956                // but `Foo` is declared as `trait Foo: Bar<u32>`.
957                let candidate_supertraits = util::supertraits(self.tcx(), principal_trait_ref)
958                    .enumerate()
959                    .filter(|&(_, upcast_trait_ref)| {
960                        self.infcx.probe(|_| {
961                            self.match_normalize_trait_ref(
962                                obligation,
963                                placeholder_trait_predicate.trait_ref,
964                                upcast_trait_ref,
965                            )
966                            .is_ok()
967                        })
968                    })
969                    .map(|(idx, _)| ObjectCandidate(idx));
970
971                candidates.vec.extend(candidate_supertraits);
972            })
973        })
974    }
975
976    /// Searches for unsizing that might apply to `obligation`.
977    fn assemble_candidates_for_unsizing(
978        &mut self,
979        obligation: &PolyTraitObligation<'tcx>,
980        candidates: &mut SelectionCandidateSet<'tcx>,
981    ) {
982        // We currently never consider higher-ranked obligations e.g.
983        // `for<'a> &'a T: Unsize<Trait+'a>` to be implemented. This is not
984        // because they are a priori invalid, and we could potentially add support
985        // for them later, it's just that there isn't really a strong need for it.
986        // A `T: Unsize<U>` obligation is always used as part of a `T: CoerceUnsize<U>`
987        // impl, and those are generally applied to concrete types.
988        //
989        // That said, one might try to write a fn with a where clause like
990        //     for<'a> Foo<'a, T>: Unsize<Foo<'a, Trait>>
991        // where the `'a` is kind of orthogonal to the relevant part of the `Unsize`.
992        // Still, you'd be more likely to write that where clause as
993        //     T: Trait
994        // so it seems ok if we (conservatively) fail to accept that `Unsize`
995        // obligation above. Should be possible to extend this in the future.
996        let Some(trait_pred) = obligation.predicate.no_bound_vars() else {
997            // Don't add any candidates if there are bound regions.
998            return;
999        };
1000        let source = trait_pred.self_ty();
1001        let target = trait_pred.trait_ref.args.type_at(1);
1002
1003        {
    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:1003",
                        "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(1003u32),
                        ::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");
1004
1005        match (source.kind(), target.kind()) {
1006            // Trait+Kx+'a -> Trait+Ky+'b (upcasts).
1007            (&ty::Dynamic(a_data, a_region), &ty::Dynamic(b_data, b_region)) => {
1008                // Upcast coercions permit several things:
1009                //
1010                // 1. Dropping auto traits, e.g., `Foo + Send` to `Foo`
1011                // 2. Tightening the region bound, e.g., `Foo + 'a` to `Foo + 'b` if `'a: 'b`
1012                // 3. Tightening trait to its super traits, eg. `Foo` to `Bar` if `Foo: Bar`
1013                //
1014                // Note that neither of the first two of these changes requires any
1015                // change at runtime. The third needs to change pointer metadata at runtime.
1016                //
1017                // We always perform upcasting coercions when we can because of reason
1018                // #2 (region bounds).
1019                let principal_def_id_a = a_data.principal_def_id();
1020                let principal_def_id_b = b_data.principal_def_id();
1021                if principal_def_id_a == principal_def_id_b || principal_def_id_b.is_none() {
1022                    // We may upcast to auto traits that are either explicitly listed in
1023                    // the object type's bounds, or implied by the principal trait ref's
1024                    // supertraits.
1025                    let a_auto_traits: FxIndexSet<DefId> = a_data
1026                        .auto_traits()
1027                        .chain(principal_def_id_a.into_iter().flat_map(|principal_def_id| {
1028                            elaborate::supertrait_def_ids(self.tcx(), principal_def_id)
1029                                .filter(|def_id| self.tcx().trait_is_auto(*def_id))
1030                        }))
1031                        .collect();
1032                    let auto_traits_compatible = b_data
1033                        .auto_traits()
1034                        // All of a's auto traits need to be in b's auto traits.
1035                        .all(|b| a_auto_traits.contains(&b));
1036                    if auto_traits_compatible {
1037                        candidates.vec.push(BuiltinUnsizeCandidate);
1038                    }
1039                } else if principal_def_id_a.is_some() && principal_def_id_b.is_some() {
1040                    // not casual unsizing, now check whether this is trait upcasting coercion.
1041                    let principal_a = a_data.principal().unwrap();
1042                    let target_trait_did = principal_def_id_b.unwrap();
1043                    let source_trait_ref = principal_a.with_self_ty(self.tcx(), source);
1044
1045                    for (idx, upcast_trait_ref) in
1046                        util::supertraits(self.tcx(), source_trait_ref).enumerate()
1047                    {
1048                        self.infcx.probe(|_| {
1049                            if upcast_trait_ref.def_id() == target_trait_did
1050                                && let Ok(nested) = self.match_upcast_principal(
1051                                    obligation,
1052                                    upcast_trait_ref,
1053                                    a_data,
1054                                    b_data,
1055                                    a_region,
1056                                    b_region,
1057                                )
1058                            {
1059                                if nested.is_none() {
1060                                    candidates.ambiguous = true;
1061                                }
1062                                candidates.vec.push(TraitUpcastingUnsizeCandidate(idx));
1063                            }
1064                        })
1065                    }
1066                }
1067            }
1068
1069            // `T` -> `Trait`
1070            (_, &ty::Dynamic(_, _)) => {
1071                candidates.vec.push(BuiltinUnsizeCandidate);
1072            }
1073
1074            // Ambiguous handling is below `T` -> `Trait`, because inference
1075            // variables can still implement `Unsize<Trait>` and nested
1076            // obligations will have the final say (likely deferred).
1077            (&ty::Infer(ty::TyVar(_)), _) | (_, &ty::Infer(ty::TyVar(_))) => {
1078                {
    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:1078",
                        "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(1078u32),
                        ::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");
1079                candidates.ambiguous = true;
1080            }
1081
1082            // `[T; n]` -> `[T]`
1083            (&ty::Array(..), &ty::Slice(_)) => {
1084                candidates.vec.push(BuiltinUnsizeCandidate);
1085            }
1086
1087            // `Struct<T>` -> `Struct<U>`
1088            (&ty::Adt(def_id_a, _), &ty::Adt(def_id_b, _)) if def_id_a.is_struct() => {
1089                if def_id_a == def_id_b {
1090                    candidates.vec.push(BuiltinUnsizeCandidate);
1091                }
1092            }
1093
1094            _ => {}
1095        };
1096    }
1097
1098    #[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(1098u32),
                                    ::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))]
1099    fn assemble_candidates_for_transmutability(
1100        &mut self,
1101        obligation: &PolyTraitObligation<'tcx>,
1102        candidates: &mut SelectionCandidateSet<'tcx>,
1103    ) {
1104        if obligation.predicate.has_non_region_param() {
1105            return;
1106        }
1107
1108        if obligation.has_non_region_infer() {
1109            candidates.ambiguous = true;
1110            return;
1111        }
1112
1113        candidates.vec.push(TransmutabilityCandidate);
1114    }
1115
1116    #[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(1116u32),
                                    ::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:1124",
                                    "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(1124u32),
                                    ::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))]
1117    fn assemble_candidates_for_trait_alias(
1118        &mut self,
1119        obligation: &PolyTraitObligation<'tcx>,
1120        candidates: &mut SelectionCandidateSet<'tcx>,
1121    ) {
1122        // Okay to skip binder here because the tests we do below do not involve bound regions.
1123        let self_ty = obligation.self_ty().skip_binder();
1124        debug!(?self_ty);
1125
1126        let def_id = obligation.predicate.def_id();
1127
1128        if self.tcx().is_trait_alias(def_id) {
1129            candidates.vec.push(TraitAliasCandidate);
1130        }
1131    }
1132
1133    /// Assembles `Copy` and `Clone` candidates for built-in types with no libcore-defined
1134    /// `Copy` or `Clone` impls.
1135    #[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(1135u32),
                                    ::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))]
1136    fn assemble_builtin_copy_clone_candidate(
1137        &mut self,
1138        self_ty: Ty<'tcx>,
1139        candidates: &mut SelectionCandidateSet<'tcx>,
1140    ) {
1141        match *self_ty.kind() {
1142            // These impls are built-in because we cannot express sufficiently
1143            // generic impls in libcore.
1144            ty::FnDef(..) | ty::FnPtr(..) | ty::Error(_) | ty::Tuple(..) | ty::Pat(..) => {
1145                candidates.vec.push(BuiltinCandidate);
1146            }
1147
1148            // Implementations provided in libcore.
1149            ty::Uint(_)
1150            | ty::Int(_)
1151            | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1152            | ty::Bool
1153            | ty::Float(_)
1154            | ty::Char
1155            | ty::RawPtr(..)
1156            | ty::Never
1157            | ty::Ref(_, _, hir::Mutability::Not)
1158            | ty::Array(..) => {}
1159
1160            // FIXME(unsafe_binder): Should we conditionally
1161            // (i.e. universally) implement copy/clone?
1162            ty::UnsafeBinder(_) => {}
1163
1164            // Not `Sized`, which is a supertrait of `Copy`/`Clone`.
1165            ty::Dynamic(..) | ty::Str | ty::Slice(..) | ty::Foreign(..) => {}
1166
1167            // Not `Copy` or `Clone` by design.
1168            ty::Ref(_, _, hir::Mutability::Mut) => {}
1169
1170            ty::Coroutine(coroutine_def_id, args) => {
1171                if self.should_stall_coroutine(coroutine_def_id) {
1172                    candidates.ambiguous = true;
1173                    return;
1174                }
1175
1176                match self.tcx().coroutine_movability(coroutine_def_id) {
1177                    hir::Movability::Static => {}
1178                    hir::Movability::Movable => {
1179                        if self.tcx().features().coroutine_clone() {
1180                            let resolved_upvars =
1181                                self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
1182                            if resolved_upvars.is_ty_var() {
1183                                // Not yet resolved.
1184                                candidates.ambiguous = true;
1185                            } else {
1186                                candidates.vec.push(BuiltinCandidate);
1187                            }
1188                        }
1189                    }
1190                }
1191            }
1192
1193            ty::Closure(_, args) => {
1194                let resolved_upvars =
1195                    self.infcx.shallow_resolve(args.as_closure().tupled_upvars_ty());
1196                if resolved_upvars.is_ty_var() {
1197                    // Not yet resolved.
1198                    candidates.ambiguous = true;
1199                } else {
1200                    candidates.vec.push(BuiltinCandidate);
1201                }
1202            }
1203
1204            ty::CoroutineClosure(_, args) => {
1205                let resolved_upvars =
1206                    self.infcx.shallow_resolve(args.as_coroutine_closure().tupled_upvars_ty());
1207                if resolved_upvars.is_ty_var() {
1208                    // Not yet resolved.
1209                    candidates.ambiguous = true;
1210                } else {
1211                    candidates.vec.push(BuiltinCandidate);
1212                }
1213            }
1214
1215            ty::CoroutineWitness(..) => {
1216                candidates.vec.push(SizedCandidate);
1217            }
1218
1219            // Fallback to whatever user-defined impls or param-env clauses exist in this case.
1220            ty::Adt(..) | ty::Alias(..) | ty::Param(..) | ty::Placeholder(..) => {}
1221
1222            ty::Infer(ty::TyVar(_)) => {
1223                candidates.ambiguous = true;
1224            }
1225
1226            // Only appears when assembling higher-ranked `for<T> T: Clone`.
1227            ty::Bound(..) => {}
1228
1229            ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1230                bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
1231            }
1232        }
1233    }
1234
1235    /// Assembles the `Sized` and `MetaSized` traits which are built-in to the language itself.
1236    #[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(1236u32),
                                    ::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))]
1237    fn assemble_builtin_sized_candidate(
1238        &mut self,
1239        self_ty: Ty<'tcx>,
1240        candidates: &mut SelectionCandidateSet<'tcx>,
1241        sizedness: SizedTraitKind,
1242    ) {
1243        match *self_ty.kind() {
1244            // Always sized.
1245            ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1246            | ty::Uint(_)
1247            | ty::Int(_)
1248            | ty::Bool
1249            | ty::Float(_)
1250            | ty::FnDef(..)
1251            | ty::FnPtr(..)
1252            | ty::RawPtr(..)
1253            | ty::Char
1254            | ty::Ref(..)
1255            | ty::Array(..)
1256            | ty::Closure(..)
1257            | ty::CoroutineClosure(..)
1258            | ty::Never
1259            | ty::Error(_) => {
1260                candidates.vec.push(SizedCandidate);
1261            }
1262
1263            ty::Coroutine(coroutine_def_id, _) => {
1264                if self.should_stall_coroutine(coroutine_def_id) {
1265                    candidates.ambiguous = true;
1266                } else {
1267                    candidates.vec.push(SizedCandidate);
1268                }
1269            }
1270
1271            ty::CoroutineWitness(..) => {
1272                candidates.vec.push(SizedCandidate);
1273            }
1274
1275            // Conditionally `Sized`.
1276            ty::Tuple(..) | ty::Pat(..) | ty::Adt(..) | ty::UnsafeBinder(_) => {
1277                candidates.vec.push(SizedCandidate);
1278            }
1279
1280            // `MetaSized` but not `Sized`.
1281            ty::Str | ty::Slice(_) | ty::Dynamic(..) => match sizedness {
1282                SizedTraitKind::Sized => {}
1283                SizedTraitKind::MetaSized => {
1284                    candidates.vec.push(SizedCandidate);
1285                }
1286            },
1287
1288            // Not `MetaSized` or `Sized`.
1289            ty::Foreign(..) => {}
1290
1291            ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => {}
1292
1293            ty::Infer(ty::TyVar(_)) => {
1294                candidates.ambiguous = true;
1295            }
1296
1297            // Only appears when assembling higher-ranked `for<T> T: Sized`.
1298            ty::Bound(..) => {}
1299
1300            ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1301                bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
1302            }
1303        }
1304    }
1305
1306    fn assemble_const_destruct_candidates(
1307        &mut self,
1308        _obligation: &PolyTraitObligation<'tcx>,
1309        candidates: &mut SelectionCandidateSet<'tcx>,
1310    ) {
1311        candidates.vec.push(BuiltinCandidate);
1312    }
1313
1314    fn assemble_candidate_for_tuple(
1315        &mut self,
1316        obligation: &PolyTraitObligation<'tcx>,
1317        candidates: &mut SelectionCandidateSet<'tcx>,
1318    ) {
1319        let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
1320        match self_ty.kind() {
1321            ty::Tuple(_) => {
1322                candidates.vec.push(BuiltinCandidate);
1323            }
1324            ty::Infer(ty::TyVar(_)) => {
1325                candidates.ambiguous = true;
1326            }
1327            ty::Bool
1328            | ty::Char
1329            | ty::Int(_)
1330            | ty::Uint(_)
1331            | ty::Float(_)
1332            | ty::Adt(_, _)
1333            | ty::Foreign(_)
1334            | ty::Str
1335            | ty::Array(_, _)
1336            | ty::Slice(_)
1337            | ty::RawPtr(_, _)
1338            | ty::Ref(_, _, _)
1339            | ty::FnDef(_, _)
1340            | ty::Pat(_, _)
1341            | ty::FnPtr(..)
1342            | ty::UnsafeBinder(_)
1343            | ty::Dynamic(_, _)
1344            | ty::Closure(..)
1345            | ty::CoroutineClosure(..)
1346            | ty::Coroutine(_, _)
1347            | ty::CoroutineWitness(..)
1348            | ty::Never
1349            | ty::Alias(..)
1350            | ty::Param(_)
1351            | ty::Bound(_, _)
1352            | ty::Error(_)
1353            | ty::Infer(_)
1354            | ty::Placeholder(_) => {}
1355        }
1356    }
1357
1358    fn assemble_candidates_for_fn_ptr_trait(
1359        &mut self,
1360        obligation: &PolyTraitObligation<'tcx>,
1361        candidates: &mut SelectionCandidateSet<'tcx>,
1362    ) {
1363        let self_ty = self.infcx.resolve_vars_if_possible(obligation.self_ty());
1364
1365        match self_ty.skip_binder().kind() {
1366            ty::FnPtr(..) => candidates.vec.push(BuiltinCandidate),
1367            ty::Bool
1368            | ty::Char
1369            | ty::Int(_)
1370            | ty::Uint(_)
1371            | ty::Float(_)
1372            | ty::Adt(..)
1373            | ty::Foreign(..)
1374            | ty::Str
1375            | ty::Array(..)
1376            | ty::Pat(..)
1377            | ty::Slice(_)
1378            | ty::RawPtr(_, _)
1379            | ty::Ref(..)
1380            | ty::FnDef(..)
1381            | ty::Placeholder(..)
1382            | ty::Dynamic(..)
1383            | ty::Closure(..)
1384            | ty::CoroutineClosure(..)
1385            | ty::Coroutine(..)
1386            | ty::CoroutineWitness(..)
1387            | ty::UnsafeBinder(_)
1388            | ty::Never
1389            | ty::Tuple(..)
1390            | ty::Alias(..)
1391            | ty::Param(..)
1392            | ty::Bound(..)
1393            | ty::Error(_)
1394            | ty::Infer(
1395                ty::InferTy::IntVar(_)
1396                | ty::InferTy::FloatVar(_)
1397                | ty::InferTy::FreshIntTy(_)
1398                | ty::InferTy::FreshFloatTy(_),
1399            ) => {}
1400            ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)) => {
1401                candidates.ambiguous = true;
1402            }
1403        }
1404    }
1405
1406    fn assemble_candidates_for_bikeshed_guaranteed_no_drop_trait(
1407        &mut self,
1408        obligation: &PolyTraitObligation<'tcx>,
1409        candidates: &mut SelectionCandidateSet<'tcx>,
1410    ) {
1411        match obligation.predicate.self_ty().skip_binder().kind() {
1412            ty::Ref(..)
1413            | ty::Adt(..)
1414            | ty::Tuple(_)
1415            | ty::Array(..)
1416            | ty::FnDef(..)
1417            | ty::FnPtr(..)
1418            | ty::Error(_)
1419            | ty::Uint(_)
1420            | ty::Int(_)
1421            | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1422            | ty::Bool
1423            | ty::Float(_)
1424            | ty::Char
1425            | ty::RawPtr(..)
1426            | ty::Never
1427            | ty::Pat(..)
1428            | ty::Dynamic(..)
1429            | ty::Str
1430            | ty::Slice(_)
1431            | ty::Foreign(..)
1432            | ty::Alias(..)
1433            | ty::Param(_)
1434            | ty::Placeholder(..)
1435            | ty::Closure(..)
1436            | ty::CoroutineClosure(..)
1437            | ty::Coroutine(..)
1438            | ty::UnsafeBinder(_)
1439            | ty::CoroutineWitness(..)
1440            | ty::Bound(..) => {
1441                candidates.vec.push(BikeshedGuaranteedNoDropCandidate);
1442            }
1443
1444            ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1445                candidates.ambiguous = true;
1446            }
1447        }
1448    }
1449
1450    fn assemble_candidates_for_field_trait(
1451        &mut self,
1452        obligation: &PolyTraitObligation<'tcx>,
1453        candidates: &mut SelectionCandidateSet<'tcx>,
1454    ) {
1455        if let ty::Adt(def, args) = obligation.predicate.self_ty().skip_binder().kind()
1456            && let Some(FieldInfo { base, ty, .. }) =
1457                def.field_representing_type_info(self.tcx(), args)
1458            // NOTE: these bounds have to be kept in sync with the definition of the `Field` trait
1459            // in `library/core/src/field.rs` as well as the new trait solver `fn
1460            // consider_builtin_field_candidate` in
1461            // `compiler/rustc_next_trait_solver/src/solve/trait_goals.rs`.
1462            && match self.infcx.evaluate_obligation(&PredicateObligation::new(
1463                self.tcx(),
1464                obligation.cause.clone(),
1465                obligation.param_env,
1466                TraitRef::new(
1467                    self.tcx(),
1468                    self.tcx().require_lang_item(LangItem::Sized, DUMMY_SP),
1469                    [base],
1470                ),
1471            )) {
1472                Ok(res) if res.must_apply_modulo_regions() => true,
1473                _ => false,
1474            }
1475            && match self.infcx.evaluate_obligation(&PredicateObligation::new(
1476                self.tcx(),
1477                obligation.cause.clone(),
1478                obligation.param_env,
1479                TraitRef::new(
1480                    self.tcx(),
1481                    self.tcx().require_lang_item(LangItem::Sized, DUMMY_SP),
1482                    [ty],
1483                ),
1484            )) {
1485                Ok(res) if res.must_apply_modulo_regions() => true,
1486                _ => false,
1487            }
1488            && match base.kind() {
1489                ty::Adt(def, _) => def.is_struct() && !def.repr().packed(),
1490                ty::Tuple(..) => true,
1491                _ => false,
1492            }
1493        {
1494            candidates.vec.push(BuiltinCandidate);
1495        }
1496    }
1497}