Skip to main content

rustc_hir_typeck/method/
probe.rs

1use std::cell::{Cell, RefCell};
2use std::cmp::max;
3use std::ops::Deref;
4use std::{assert_matches, debug_assert_matches};
5
6use rustc_attr_ir::find_attr;
7use rustc_attr_ir::lang_items::LangItem;
8use rustc_data_structures::fx::FxHashSet;
9use rustc_data_structures::sso::SsoHashSet;
10use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, Level};
11use rustc_hir::def::DefKind;
12use rustc_hir::{self as hir, ExprKind, HirId, Node};
13use rustc_hir_analysis::autoderef::{self, Autoderef};
14use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
15use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
16use rustc_infer::traits::{ObligationCauseCode, PredicateObligation, query};
17use rustc_lint_defs::builtin::{
18    METHOD_CALL_ON_DIVERGING_INFER_VAR, TYVAR_BEHIND_RAW_POINTER, UNSTABLE_NAME_COLLISIONS,
19};
20use rustc_macros::Diagnostic;
21use rustc_middle::middle::stability;
22use rustc_middle::ty::elaborate::supertrait_def_ids;
23use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, simplify_type};
24use rustc_middle::ty::{
25    self, AssocContainer, AssocItem, GenericArgs, GenericArgsRef, GenericParamDefKind, ParamEnvAnd,
26    Ty, TyCtxt, TypeVisitableExt, Unnormalized, Upcast,
27};
28use rustc_span::def_id::{DefId, LocalDefId};
29use rustc_span::edit_distance::{
30    edit_distance_with_substrings, find_best_match_for_name_with_substrings,
31};
32use rustc_span::{DUMMY_SP, Ident, Span, Symbol, bug, span_bug};
33use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
34use rustc_trait_selection::infer::InferCtxtExt as _;
35use rustc_trait_selection::solve::Goal;
36use rustc_trait_selection::traits::query::CanonicalMethodAutoderefStepsGoal;
37use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
38use rustc_trait_selection::traits::query::method_autoderef::{
39    CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult,
40};
41use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt};
42use smallvec::SmallVec;
43use tracing::{debug, instrument};
44
45use self::CandidateKind::*;
46pub(crate) use self::PickKind::*;
47use super::{CandidateSource, MethodError, NoMatchData, suggest};
48use crate::FnCtxt;
49
50/// Boolean flag used to indicate if this search is for a suggestion
51/// or not. If true, we can allow ambiguity and so forth.
52#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for IsSuggestion { }
#[automatically_derived]
impl ::core::clone::Clone for IsSuggestion {
    #[inline]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<bool>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for IsSuggestion { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for IsSuggestion {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_tuple_field1_finish(f, "IsSuggestion",
            &&self.0)
    }
}Debug)]
53pub(crate) struct IsSuggestion(pub bool);
54
55pub(crate) struct ProbeContext<'a, 'tcx> {
56    fcx: &'a FnCtxt<'a, 'tcx>,
57    span: Span,
58    mode: Mode,
59    method_name: Option<Ident>,
60    return_type: Option<Ty<'tcx>>,
61
62    /// This is the OriginalQueryValues for the steps queries
63    /// that are answered in steps.
64    orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
65    steps: &'tcx [CandidateStep<'tcx>],
66
67    inherent_candidates: Vec<Candidate<'tcx>>,
68    extension_candidates: Vec<Candidate<'tcx>>,
69    impl_dups: FxHashSet<DefId>,
70
71    /// When probing for names, include names that are close to the
72    /// requested name (by edit distance)
73    allow_similar_names: bool,
74
75    /// List of potential private candidates. Will be trimmed to ones that
76    /// actually apply and then the result inserted into `private_candidate`
77    private_candidates: Vec<Candidate<'tcx>>,
78
79    /// Some(candidate) if there is a private candidate
80    private_candidate: Cell<Option<(DefKind, DefId)>>,
81
82    /// Collects near misses when the candidate functions are missing a `self` keyword and is only
83    /// used for error reporting
84    static_candidates: RefCell<Vec<CandidateSource>>,
85
86    scope_expr_id: HirId,
87
88    /// Is this probe being done for a diagnostic? This will skip some error reporting
89    /// machinery, since we don't particularly care about, for example, similarly named
90    /// candidates if we're *reporting* similarly named candidates.
91    is_suggestion: IsSuggestion,
92
93    /// Hack for applying method probing routine for arbitrary types
94    /// in order to get adjustments as if they were at receiver position.
95    /// Used only for delegation's `Self` arguments mapping.
96    /// FIXME(fn_delegation): now this hack is used, however in perfect world
97    /// we would like to separate adjustments finding logic from probe context,
98    /// if we do so we will be able to find wanted adjustments given only two
99    /// types without reusing the whole method probing routine
100    self_ty_override: Option<Ty<'tcx>>,
101}
102
103impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
104    type Target = FnCtxt<'a, 'tcx>;
105    fn deref(&self) -> &Self::Target {
106        self.fcx
107    }
108}
109
110#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for Candidate<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f, "Candidate",
            "item", &self.item, "kind", &self.kind, "import_ids",
            &&self.import_ids)
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for Candidate<'tcx> {
    #[inline]
    fn clone(&self) -> Self {
        Self {
            item: ::core::clone::Clone::clone(&self.item),
            kind: ::core::clone::Clone::clone(&self.kind),
            import_ids: ::core::clone::Clone::clone(&self.import_ids),
        }
    }
}Clone)]
111pub(crate) struct Candidate<'tcx> {
112    pub(crate) item: ty::AssocItem,
113    pub(crate) kind: CandidateKind<'tcx>,
114    pub(crate) import_ids: &'tcx [LocalDefId],
115}
116
117#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for CandidateKind<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::InherentImplCandidate {
                impl_def_id: __self_0, receiver_steps: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "InherentImplCandidate", "impl_def_id", __self_0,
                    "receiver_steps", &__self_1),
            Self::ObjectCandidate(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "ObjectCandidate", &__self_0),
            Self::TraitCandidate {
                trait_ref: __self_0, is_ambiguously_imported: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "TraitCandidate", "trait_ref", __self_0,
                    "is_ambiguously_imported", &__self_1),
            Self::WhereClauseCandidate(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "WhereClauseCandidate", &__self_0),
        }
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for CandidateKind<'tcx> {
    #[inline]
    fn clone(&self) -> Self {
        match self {
            Self::InherentImplCandidate {
                impl_def_id: __self_0, receiver_steps: __self_1 } =>
                Self::InherentImplCandidate {
                    impl_def_id: ::core::clone::Clone::clone(__self_0),
                    receiver_steps: ::core::clone::Clone::clone(__self_1),
                },
            Self::ObjectCandidate(__self_0) =>
                Self::ObjectCandidate(::core::clone::Clone::clone(__self_0)),
            Self::TraitCandidate {
                trait_ref: __self_0, is_ambiguously_imported: __self_1 } =>
                Self::TraitCandidate {
                    trait_ref: ::core::clone::Clone::clone(__self_0),
                    is_ambiguously_imported: ::core::clone::Clone::clone(__self_1),
                },
            Self::WhereClauseCandidate(__self_0) =>
                Self::WhereClauseCandidate(::core::clone::Clone::clone(__self_0)),
        }
    }
}Clone)]
118pub(crate) enum CandidateKind<'tcx> {
119    InherentImplCandidate { impl_def_id: DefId, receiver_steps: usize },
120    ObjectCandidate(ty::PolyTraitRef<'tcx>),
121    TraitCandidate { trait_ref: ty::PolyTraitRef<'tcx>, is_ambiguously_imported: bool },
122    WhereClauseCandidate(ty::PolyTraitRef<'tcx>),
123}
124
125#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ProbeResult {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                ProbeResult::NoMatch => "NoMatch",
                ProbeResult::BadReturnType => "BadReturnType",
                ProbeResult::Match => "Match",
            })
    }
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ProbeResult { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ProbeResult {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
            ::core::intrinsics::discriminant_value(other)
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ProbeResult { }Eq, #[automatically_derived]
impl ::core::marker::Copy for ProbeResult { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ProbeResult { }
#[automatically_derived]
impl ::core::clone::Clone for ProbeResult {
    #[inline]
    fn clone(&self) -> Self { *self }
}Clone)]
126enum ProbeResult {
127    NoMatch,
128    BadReturnType,
129    Match,
130}
131
132/// When adjusting a receiver we often want to do one of
133///
134/// - Add a `&` (or `&mut`), converting the receiver from `T` to `&T` (or `&mut T`)
135/// - If the receiver has type `*mut T`, convert it to `*const T`
136///
137/// This type tells us which one to do.
138///
139/// Note that in principle we could do both at the same time. For example, when the receiver has
140/// type `T`, we could autoref it to `&T`, then convert to `*const T`. Or, when it has type `*mut
141/// T`, we could convert it to `*const T`, then autoref to `&*const T`. However, currently we do
142/// (at most) one of these. Either the receiver has type `T` and we convert it to `&T` (or with
143/// `mut`), or it has type `*mut T` and we convert it to `*const T`.
144#[derive(#[automatically_derived]
impl ::core::fmt::Debug for AutorefOrPtrAdjustment {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::Autoref { mutbl: __self_0, unsize: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "Autoref", "mutbl", __self_0, "unsize", &__self_1),
            Self::ToConstPtr =>
                ::core::fmt::Formatter::write_str(f, "ToConstPtr"),
            Self::ReborrowPin(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "ReborrowPin", &__self_0),
        }
    }
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for AutorefOrPtrAdjustment { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AutorefOrPtrAdjustment {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
                ::core::intrinsics::discriminant_value(other) &&
            match (self, other) {
                (Self::Autoref { mutbl: __self_0, unsize: __self_1 },
                    Self::Autoref { mutbl: __arg1_0, unsize: __arg1_1 }) =>
                    __self_1 == __arg1_1 && __self_0 == __arg1_0,
                (Self::ReborrowPin(__self_0), Self::ReborrowPin(__arg1_0)) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::marker::Copy for AutorefOrPtrAdjustment { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AutorefOrPtrAdjustment { }
#[automatically_derived]
impl ::core::clone::Clone for AutorefOrPtrAdjustment {
    #[inline]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<hir::Mutability>;
        let _: ::core::clone::AssertParamIsClone<bool>;
        let _: ::core::clone::AssertParamIsClone<hir::Mutability>;
        *self
    }
}Clone)]
145pub(crate) enum AutorefOrPtrAdjustment {
146    /// Receiver has type `T`, add `&` or `&mut` (if `T` is `mut`), and maybe also "unsize" it.
147    /// Unsizing is used to convert a `[T; N]` to `[T]`, which only makes sense when autorefing.
148    Autoref {
149        mutbl: hir::Mutability,
150
151        /// Indicates that the source expression should be "unsized" to a target type.
152        /// This is special-cased for just arrays unsizing to slices.
153        unsize: bool,
154    },
155    /// Receiver has type `*mut T`, convert to `*const T`
156    ToConstPtr,
157
158    /// Reborrow a `Pin<&mut T>` or `Pin<&T>`.
159    ReborrowPin(hir::Mutability),
160}
161
162impl AutorefOrPtrAdjustment {
163    fn get_unsize(&self) -> bool {
164        match self {
165            AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => *unsize,
166            AutorefOrPtrAdjustment::ToConstPtr => false,
167            AutorefOrPtrAdjustment::ReborrowPin(_) => false,
168        }
169    }
170}
171
172/// Extra information required only for error reporting.
173#[derive(#[automatically_derived]
impl<'a, 'tcx> ::core::fmt::Debug for PickDiagHints<'a, 'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "PickDiagHints",
            "unstable_candidates", &self.unstable_candidates,
            "unsatisfied_predicates", &&self.unsatisfied_predicates)
    }
}Debug)]
174struct PickDiagHints<'a, 'tcx> {
175    /// Unstable candidates alongside the stable ones.
176    unstable_candidates: Option<Vec<(Candidate<'tcx>, Symbol)>>,
177
178    /// Collects near misses when trait bounds for type parameters are unsatisfied and is only used
179    /// for error reporting
180    unsatisfied_predicates: &'a mut UnsatisfiedPredicates<'tcx>,
181}
182
183pub(crate) type UnsatisfiedPredicates<'tcx> =
184    Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>;
185
186/// Criteria to apply when searching for a given Pick. This is used during
187/// the search for potentially shadowed methods to ensure we don't search
188/// more candidates than strictly necessary.
189#[derive(#[automatically_derived]
impl ::core::fmt::Debug for PickConstraintsForShadowed {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f,
            "PickConstraintsForShadowed", "autoderefs", &self.autoderefs,
            "receiver_steps", &self.receiver_steps, "def_id", &&self.def_id)
    }
}Debug)]
190struct PickConstraintsForShadowed {
191    autoderefs: usize,
192    receiver_steps: Option<usize>,
193    def_id: DefId,
194}
195
196impl PickConstraintsForShadowed {
197    fn may_shadow_based_on_autoderefs(&self, autoderefs: usize) -> bool {
198        autoderefs == self.autoderefs
199    }
200
201    fn candidate_may_shadow(&self, candidate: &Candidate<'_>) -> bool {
202        // An item never shadows itself
203        candidate.item.def_id != self.def_id
204            // and we're only concerned about inherent impls doing the shadowing.
205            // Shadowing can only occur if the impl being shadowed is further along
206            // the Receiver dereferencing chain than the impl doing the shadowing.
207            && match candidate.kind {
208                CandidateKind::InherentImplCandidate { receiver_steps, .. } => match self.receiver_steps {
209                    Some(shadowed_receiver_steps) => receiver_steps > shadowed_receiver_steps,
210                    _ => false
211                },
212                _ => false
213            }
214    }
215}
216
217#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for Pick<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        let names: &'static _ =
            &["item", "kind", "import_ids", "autoderefs",
                        "autoref_or_ptr_adjustment", "self_ty",
                        "unstable_candidates", "receiver_steps",
                        "shadowed_candidates"];
        let values: &[&dyn ::core::fmt::Debug] =
            &[&self.item, &self.kind, &self.import_ids, &self.autoderefs,
                        &self.autoref_or_ptr_adjustment, &self.self_ty,
                        &self.unstable_candidates, &self.receiver_steps,
                        &&self.shadowed_candidates];
        ::core::fmt::Formatter::debug_struct_fields_finish(f, "Pick", names,
            values)
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for Pick<'tcx> {
    #[inline]
    fn clone(&self) -> Self {
        Self {
            item: ::core::clone::Clone::clone(&self.item),
            kind: ::core::clone::Clone::clone(&self.kind),
            import_ids: ::core::clone::Clone::clone(&self.import_ids),
            autoderefs: ::core::clone::Clone::clone(&self.autoderefs),
            autoref_or_ptr_adjustment: ::core::clone::Clone::clone(&self.autoref_or_ptr_adjustment),
            self_ty: ::core::clone::Clone::clone(&self.self_ty),
            unstable_candidates: ::core::clone::Clone::clone(&self.unstable_candidates),
            receiver_steps: ::core::clone::Clone::clone(&self.receiver_steps),
            shadowed_candidates: ::core::clone::Clone::clone(&self.shadowed_candidates),
        }
    }
}Clone)]
218pub(crate) struct Pick<'tcx> {
219    pub item: ty::AssocItem,
220    pub kind: PickKind<'tcx>,
221    pub import_ids: &'tcx [LocalDefId],
222
223    /// Indicates that the source expression should be autoderef'd N times
224    /// ```ignore (not-rust)
225    /// A = expr | *expr | **expr | ...
226    /// ```
227    pub autoderefs: usize,
228
229    /// Indicates that we want to add an autoref (and maybe also unsize it), or if the receiver is
230    /// `*mut T`, convert it to `*const T`.
231    pub autoref_or_ptr_adjustment: Option<AutorefOrPtrAdjustment>,
232    pub self_ty: Ty<'tcx>,
233
234    /// Unstable candidates alongside the stable ones.
235    unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
236
237    /// Number of jumps along the `Receiver::Target` chain we followed
238    /// to identify this method. Used only for deshadowing errors.
239    /// Only applies for inherent impls.
240    pub receiver_steps: Option<usize>,
241
242    /// Candidates that were shadowed by subtraits.
243    pub shadowed_candidates: Vec<ty::AssocItem>,
244}
245
246#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for PickKind<'tcx> {
    #[inline]
    fn clone(&self) -> Self {
        match self {
            Self::InherentImplPick => Self::InherentImplPick,
            Self::ObjectPick => Self::ObjectPick,
            Self::TraitPick { is_ambiguously_imported: __self_0 } =>
                Self::TraitPick {
                    is_ambiguously_imported: ::core::clone::Clone::clone(__self_0),
                },
            Self::WhereClausePick(__self_0) =>
                Self::WhereClausePick(::core::clone::Clone::clone(__self_0)),
        }
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for PickKind<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::InherentImplPick =>
                ::core::fmt::Formatter::write_str(f, "InherentImplPick"),
            Self::ObjectPick =>
                ::core::fmt::Formatter::write_str(f, "ObjectPick"),
            Self::TraitPick { is_ambiguously_imported: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "TraitPick", "is_ambiguously_imported", &__self_0),
            Self::WhereClausePick(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "WhereClausePick", &__self_0),
        }
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for PickKind<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for PickKind<'tcx> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
                ::core::intrinsics::discriminant_value(other) &&
            match (self, other) {
                (Self::TraitPick { is_ambiguously_imported: __self_0 },
                    Self::TraitPick { is_ambiguously_imported: __arg1_0 }) =>
                    __self_0 == __arg1_0,
                (Self::WhereClausePick(__self_0),
                    Self::WhereClausePick(__arg1_0)) => __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for PickKind<'tcx> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<bool>;
        let _: ::core::cmp::AssertParamIsEq<ty::PolyTraitRef<'tcx>>;
    }
}Eq)]
247pub(crate) enum PickKind<'tcx> {
248    InherentImplPick,
249    ObjectPick,
250    TraitPick {
251        is_ambiguously_imported: bool,
252    },
253    WhereClausePick(
254        // Trait
255        ty::PolyTraitRef<'tcx>,
256    ),
257}
258
259pub(crate) type PickResult<'tcx> = Result<Pick<'tcx>, MethodError<'tcx>>;
260
261#[derive(#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Mode { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Mode {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
            ::core::intrinsics::discriminant_value(other)
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Mode { }Eq, #[automatically_derived]
impl ::core::marker::Copy for Mode { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Mode { }
#[automatically_derived]
impl ::core::clone::Clone for Mode {
    #[inline]
    fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Mode {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                Mode::MethodCall => "MethodCall",
                Mode::Path => "Path",
            })
    }
}Debug)]
262pub(crate) enum Mode {
263    // An expression of the form `receiver.method_name(...)`.
264    // Autoderefs are performed on `receiver`, lookup is done based on the
265    // `self` argument of the method, and static methods aren't considered.
266    MethodCall,
267    // An expression of the form `Type::item` or `<T>::item`.
268    // No autoderefs are performed, lookup is done based on the type each
269    // implementation is for, and static methods are included.
270    Path,
271}
272
273#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for ProbeScope<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for ProbeScope<'tcx> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
                ::core::intrinsics::discriminant_value(other) &&
            match (self, other) {
                (Self::Single(__self_0, __self_1),
                    Self::Single(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for ProbeScope<'tcx> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<DefId>;
        let _: ::core::cmp::AssertParamIsEq<Option<Ty<'tcx>>>;
    }
}Eq, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ProbeScope<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::Single(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f, "Single",
                    __self_0, &__self_1),
            Self::TraitsInScope =>
                ::core::fmt::Formatter::write_str(f, "TraitsInScope"),
            Self::AllTraits =>
                ::core::fmt::Formatter::write_str(f, "AllTraits"),
        }
    }
}Debug)]
274pub(crate) enum ProbeScope<'tcx> {
275    // Single candidate coming from pre-resolved delegation method.
276    Single(DefId, Option<Ty<'tcx>> /* self_ty override */),
277
278    // Assemble candidates coming only from traits in scope.
279    TraitsInScope,
280
281    // Assemble candidates coming from all traits.
282    AllTraits,
283}
284
285impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
286    /// This is used to offer suggestions to users. It returns methods
287    /// that could have been called which have the desired return
288    /// type. Some effort is made to rule out methods that, if called,
289    /// would result in an error (basically, the same criteria we
290    /// would use to decide if a method is a plausible fit for
291    /// ambiguity purposes).
292    {}
#[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("probe_for_return_type_for_diagnostic",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(292u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("span")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("span");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("mode")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("mode");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("return_type")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("return_type");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self_ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("scope_expr_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("scope_expr_id");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mode)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&return_type)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope_expr_id)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: Vec<ty::AssocItem> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let method_names =
                self.probe_op(span, mode, None, Some(return_type),
                        IsSuggestion(true), self_ty, scope_expr_id,
                        ProbeScope::AllTraits,
                        |probe_cx|
                            Ok(probe_cx.candidate_method_names(candidate_filter))).unwrap_or_default();
            method_names.iter().flat_map(|&method_name|
                        {
                            self.probe_op(span, mode, Some(method_name),
                                        Some(return_type), IsSuggestion(true), self_ty,
                                        scope_expr_id, ProbeScope::AllTraits,
                                        |probe_cx| probe_cx.pick()).ok().map(|pick| pick.item)
                        }).collect()
        }
    }
}#[instrument(level = "debug", skip(self, candidate_filter))]
293    pub(crate) fn probe_for_return_type_for_diagnostic(
294        &self,
295        span: Span,
296        mode: Mode,
297        return_type: Ty<'tcx>,
298        self_ty: Ty<'tcx>,
299        scope_expr_id: HirId,
300        candidate_filter: impl Fn(&ty::AssocItem) -> bool,
301    ) -> Vec<ty::AssocItem> {
302        let method_names = self
303            .probe_op(
304                span,
305                mode,
306                None,
307                Some(return_type),
308                IsSuggestion(true),
309                self_ty,
310                scope_expr_id,
311                ProbeScope::AllTraits,
312                |probe_cx| Ok(probe_cx.candidate_method_names(candidate_filter)),
313            )
314            .unwrap_or_default();
315        method_names
316            .iter()
317            .flat_map(|&method_name| {
318                self.probe_op(
319                    span,
320                    mode,
321                    Some(method_name),
322                    Some(return_type),
323                    IsSuggestion(true),
324                    self_ty,
325                    scope_expr_id,
326                    ProbeScope::AllTraits,
327                    |probe_cx| probe_cx.pick(),
328                )
329                .ok()
330                .map(|pick| pick.item)
331            })
332            .collect()
333    }
334
335    {}
#[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("probe_for_name",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(335u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("mode")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("mode");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("item_name")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("item_name");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("return_type")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("return_type");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("is_suggestion")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("is_suggestion");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self_ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("scope_expr_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("scope_expr_id");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("scope")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("scope");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mode)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_name)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&return_type)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&is_suggestion)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope_expr_id)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: PickResult<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            self.probe_op(item_name.span, mode, Some(item_name), return_type,
                is_suggestion, self_ty, scope_expr_id, scope,
                |probe_cx| probe_cx.pick())
        }
    }
}#[instrument(level = "debug", skip(self))]
336    pub(crate) fn probe_for_name(
337        &self,
338        mode: Mode,
339        item_name: Ident,
340        return_type: Option<Ty<'tcx>>,
341        is_suggestion: IsSuggestion,
342        self_ty: Ty<'tcx>,
343        scope_expr_id: HirId,
344        scope: ProbeScope<'tcx>,
345    ) -> PickResult<'tcx> {
346        self.probe_op(
347            item_name.span,
348            mode,
349            Some(item_name),
350            return_type,
351            is_suggestion,
352            self_ty,
353            scope_expr_id,
354            scope,
355            |probe_cx| probe_cx.pick(),
356        )
357    }
358
359    {}
#[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("probe_for_name_many",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(359u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("mode")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("mode");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("item_name")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("item_name");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("return_type")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("return_type");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("is_suggestion")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("is_suggestion");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self_ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("scope_expr_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("scope_expr_id");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("scope")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("scope");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mode)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_name)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&return_type)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&is_suggestion)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope_expr_id)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return:
                    Result<Vec<Candidate<'tcx>>, MethodError<'tcx>> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            self.probe_op(item_name.span, mode, Some(item_name), return_type,
                is_suggestion, self_ty, scope_expr_id, scope,
                |probe_cx|
                    {
                        Ok(probe_cx.inherent_candidates.into_iter().chain(probe_cx.extension_candidates).collect())
                    })
        }
    }
}#[instrument(level = "debug", skip(self))]
360    pub(crate) fn probe_for_name_many(
361        &self,
362        mode: Mode,
363        item_name: Ident,
364        return_type: Option<Ty<'tcx>>,
365        is_suggestion: IsSuggestion,
366        self_ty: Ty<'tcx>,
367        scope_expr_id: HirId,
368        scope: ProbeScope<'tcx>,
369    ) -> Result<Vec<Candidate<'tcx>>, MethodError<'tcx>> {
370        self.probe_op(
371            item_name.span,
372            mode,
373            Some(item_name),
374            return_type,
375            is_suggestion,
376            self_ty,
377            scope_expr_id,
378            scope,
379            |probe_cx| {
380                Ok(probe_cx
381                    .inherent_candidates
382                    .into_iter()
383                    .chain(probe_cx.extension_candidates)
384                    .collect())
385            },
386        )
387    }
388
389    pub(crate) fn probe_op<OP, R>(
390        &'a self,
391        span: Span,
392        mode: Mode,
393        method_name: Option<Ident>,
394        return_type: Option<Ty<'tcx>>,
395        is_suggestion: IsSuggestion,
396        self_ty: Ty<'tcx>,
397        scope_expr_id: HirId,
398        scope: ProbeScope<'tcx>,
399        op: OP,
400    ) -> Result<R, MethodError<'tcx>>
401    where
402        OP: FnOnce(ProbeContext<'_, 'tcx>) -> Result<R, MethodError<'tcx>>,
403    {
404        #[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for MissingTypeAnnot {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    MissingTypeAnnot => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type annotations needed")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
405        #[diag("type annotations needed")]
406        struct MissingTypeAnnot;
407
408        #[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            MethodCallOnDivergingInferenceVariable {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    MethodCallOnDivergingInferenceVariable => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("method call on a diverging inference variable")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider providing a type annotation")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
409        #[diag("method call on a diverging inference variable")]
410        #[help("consider providing a type annotation")]
411        struct MethodCallOnDivergingInferenceVariable;
412
413        let mut orig_values = OriginalQueryValues::default();
414        let predefined_opaques_in_body = if self.next_trait_solver() {
415            self.tcx.mk_predefined_opaques_in_body_from_iter(
416                self.inner.borrow_mut().opaque_types().iter_opaque_types().map(|(k, v)| (k, v.ty)),
417            )
418        } else {
419            ty::List::empty()
420        };
421        let value = query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty };
422        let query_input = self
423            .canonicalize_query(ParamEnvAnd { param_env: self.param_env, value }, &mut orig_values);
424
425        let steps = match mode {
426            Mode::MethodCall => self.tcx.method_autoderef_steps(query_input),
427            Mode::Path => self.probe(|_| {
428                // Mode::Path - the deref steps is "trivial". This turns
429                // our CanonicalQuery into a "trivial" QueryResponse. This
430                // is a bit inefficient, but I don't think that writing
431                // special handling for this "trivial case" is a good idea.
432
433                let infcx = &self.infcx;
434                let (ParamEnvAnd { param_env: _, value }, var_values) =
435                    infcx.instantiate_canonical(span, &query_input.canonical);
436                let query::MethodAutoderefSteps { predefined_opaques_in_body: _, self_ty } = value;
437                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:437",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(437u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("self_ty")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("self_ty");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("query_input")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("query_input");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("probe_op: Mode::Path")
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&query_input)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?self_ty, ?query_input, "probe_op: Mode::Path");
438                let prev_opaque_entries = self.inner.borrow_mut().opaque_types().num_entries();
439                MethodAutoderefStepsResult {
440                    steps: infcx.tcx.arena.alloc_from_iter([CandidateStep {
441                        self_ty: self.make_query_response_ignoring_pending_obligations(
442                            var_values,
443                            self_ty,
444                            prev_opaque_entries,
445                        ),
446                        self_ty_is_opaque: false,
447                        autoderefs: 0,
448                        from_unsafe_deref: false,
449                        unsize: false,
450                        reachable_via_deref: true,
451                    }]),
452                    opt_bad_ty: None,
453                    reached_recursion_limit: false,
454                }
455            }),
456        };
457
458        // If our autoderef loop had reached the recursion limit,
459        // report an overflow error, but continue going on with
460        // the truncated autoderef list.
461        if steps.reached_recursion_limit && !is_suggestion.0 {
462            self.probe(|_| {
463                let ty = &steps
464                    .steps
465                    .last()
466                    .unwrap_or_else(|| ::rustc_span::macros::bug_impl(Some(span),
    format_args!("reached the recursion limit in 0 steps?"),
    Location::caller())span_bug!(span, "reached the recursion limit in 0 steps?"))
467                    .self_ty;
468                let ty = self
469                    .probe_instantiate_query_response(span, &orig_values, ty)
470                    .unwrap_or_else(|_| ::rustc_span::macros::bug_impl(Some(span),
    format_args!("instantiating {0:?} failed?", ty), Location::caller())span_bug!(span, "instantiating {:?} failed?", ty));
471                autoderef::report_autoderef_recursion_limit_error(self.tcx, span, ty.value);
472            });
473        }
474
475        // If we encountered an `_` type or an error type during autoderef, this is
476        // ambiguous.
477        if let Some(bad_ty) = &steps.opt_bad_ty {
478            // We care about the opt_bad_ty given the inference state at the point of computing the auto deref chain,
479            // so we don't call structurally_resolve_type as it processes obligations in our local FnCtxt,
480            // potentially making inference progress.
481            let ty = &bad_ty.ty;
482            let ty = self
483                .probe_instantiate_query_response(span, &orig_values, ty)
484                .unwrap_or_else(|_| ::rustc_span::macros::bug_impl(Some(span),
    format_args!("instantiating {0:?} failed?", ty), Location::caller())span_bug!(span, "instantiating {:?} failed?", ty));
485            let ty = ty.value;
486
487            if is_suggestion.0 {
488                // Ambiguity was encountered during a suggestion. There's really
489                // not much use in suggesting methods in this case.
490                return Err(MethodError::NoMatch(NoMatchData {
491                    static_candidates: Vec::new(),
492                    unsatisfied_predicates: Vec::new(),
493                    out_of_scope_traits: Vec::new(),
494                    similar_candidate: None,
495                    mode,
496                }));
497            } else if bad_ty.reached_raw_pointer
498                && !self.tcx.features().arbitrary_self_types_pointers()
499                && !self.tcx.sess.at_least_rust_2018()
500            {
501                // this case used to be allowed by the compiler,
502                // so we do a future-compat lint here for the 2015 edition
503                // (see https://github.com/rust-lang/rust/issues/46906)
504                self.tcx.emit_node_span_lint(
505                    TYVAR_BEHIND_RAW_POINTER,
506                    scope_expr_id,
507                    span,
508                    MissingTypeAnnot,
509                );
510            // If `ty` is an inference variable that was created by being adjusted from the never type,
511            // We demand the type to be equal to the never type, so we can probe the never type for methods
512            // (see https://github.com/rust-lang/rust/issues/143349)
513            } else if let ty::Infer(ty::TyVar(ty_id)) = *ty.kind()
514                && let ty_id = self.sub_unification_table_root_var(ty_id)
515                && self
516                    .diverging_type_vars
517                    .borrow()
518                    .iter()
519                    .any(|&candidate_id| self.sub_unification_table_root_var(candidate_id) == ty_id)
520            {
521                self.tcx.emit_node_span_lint(
522                    METHOD_CALL_ON_DIVERGING_INFER_VAR,
523                    scope_expr_id,
524                    span,
525                    MethodCallOnDivergingInferenceVariable,
526                );
527                self.demand_eqtype(span, ty, self.tcx.types.never);
528            } else {
529                let guar = match *ty.kind() {
530                    _ if let Some(guar) = self.tainted_by_errors() => guar,
531                    ty::Infer(ty::TyVar(_)) => {
532                        // We want to get the variable name that the method
533                        // is being called on. If it is a method call.
534                        let err_span = match (mode, self.tcx.hir_node(scope_expr_id)) {
535                            (
536                                Mode::MethodCall,
537                                Node::Expr(hir::Expr {
538                                    kind: ExprKind::MethodCall(_, recv, ..),
539                                    ..
540                                }),
541                            ) => recv.span,
542                            _ => span,
543                        };
544
545                        let raw_ptr_call = bad_ty.reached_raw_pointer
546                            && !self.tcx.features().arbitrary_self_types();
547
548                        let mut err = self.err_ctxt().emit_inference_failure_err(
549                            self.body_def_id,
550                            err_span,
551                            ty.into(),
552                            TypeAnnotationNeeded::E0282,
553                            !raw_ptr_call,
554                        );
555                        if raw_ptr_call {
556                            err.span_label(span, "cannot call a method on a raw pointer with an unknown pointee type");
557                        }
558                        err.emit_err()
559                    }
560                    ty::Error(guar) => guar,
561                    _ => ::rustc_span::macros::bug_impl(None,
    format_args!("unexpected bad final type in method autoderef"),
    Location::caller())bug!("unexpected bad final type in method autoderef"),
562                };
563                self.demand_eqtype(span, ty, Ty::new_error(self.tcx, guar));
564                return Err(MethodError::ErrorReported(guar));
565            }
566        }
567
568        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:568",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(568u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("ProbeContext: steps for self_ty={0:?} are {1:?}",
                                                    self_ty, steps) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("ProbeContext: steps for self_ty={:?} are {:?}", self_ty, steps);
569
570        // this creates one big transaction so that all type variables etc
571        // that we create during the probe process are removed later
572        self.probe(|_| {
573            let mut probe_cx = ProbeContext::new(
574                self,
575                span,
576                mode,
577                method_name,
578                return_type,
579                &orig_values,
580                steps.steps,
581                scope_expr_id,
582                is_suggestion,
583            );
584
585            match scope {
586                ProbeScope::TraitsInScope => {
587                    probe_cx.assemble_inherent_candidates();
588                    probe_cx.assemble_extension_candidates_for_traits_in_scope();
589                }
590                ProbeScope::AllTraits => {
591                    probe_cx.assemble_inherent_candidates();
592                    probe_cx.assemble_extension_candidates_for_all_traits();
593                }
594                ProbeScope::Single(def_id, self_ty_override) => {
595                    let item = self.tcx.associated_item(def_id);
596                    {
    match item.container {
        AssocContainer::Trait | AssocContainer::InherentImpl => {}
        ref left_val => {
            ::core::panicking::assert_matches_failed(left_val,
                "AssocContainer::Trait | AssocContainer::InherentImpl",
                ::core::option::Option::None);
        }
    }
};assert_matches!(
597                        item.container,
598                        AssocContainer::Trait | AssocContainer::InherentImpl
599                    );
600
601                    let trait_def_id = self.tcx.parent(def_id);
602                    let trait_span = self.tcx.def_span(trait_def_id);
603
604                    let trait_args = self.fresh_args_for_item(trait_span, trait_def_id);
605                    let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
606
607                    probe_cx.self_ty_override = self_ty_override;
608                    probe_cx.push_candidate(
609                        Candidate {
610                            item,
611                            kind: match item.container {
612                                AssocContainer::Trait => CandidateKind::TraitCandidate {
613                                    trait_ref: ty::Binder::dummy(trait_ref),
614                                    is_ambiguously_imported: false,
615                                },
616                                AssocContainer::InherentImpl => {
617                                    CandidateKind::InherentImplCandidate {
618                                        impl_def_id: self.tcx.parent(def_id),
619                                        receiver_steps: 0,
620                                    }
621                                }
622                                _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
623                            },
624                            import_ids: &[],
625                        },
626                        false,
627                    );
628                }
629            };
630            op(probe_cx)
631        })
632    }
633}
634
635pub(crate) fn method_autoderef_steps<'tcx>(
636    tcx: TyCtxt<'tcx>,
637    goal: CanonicalMethodAutoderefStepsGoal<'tcx>,
638) -> MethodAutoderefStepsResult<'tcx> {
639    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:639",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(639u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("method_autoderef_steps({0:?})",
                                                    goal) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("method_autoderef_steps({:?})", goal);
640
641    let (ref infcx, goal, inference_vars) = tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &goal);
642    let ParamEnvAnd {
643        param_env,
644        value: query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty },
645    } = goal;
646    for (key, ty) in predefined_opaques_in_body {
647        let prev = infcx
648            .register_hidden_type_in_storage(key, ty::ProvisionalHiddenType { span: DUMMY_SP, ty });
649        // It may be possible that two entries in the opaque type storage end up
650        // with the same key after resolving contained inference variables.
651        //
652        // We could put them in the duplicate list but don't have to. The opaques we
653        // encounter here are already tracked in the caller, so there's no need to
654        // also store them here. We'd take them out when computing the query response
655        // and then discard them, as they're already present in the input.
656        //
657        // Ideally we'd drop duplicate opaque type definitions when computing
658        // the canonical input. This is more annoying to implement and may cause a
659        // perf regression, so we do it inside of the query for now.
660        if let Some(prev) = prev {
661            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:661",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(661u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message",
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("key")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("key");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("ty")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("ty");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("prev")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("prev");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("ignore duplicate in `opaque_types_storage`")
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&key)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&prev)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?key, ?ty, ?prev, "ignore duplicate in `opaque_types_storage`");
662        }
663    }
664    let prev_opaque_entries = infcx.inner.borrow_mut().opaque_types().num_entries();
665
666    // We accept not-yet-defined opaque types in the autoderef
667    // chain to support recursive calls. We do error if the final
668    // infer var is not an opaque.
669    let self_ty_is_opaque = |ty: Ty<'_>| {
670        if let &ty::Infer(ty::TyVar(vid)) = ty.kind() {
671            infcx.has_opaques_with_sub_unified_hidden_type(vid)
672        } else {
673            false
674        }
675    };
676
677    // If arbitrary self types is not enabled, we follow the chain of
678    // `Deref<Target=T>`. If arbitrary self types is enabled, we instead
679    // follow the chain of `Receiver<Target=T>`, but we also record whether
680    // such types are reachable by following the (potentially shorter)
681    // chain of `Deref<Target=T>`. We will use the first list when finding
682    // potentially relevant function implementations (e.g. relevant impl blocks)
683    // but the second list when determining types that the receiver may be
684    // converted to, in order to find out which of those methods might actually
685    // be callable.
686    let mut autoderef_via_deref =
687        Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
688            .include_raw_pointers()
689            .silence_errors();
690
691    let mut reached_raw_pointer = false;
692    let arbitrary_self_types_enabled =
693        tcx.features().arbitrary_self_types() || tcx.features().arbitrary_self_types_pointers();
694    let (mut steps, reached_recursion_limit): (Vec<_>, bool) = if arbitrary_self_types_enabled {
695        let reachable_via_deref =
696            autoderef_via_deref.by_ref().map(|_| true).chain(std::iter::repeat(false));
697
698        let mut autoderef_via_receiver =
699            Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
700                .include_raw_pointers()
701                .use_receiver_trait()
702                .silence_errors();
703        let steps = autoderef_via_receiver
704            .by_ref()
705            .zip(reachable_via_deref)
706            .map(|((ty, d), reachable_via_deref)| {
707                let step = CandidateStep {
708                    self_ty: infcx.make_query_response_ignoring_pending_obligations(
709                        inference_vars,
710                        ty,
711                        prev_opaque_entries,
712                    ),
713                    self_ty_is_opaque: self_ty_is_opaque(ty),
714                    autoderefs: d,
715                    from_unsafe_deref: reached_raw_pointer,
716                    unsize: false,
717                    reachable_via_deref,
718                };
719                if ty.is_raw_ptr() {
720                    // all the subsequent steps will be from_unsafe_deref
721                    reached_raw_pointer = true;
722                }
723                step
724            })
725            .collect();
726        (steps, autoderef_via_receiver.reached_recursion_limit())
727    } else {
728        let steps = autoderef_via_deref
729            .by_ref()
730            .map(|(ty, d)| {
731                let step = CandidateStep {
732                    self_ty: infcx.make_query_response_ignoring_pending_obligations(
733                        inference_vars,
734                        ty,
735                        prev_opaque_entries,
736                    ),
737                    self_ty_is_opaque: self_ty_is_opaque(ty),
738                    autoderefs: d,
739                    from_unsafe_deref: reached_raw_pointer,
740                    unsize: false,
741                    reachable_via_deref: true,
742                };
743                if ty.is_raw_ptr() {
744                    // all the subsequent steps will be from_unsafe_deref
745                    reached_raw_pointer = true;
746                }
747                step
748            })
749            .collect();
750        (steps, autoderef_via_deref.reached_recursion_limit())
751    };
752    let final_ty = autoderef_via_deref.final_ty();
753    let opt_bad_ty = match final_ty.kind() {
754        ty::Infer(ty::TyVar(_)) if !self_ty_is_opaque(final_ty) => Some(MethodAutoderefBadTy {
755            reached_raw_pointer,
756            ty: infcx.make_query_response_ignoring_pending_obligations(
757                inference_vars,
758                final_ty,
759                prev_opaque_entries,
760            ),
761        }),
762        ty::Error(_) => Some(MethodAutoderefBadTy {
763            reached_raw_pointer,
764            ty: infcx.make_query_response_ignoring_pending_obligations(
765                inference_vars,
766                final_ty,
767                prev_opaque_entries,
768            ),
769        }),
770        ty::Array(elem_ty, _) => {
771            let autoderefs = steps.iter().filter(|s| s.reachable_via_deref).count() - 1;
772            steps.push(CandidateStep {
773                self_ty: infcx.make_query_response_ignoring_pending_obligations(
774                    inference_vars,
775                    Ty::new_slice(infcx.tcx, *elem_ty),
776                    prev_opaque_entries,
777                ),
778                self_ty_is_opaque: false,
779                autoderefs,
780                // this could be from an unsafe deref if we had
781                // a *mut/const [T; N]
782                from_unsafe_deref: reached_raw_pointer,
783                unsize: true,
784                reachable_via_deref: true, // this is always the final type from
785                                           // autoderef_via_deref
786            });
787
788            None
789        }
790        _ => None,
791    };
792
793    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:793",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(793u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("method_autoderef_steps: steps={0:?} opt_bad_ty={1:?}",
                                                    steps, opt_bad_ty) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("method_autoderef_steps: steps={:?} opt_bad_ty={:?}", steps, opt_bad_ty);
794    // Need to empty the opaque types storage before it gets dropped.
795    let _ = infcx.take_opaque_types();
796    MethodAutoderefStepsResult {
797        steps: tcx.arena.alloc_from_iter(steps),
798        opt_bad_ty: opt_bad_ty.map(|ty| &*tcx.arena.alloc(ty)),
799        reached_recursion_limit,
800    }
801}
802
803impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
804    fn new(
805        fcx: &'a FnCtxt<'a, 'tcx>,
806        span: Span,
807        mode: Mode,
808        method_name: Option<Ident>,
809        return_type: Option<Ty<'tcx>>,
810        orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
811        steps: &'tcx [CandidateStep<'tcx>],
812        scope_expr_id: HirId,
813        is_suggestion: IsSuggestion,
814    ) -> ProbeContext<'a, 'tcx> {
815        ProbeContext {
816            fcx,
817            span,
818            mode,
819            method_name,
820            return_type,
821            inherent_candidates: Vec::new(),
822            extension_candidates: Vec::new(),
823            impl_dups: FxHashSet::default(),
824            orig_steps_var_values,
825            steps,
826            allow_similar_names: false,
827            private_candidates: Vec::new(),
828            private_candidate: Cell::new(None),
829            static_candidates: RefCell::new(Vec::new()),
830            scope_expr_id,
831            is_suggestion,
832            self_ty_override: None,
833        }
834    }
835
836    fn reset(&mut self) {
837        self.inherent_candidates.clear();
838        self.extension_candidates.clear();
839        self.impl_dups.clear();
840        self.private_candidates.clear();
841        self.private_candidate.set(None);
842        self.static_candidates.borrow_mut().clear();
843    }
844
845    /// When we're looking up a method by path (UFCS), we relate the receiver
846    /// types invariantly. When we are looking up a method by the `.` operator,
847    /// we relate them covariantly.
848    fn variance(&self) -> ty::Variance {
849        match self.mode {
850            Mode::MethodCall => ty::Covariant,
851            Mode::Path => ty::Invariant,
852        }
853    }
854
855    ///////////////////////////////////////////////////////////////////////////
856    // CANDIDATE ASSEMBLY
857
858    fn push_candidate(&mut self, candidate: Candidate<'tcx>, is_inherent: bool) {
859        let is_accessible = if let Some(name) = self.method_name {
860            let item = candidate.item;
861            let container_id = item.container_id(self.tcx);
862            let def_scope = self.tcx.adjust_ident_and_get_scope(name, container_id, self.mod_id).1;
863            item.visibility(self.tcx).is_accessible_from(def_scope, self.tcx)
864        } else {
865            true
866        };
867        if is_accessible {
868            if is_inherent {
869                self.inherent_candidates.push(candidate);
870            } else {
871                self.extension_candidates.push(candidate);
872            }
873        } else {
874            self.private_candidates.push(candidate);
875        }
876    }
877
878    fn assemble_inherent_candidates(&mut self) {
879        for step in self.steps.iter() {
880            self.assemble_probe(&step.self_ty, step.autoderefs);
881        }
882    }
883
884    {}
#[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_probe",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(884u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self_ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("receiver_steps")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("receiver_steps");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&receiver_steps as
                                                            &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let raw_self_ty = self_ty.value.value;
            match *raw_self_ty.kind() {
                ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
                    let (QueryResponse { value: generalized_self_ty, .. },
                            _ignored_var_values) =
                        self.fcx.instantiate_canonical(self.span, self_ty);
                    self.assemble_inherent_candidates_from_object(generalized_self_ty);
                    self.assemble_inherent_impl_candidates_for_type(p.def_id(),
                        receiver_steps);
                    self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty,
                        receiver_steps);
                }
                ty::Adt(def, _) => {
                    let def_id = def.did();
                    self.assemble_inherent_impl_candidates_for_type(def_id,
                        receiver_steps);
                    self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty,
                        receiver_steps);
                }
                ty::Foreign(did) => {
                    self.assemble_inherent_impl_candidates_for_type(did,
                        receiver_steps);
                    self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty,
                        receiver_steps);
                }
                ty::Param(_) => {
                    self.assemble_inherent_candidates_from_param(raw_self_ty);
                }
                ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_)
                    | ty::Str | ty::Array(..) | ty::Slice(_) | ty::RawPtr(_, _)
                    | ty::Ref(..) | ty::Never | ty::Tuple(..) => {
                    self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty,
                        receiver_steps)
                }
                ty::Alias(..) | ty::Bound(..) | ty::Closure(..) |
                    ty::Coroutine(..) | ty::CoroutineClosure(..) |
                    ty::CoroutineWitness(..) | ty::Dynamic(..) | ty::Error(..) |
                    ty::FnDef(..) | ty::FnPtr(..) | ty::Infer(..) | ty::Pat(..)
                    | ty::Placeholder(..) | ty::UnsafeBinder(..) => {}
            }
        }
    }
}#[instrument(level = "debug", skip(self))]
885    fn assemble_probe(
886        &mut self,
887        self_ty: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
888        receiver_steps: usize,
889    ) {
890        let raw_self_ty = self_ty.value.value;
891        match *raw_self_ty.kind() {
892            ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
893                // Subtle: we can't use `instantiate_query_response` here: using it will
894                // commit to all of the type equalities assumed by inference going through
895                // autoderef (see the `method-probe-no-guessing` test).
896                //
897                // However, in this code, it is OK if we end up with an object type that is
898                // "more general" than the object type that we are evaluating. For *every*
899                // object type `MY_OBJECT`, a function call that goes through a trait-ref
900                // of the form `<MY_OBJECT as SuperTraitOf(MY_OBJECT)>::func` is a valid
901                // `ObjectCandidate`, and it should be discoverable "exactly" through one
902                // of the iterations in the autoderef loop, so there is no problem with it
903                // being discoverable in another one of these iterations.
904                //
905                // Using `instantiate_canonical` on our
906                // `Canonical<QueryResponse<Ty<'tcx>>>` and then *throwing away* the
907                // `CanonicalVarValues` will exactly give us such a generalization - it
908                // will still match the original object type, but it won't pollute our
909                // type variables in any form, so just do that!
910                let (QueryResponse { value: generalized_self_ty, .. }, _ignored_var_values) =
911                    self.fcx.instantiate_canonical(self.span, self_ty);
912
913                self.assemble_inherent_candidates_from_object(generalized_self_ty);
914                self.assemble_inherent_impl_candidates_for_type(p.def_id(), receiver_steps);
915                self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
916            }
917            ty::Adt(def, _) => {
918                let def_id = def.did();
919                self.assemble_inherent_impl_candidates_for_type(def_id, receiver_steps);
920                self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
921            }
922            ty::Foreign(did) => {
923                self.assemble_inherent_impl_candidates_for_type(did, receiver_steps);
924                self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
925            }
926            ty::Param(_) => {
927                self.assemble_inherent_candidates_from_param(raw_self_ty);
928            }
929            ty::Bool
930            | ty::Char
931            | ty::Int(_)
932            | ty::Uint(_)
933            | ty::Float(_)
934            | ty::Str
935            | ty::Array(..)
936            | ty::Slice(_)
937            | ty::RawPtr(_, _)
938            | ty::Ref(..)
939            | ty::Never
940            | ty::Tuple(..) => {
941                self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps)
942            }
943            ty::Alias(..)
944            | ty::Bound(..)
945            | ty::Closure(..)
946            | ty::Coroutine(..)
947            | ty::CoroutineClosure(..)
948            | ty::CoroutineWitness(..)
949            | ty::Dynamic(..)
950            | ty::Error(..)
951            | ty::FnDef(..)
952            | ty::FnPtr(..)
953            | ty::Infer(..)
954            | ty::Pat(..)
955            | ty::Placeholder(..)
956            | ty::UnsafeBinder(..) => {}
957        }
958    }
959
960    fn assemble_inherent_candidates_for_incoherent_ty(
961        &mut self,
962        self_ty: Ty<'tcx>,
963        receiver_steps: usize,
964    ) {
965        let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::InstantiateWithInfer) else {
966            ::rustc_span::macros::bug_impl(None,
    format_args!("unexpected incoherent type: {0:?}", self_ty),
    Location::caller())bug!("unexpected incoherent type: {:?}", self_ty)
967        };
968        for &impl_def_id in self.tcx.incoherent_impls(simp).into_iter() {
969            self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
970        }
971    }
972
973    fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: DefId, receiver_steps: usize) {
974        let impl_def_ids = self.tcx.at(self.span).inherent_impls(def_id).into_iter();
975        for &impl_def_id in impl_def_ids {
976            self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
977        }
978    }
979
980    {}
#[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_inherent_impl_probe",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(980u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("impl_def_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("impl_def_id");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("receiver_steps")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("receiver_steps");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_def_id)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&receiver_steps as
                                                            &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if !self.impl_dups.insert(impl_def_id) { return; }
            for item in self.impl_or_trait_item(impl_def_id) {
                if !self.has_applicable_self(&item) {
                    self.record_static_candidate(CandidateSource::Impl(impl_def_id));
                    continue;
                }
                self.push_candidate(Candidate {
                        item,
                        kind: InherentImplCandidate { impl_def_id, receiver_steps },
                        import_ids: &[],
                    }, true);
            }
        }
    }
}#[instrument(level = "debug", skip(self))]
981    fn assemble_inherent_impl_probe(&mut self, impl_def_id: DefId, receiver_steps: usize) {
982        if !self.impl_dups.insert(impl_def_id) {
983            return; // already visited
984        }
985
986        for item in self.impl_or_trait_item(impl_def_id) {
987            if !self.has_applicable_self(&item) {
988                // No receiver declared. Not a candidate.
989                self.record_static_candidate(CandidateSource::Impl(impl_def_id));
990                continue;
991            }
992            self.push_candidate(
993                Candidate {
994                    item,
995                    kind: InherentImplCandidate { impl_def_id, receiver_steps },
996                    import_ids: &[],
997                },
998                true,
999            );
1000        }
1001    }
1002
1003    {}
#[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_inherent_candidates_from_object",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1003u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self_ty");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } 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 principal =
                match self_ty.kind() {
                            ty::Dynamic(data, ..) => Some(data),
                            _ => None,
                        }.and_then(|data|
                            data.principal()).unwrap_or_else(||
                        {
                            ::rustc_span::macros::bug_impl(Some(self.span),
                                format_args!("non-object {0:?} in assemble_inherent_candidates_from_object",
                                    self_ty), Location::caller())
                        });
            let trait_ref = principal.with_self_ty(self.tcx, self_ty);
            self.assemble_candidates_for_bounds(traits::supertraits(self.tcx,
                    trait_ref),
                |this, new_trait_ref, item|
                    {
                        this.push_candidate(Candidate {
                                item,
                                kind: ObjectCandidate(new_trait_ref),
                                import_ids: &[],
                            }, true);
                    });
        }
    }
}#[instrument(level = "debug", skip(self))]
1004    fn assemble_inherent_candidates_from_object(&mut self, self_ty: Ty<'tcx>) {
1005        let principal = match self_ty.kind() {
1006            ty::Dynamic(data, ..) => Some(data),
1007            _ => None,
1008        }
1009        .and_then(|data| data.principal())
1010        .unwrap_or_else(|| {
1011            span_bug!(
1012                self.span,
1013                "non-object {:?} in assemble_inherent_candidates_from_object",
1014                self_ty
1015            )
1016        });
1017
1018        // It is illegal to invoke a method on a trait instance that refers to
1019        // the `Self` type. An [`DynCompatibilityViolation::SupertraitSelf`] error
1020        // will be reported by `dyn_compatibility.rs` if the method refers to the
1021        // `Self` type anywhere other than the receiver. Here, we use a
1022        // instantiation that replaces `Self` with the object type itself. Hence,
1023        // a `&self` method will wind up with an argument type like `&dyn Trait`.
1024        let trait_ref = principal.with_self_ty(self.tcx, self_ty);
1025        self.assemble_candidates_for_bounds(
1026            traits::supertraits(self.tcx, trait_ref),
1027            |this, new_trait_ref, item| {
1028                this.push_candidate(
1029                    Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: &[] },
1030                    true,
1031                );
1032            },
1033        );
1034    }
1035
1036    {}
#[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_inherent_candidates_from_param",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1036u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("param_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("param_ty");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&param_ty)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if true {
                {
                    match param_ty.kind() {
                        ty::Param(_) => {}
                        ref left_val => {
                            ::core::panicking::assert_matches_failed(left_val,
                                "ty::Param(_)", ::core::option::Option::None);
                        }
                    }
                };
            };
            let tcx = self.tcx;
            let bounds =
                self.param_env.caller_bounds().filter_map(|clause|
                        {
                            let bound_clause = clause.kind();
                            match bound_clause.skip_binder() {
                                ty::ClauseKind::Trait(trait_predicate) =>
                                    DeepRejectCtxt::relate_rigid_rigid(tcx).types_may_unify(param_ty,
                                            trait_predicate.trait_ref.self_ty()).then(||
                                            bound_clause.rebind(trait_predicate.trait_ref)),
                                ty::ClauseKind::RegionOutlives(_) |
                                    ty::ClauseKind::TypeOutlives(_) |
                                    ty::ClauseKind::Projection(_) |
                                    ty::ClauseKind::ConstArgHasType(_, _) |
                                    ty::ClauseKind::WellFormed(_) |
                                    ty::ClauseKind::ConstEvaluatable(_) |
                                    ty::ClauseKind::UnstableFeature(_) |
                                    ty::ClauseKind::HostEffect(..) => None,
                            }
                        });
            self.assemble_candidates_for_bounds(bounds,
                |this, poly_trait_ref, item|
                    {
                        this.push_candidate(Candidate {
                                item,
                                kind: WhereClauseCandidate(poly_trait_ref),
                                import_ids: &[],
                            }, true);
                    });
        }
    }
}#[instrument(level = "debug", skip(self))]
1037    fn assemble_inherent_candidates_from_param(&mut self, param_ty: Ty<'tcx>) {
1038        debug_assert_matches!(param_ty.kind(), ty::Param(_));
1039
1040        let tcx = self.tcx;
1041
1042        // We use `DeepRejectCtxt` here which may return false positive on where clauses
1043        // with alias self types. We need to later on reject these as inherent candidates
1044        // in `consider_probe`.
1045        let bounds = self.param_env.caller_bounds().filter_map(|clause| {
1046            let bound_clause = clause.kind();
1047            match bound_clause.skip_binder() {
1048                ty::ClauseKind::Trait(trait_predicate) => DeepRejectCtxt::relate_rigid_rigid(tcx)
1049                    .types_may_unify(param_ty, trait_predicate.trait_ref.self_ty())
1050                    .then(|| bound_clause.rebind(trait_predicate.trait_ref)),
1051                ty::ClauseKind::RegionOutlives(_)
1052                | ty::ClauseKind::TypeOutlives(_)
1053                | ty::ClauseKind::Projection(_)
1054                | ty::ClauseKind::ConstArgHasType(_, _)
1055                | ty::ClauseKind::WellFormed(_)
1056                | ty::ClauseKind::ConstEvaluatable(_)
1057                | ty::ClauseKind::UnstableFeature(_)
1058                | ty::ClauseKind::HostEffect(..) => None,
1059            }
1060        });
1061
1062        self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
1063            this.push_candidate(
1064                Candidate { item, kind: WhereClauseCandidate(poly_trait_ref), import_ids: &[] },
1065                true,
1066            );
1067        });
1068    }
1069
1070    // Do a search through a list of bounds, using a callback to actually
1071    // create the candidates.
1072    fn assemble_candidates_for_bounds<F>(
1073        &mut self,
1074        bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
1075        mut mk_cand: F,
1076    ) where
1077        F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
1078    {
1079        for bound_trait_ref in bounds {
1080            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:1080",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(1080u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("elaborate_bounds(bound_trait_ref={0:?})",
                                                    bound_trait_ref) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref);
1081            for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1082                if !self.has_applicable_self(&item) {
1083                    self.record_static_candidate(CandidateSource::Trait(bound_trait_ref.def_id()));
1084                } else {
1085                    mk_cand(self, bound_trait_ref, item);
1086                }
1087            }
1088        }
1089    }
1090
1091    {}
#[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_extension_candidates_for_traits_in_scope",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1091u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::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_all(&[]) })
                } 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 mut duplicates = FxHashSet::default();
            let opt_applicable_traits =
                self.tcx.in_scope_traits(self.scope_expr_id);
            if let Some(applicable_traits) = opt_applicable_traits {
                for trait_candidate in applicable_traits.iter() {
                    let trait_did = trait_candidate.def_id;
                    if duplicates.insert((trait_did,
                                trait_candidate.lint_ambiguous)) {
                        self.assemble_extension_candidates_for_trait(&trait_candidate.import_ids,
                            trait_did, trait_candidate.lint_ambiguous);
                    }
                }
            }
        }
    }
}#[instrument(level = "debug", skip(self))]
1092    fn assemble_extension_candidates_for_traits_in_scope(&mut self) {
1093        let mut duplicates = FxHashSet::default();
1094        let opt_applicable_traits = self.tcx.in_scope_traits(self.scope_expr_id);
1095        if let Some(applicable_traits) = opt_applicable_traits {
1096            for trait_candidate in applicable_traits.iter() {
1097                let trait_did = trait_candidate.def_id;
1098                // If we have the same trait in scope but one of them is ambiguous and the other
1099                // is not, we should treat them differently and then handle them later on.
1100                if duplicates.insert((trait_did, trait_candidate.lint_ambiguous)) {
1101                    self.assemble_extension_candidates_for_trait(
1102                        &trait_candidate.import_ids,
1103                        trait_did,
1104                        trait_candidate.lint_ambiguous,
1105                    );
1106                }
1107            }
1108        }
1109    }
1110
1111    {}
#[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_extension_candidates_for_all_traits",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1111u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::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_all(&[]) })
                } 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 mut duplicates = FxHashSet::default();
            for trait_info in suggest::all_traits(self.tcx) {
                if duplicates.insert(trait_info.def_id) {
                    self.assemble_extension_candidates_for_trait(&[],
                        trait_info.def_id, false);
                }
            }
        }
    }
}#[instrument(level = "debug", skip(self))]
1112    fn assemble_extension_candidates_for_all_traits(&mut self) {
1113        let mut duplicates = FxHashSet::default();
1114        for trait_info in suggest::all_traits(self.tcx) {
1115            if duplicates.insert(trait_info.def_id) {
1116                self.assemble_extension_candidates_for_trait(&[], trait_info.def_id, false);
1117            }
1118        }
1119    }
1120
1121    fn matches_return_type(&self, method: ty::AssocItem, expected: Ty<'tcx>) -> bool {
1122        match method.kind {
1123            ty::AssocKind::Fn { .. } => self.probe(|_| {
1124                let args = self.fresh_args_for_item(self.span, method.def_id);
1125                let fty =
1126                    self.tcx.fn_sig(method.def_id).instantiate(self.tcx, args).skip_norm_wip();
1127                let fty = self.instantiate_binder_with_fresh_vars(
1128                    self.span,
1129                    BoundRegionConversionTime::FnCall,
1130                    fty,
1131                );
1132                self.can_eq(self.param_env, fty.output(), expected)
1133            }),
1134            _ => false,
1135        }
1136    }
1137
1138    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("assemble_extension_candidates_for_trait",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1138u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("import_ids")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("import_ids");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("trait_def_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("trait_def_id");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("is_ambiguously_imported")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("is_ambiguously_imported");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&import_ids)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_def_id)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&is_ambiguously_imported
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let trait_args =
                self.fresh_args_for_item(self.span, trait_def_id);
            let trait_ref =
                ty::TraitRef::new_from_args(self.tcx, trait_def_id,
                    trait_args);
            if self.tcx.is_trait_alias(trait_def_id) {
                for (bound_trait_pred, _) in
                    traits::expand_trait_aliases(self.tcx,
                            [(trait_ref.upcast(self.tcx), self.span)]).0 {
                    {
                        match (&bound_trait_pred.polarity(),
                                &ty::ClausePolarity::Positive) {
                            (left_val, right_val) => {
                                if !(*left_val == *right_val) {
                                    let kind = ::core::panicking::AssertKind::Eq;
                                    ::core::panicking::assert_failed(kind, &*left_val,
                                        &*right_val, ::core::option::Option::None);
                                }
                            }
                        }
                    };
                    let bound_trait_ref =
                        bound_trait_pred.map_bound(|pred| pred.trait_ref);
                    for item in
                        self.impl_or_trait_item(bound_trait_ref.def_id()) {
                        if !self.has_applicable_self(&item) {
                            self.record_static_candidate(CandidateSource::Trait(bound_trait_ref.def_id()));
                        } else {
                            self.push_candidate(Candidate {
                                    item,
                                    import_ids,
                                    kind: TraitCandidate {
                                        trait_ref: bound_trait_ref,
                                        is_ambiguously_imported,
                                    },
                                }, false);
                        }
                    }
                }
            } else {
                if true {
                    if !self.tcx.is_trait(trait_def_id) {
                        ::core::panicking::panic("assertion failed: self.tcx.is_trait(trait_def_id)")
                    };
                };
                if self.tcx.trait_is_auto(trait_def_id) { return; }
                for item in self.impl_or_trait_item(trait_def_id) {
                    if !self.has_applicable_self(&item) {
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:1183",
                                                "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                                ::tracing_core::__macro_support::Option::Some(1183u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                                ::tracing_core::field::FieldSet::new(&["message"],
                                                    ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("method has inapplicable self")
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        self.record_static_candidate(CandidateSource::Trait(trait_def_id));
                        continue;
                    }
                    self.push_candidate(Candidate {
                            item,
                            import_ids,
                            kind: TraitCandidate {
                                trait_ref: ty::Binder::dummy(trait_ref),
                                is_ambiguously_imported,
                            },
                        }, false);
                }
            }
        }
    }
}#[instrument(level = "debug", skip(self))]
1139    fn assemble_extension_candidates_for_trait(
1140        &mut self,
1141        import_ids: &'tcx [LocalDefId],
1142        trait_def_id: DefId,
1143        is_ambiguously_imported: bool,
1144    ) {
1145        let trait_args = self.fresh_args_for_item(self.span, trait_def_id);
1146        let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
1147
1148        if self.tcx.is_trait_alias(trait_def_id) {
1149            // For trait aliases, recursively assume all explicitly named traits are relevant
1150            for (bound_trait_pred, _) in
1151                traits::expand_trait_aliases(self.tcx, [(trait_ref.upcast(self.tcx), self.span)]).0
1152            {
1153                assert_eq!(bound_trait_pred.polarity(), ty::ClausePolarity::Positive);
1154                let bound_trait_ref = bound_trait_pred.map_bound(|pred| pred.trait_ref);
1155                for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1156                    if !self.has_applicable_self(&item) {
1157                        self.record_static_candidate(CandidateSource::Trait(
1158                            bound_trait_ref.def_id(),
1159                        ));
1160                    } else {
1161                        self.push_candidate(
1162                            Candidate {
1163                                item,
1164                                import_ids,
1165                                kind: TraitCandidate {
1166                                    trait_ref: bound_trait_ref,
1167                                    is_ambiguously_imported,
1168                                },
1169                            },
1170                            false,
1171                        );
1172                    }
1173                }
1174            }
1175        } else {
1176            debug_assert!(self.tcx.is_trait(trait_def_id));
1177            if self.tcx.trait_is_auto(trait_def_id) {
1178                return;
1179            }
1180            for item in self.impl_or_trait_item(trait_def_id) {
1181                // Check whether `trait_def_id` defines a method with suitable name.
1182                if !self.has_applicable_self(&item) {
1183                    debug!("method has inapplicable self");
1184                    self.record_static_candidate(CandidateSource::Trait(trait_def_id));
1185                    continue;
1186                }
1187                self.push_candidate(
1188                    Candidate {
1189                        item,
1190                        import_ids,
1191                        kind: TraitCandidate {
1192                            trait_ref: ty::Binder::dummy(trait_ref),
1193                            is_ambiguously_imported,
1194                        },
1195                    },
1196                    false,
1197                );
1198            }
1199        }
1200    }
1201
1202    fn candidate_method_names(
1203        &self,
1204        candidate_filter: impl Fn(&ty::AssocItem) -> bool,
1205    ) -> Vec<Ident> {
1206        let mut set = FxHashSet::default();
1207        let mut names: Vec<_> = self
1208            .inherent_candidates
1209            .iter()
1210            .chain(&self.extension_candidates)
1211            .filter(|candidate| candidate_filter(&candidate.item))
1212            .filter(|candidate| {
1213                if let Some(return_ty) = self.return_type {
1214                    self.matches_return_type(candidate.item, return_ty)
1215                } else {
1216                    true
1217                }
1218            })
1219            // ensure that we don't suggest unstable methods
1220            .filter(|candidate| {
1221                // note that `DUMMY_SP` is ok here because it is only used for
1222                // suggestions and macro stuff which isn't applicable here.
1223                !#[allow(non_exhaustive_omitted_patterns)] match self.tcx.eval_stability(candidate.item.def_id,
        None, DUMMY_SP, None) {
    stability::EvalResult::Deny { .. } => true,
    _ => false,
}matches!(
1224                    self.tcx.eval_stability(candidate.item.def_id, None, DUMMY_SP, None),
1225                    stability::EvalResult::Deny { .. }
1226                )
1227            })
1228            .map(|candidate| candidate.item.ident(self.tcx))
1229            .filter(|&name| set.insert(name))
1230            .collect();
1231
1232        // Sort them by the name so we have a stable result.
1233        names.sort_by(|a, b| a.as_str().cmp(b.as_str()));
1234        names
1235    }
1236
1237    ///////////////////////////////////////////////////////////////////////////
1238    // THE ACTUAL SEARCH
1239
1240    {}
#[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("pick",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1240u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::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_all(&[]) })
                } 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: PickResult<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if !self.method_name.is_some() {
                ::core::panicking::panic("assertion failed: self.method_name.is_some()")
            };
            let mut unsatisfied_predicates = Vec::new();
            if let Some(r) = self.pick_core(&mut unsatisfied_predicates) {
                return r;
            }
            if self.is_suggestion.0 {
                return Err(MethodError::NoMatch(NoMatchData {
                                static_candidates: ::alloc::vec::Vec::new(),
                                unsatisfied_predicates: ::alloc::vec::Vec::new(),
                                out_of_scope_traits: ::alloc::vec::Vec::new(),
                                similar_candidate: None,
                                mode: self.mode,
                            }));
            }
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:1262",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1262u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pick: actual search failed, assemble diagnostics")
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let static_candidates =
                std::mem::take(self.static_candidates.get_mut());
            let private_candidate = self.private_candidate.take();
            self.reset();
            self.assemble_extension_candidates_for_all_traits();
            let out_of_scope_traits =
                match self.pick_core(&mut Vec::new()) {
                    Some(Ok(p)) =>
                        ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                [p.item.container_id(self.tcx)])),
                    Some(Err(MethodError::Ambiguity(v))) =>
                        v.into_iter().map(|source|
                                    match source {
                                        CandidateSource::Trait(id) => id,
                                        CandidateSource::Impl(impl_id) =>
                                            self.tcx.impl_trait_id(impl_id),
                                    }).collect(),
                    Some(Err(MethodError::NoMatch(NoMatchData {
                        out_of_scope_traits: others, .. }))) => {
                        if !others.is_empty() {
                            ::core::panicking::panic("assertion failed: others.is_empty()")
                        };
                        ::alloc::vec::Vec::new()
                    }
                    _ => ::alloc::vec::Vec::new(),
                };
            if let Some((kind, def_id)) = private_candidate {
                return Err(MethodError::PrivateMatch(kind, def_id,
                            out_of_scope_traits));
            }
            let similar_candidate = self.probe_for_similar_candidate()?;
            Err(MethodError::NoMatch(NoMatchData {
                        static_candidates,
                        unsatisfied_predicates,
                        out_of_scope_traits,
                        similar_candidate,
                        mode: self.mode,
                    }))
        }
    }
}#[instrument(level = "debug", skip(self))]
1241    fn pick(mut self) -> PickResult<'tcx> {
1242        assert!(self.method_name.is_some());
1243
1244        let mut unsatisfied_predicates = Vec::new();
1245
1246        if let Some(r) = self.pick_core(&mut unsatisfied_predicates) {
1247            return r;
1248        }
1249
1250        // If it's a `lookup_probe_for_diagnostic`, then quit early. No need to
1251        // probe for other candidates.
1252        if self.is_suggestion.0 {
1253            return Err(MethodError::NoMatch(NoMatchData {
1254                static_candidates: vec![],
1255                unsatisfied_predicates: vec![],
1256                out_of_scope_traits: vec![],
1257                similar_candidate: None,
1258                mode: self.mode,
1259            }));
1260        }
1261
1262        debug!("pick: actual search failed, assemble diagnostics");
1263
1264        let static_candidates = std::mem::take(self.static_candidates.get_mut());
1265        let private_candidate = self.private_candidate.take();
1266
1267        // things failed, so lets look at all traits, for diagnostic purposes now:
1268        self.reset();
1269
1270        self.assemble_extension_candidates_for_all_traits();
1271
1272        let out_of_scope_traits = match self.pick_core(&mut Vec::new()) {
1273            Some(Ok(p)) => vec![p.item.container_id(self.tcx)],
1274            Some(Err(MethodError::Ambiguity(v))) => v
1275                .into_iter()
1276                .map(|source| match source {
1277                    CandidateSource::Trait(id) => id,
1278                    CandidateSource::Impl(impl_id) => self.tcx.impl_trait_id(impl_id),
1279                })
1280                .collect(),
1281            Some(Err(MethodError::NoMatch(NoMatchData {
1282                out_of_scope_traits: others, ..
1283            }))) => {
1284                assert!(others.is_empty());
1285                vec![]
1286            }
1287            _ => vec![],
1288        };
1289
1290        if let Some((kind, def_id)) = private_candidate {
1291            return Err(MethodError::PrivateMatch(kind, def_id, out_of_scope_traits));
1292        }
1293        let similar_candidate = self.probe_for_similar_candidate()?;
1294
1295        Err(MethodError::NoMatch(NoMatchData {
1296            static_candidates,
1297            unsatisfied_predicates,
1298            out_of_scope_traits,
1299            similar_candidate,
1300            mode: self.mode,
1301        }))
1302    }
1303
1304    fn pick_core(
1305        &self,
1306        unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
1307    ) -> Option<PickResult<'tcx>> {
1308        // Pick stable methods only first, and consider unstable candidates if not found.
1309        self.pick_all_method(&mut PickDiagHints {
1310            // This first cycle, maintain a list of unstable candidates which
1311            // we encounter. This will end up in the Pick for diagnostics.
1312            unstable_candidates: Some(Vec::new()),
1313            // Contribute to the list of unsatisfied predicates which may
1314            // also be used for diagnostics.
1315            unsatisfied_predicates,
1316        })
1317        .or_else(|| {
1318            self.pick_all_method(&mut PickDiagHints {
1319                // On the second search, don't provide a special list of unstable
1320                // candidates. This indicates to the picking code that it should
1321                // in fact include such unstable candidates in the actual
1322                // search.
1323                unstable_candidates: None,
1324                // And there's no need to duplicate ourselves in the
1325                // unsatisifed predicates list. Provide a throwaway list.
1326                unsatisfied_predicates: &mut Vec::new(),
1327            })
1328        })
1329    }
1330
1331    fn pick_all_method<'b>(
1332        &self,
1333        pick_diag_hints: &mut PickDiagHints<'b, 'tcx>,
1334    ) -> Option<PickResult<'tcx>> {
1335        let track_unstable_candidates = pick_diag_hints.unstable_candidates.is_some();
1336        self.steps
1337            .iter()
1338            // At this point we're considering the types to which the receiver can be converted,
1339            // so we want to follow the `Deref` chain not the `Receiver` chain. Filter out
1340            // steps which can only be reached by following the (longer) `Receiver` chain.
1341            .filter(|step| step.reachable_via_deref)
1342            .filter(|step| {
1343                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:1343",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(1343u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pick_all_method: step={0:?}",
                                                    step) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("pick_all_method: step={:?}", step);
1344                // skip types that are from a type error or that would require dereferencing
1345                // a raw pointer
1346                !step.self_ty.value.references_error() && !step.from_unsafe_deref
1347            })
1348            .find_map(|step| {
1349                let InferOk { value: self_ty, obligations: instantiate_self_ty_obligations } = self
1350                    .fcx
1351                    .probe_instantiate_query_response(
1352                        self.span,
1353                        self.orig_steps_var_values,
1354                        &step.self_ty,
1355                    )
1356                    .unwrap_or_else(|_| {
1357                        ::rustc_span::macros::bug_impl(Some(self.span),
    format_args!("{0:?} was applicable but now isn\'t?", step.self_ty),
    Location::caller())span_bug!(self.span, "{:?} was applicable but now isn't?", step.self_ty)
1358                    });
1359
1360                let by_value_pick = self.pick_by_value_method(
1361                    step,
1362                    self_ty,
1363                    &instantiate_self_ty_obligations,
1364                    pick_diag_hints,
1365                );
1366
1367                // Check for shadowing of a by-reference method by a by-value method (see comments on check_for_shadowing)
1368                if let Some(by_value_pick) = by_value_pick {
1369                    if let Ok(by_value_pick) = by_value_pick.as_ref() {
1370                        if by_value_pick.kind == PickKind::InherentImplPick {
1371                            for mutbl in [hir::Mutability::Not, hir::Mutability::Mut] {
1372                                if let Err(e) = self.check_for_shadowed_autorefd_method(
1373                                    by_value_pick,
1374                                    step,
1375                                    self_ty,
1376                                    &instantiate_self_ty_obligations,
1377                                    mutbl,
1378                                    track_unstable_candidates,
1379                                ) {
1380                                    return Some(Err(e));
1381                                }
1382                            }
1383                        }
1384                    }
1385                    return Some(by_value_pick);
1386                }
1387
1388                let autoref_pick = self.pick_autorefd_method(
1389                    step,
1390                    self_ty,
1391                    &instantiate_self_ty_obligations,
1392                    hir::Mutability::Not,
1393                    pick_diag_hints,
1394                    None,
1395                );
1396                // Check for shadowing of a by-mut-ref method by a by-reference method (see comments on check_for_shadowing)
1397                if let Some(autoref_pick) = autoref_pick {
1398                    if let Ok(autoref_pick) = autoref_pick.as_ref() {
1399                        // Check we're not shadowing others
1400                        if autoref_pick.kind == PickKind::InherentImplPick {
1401                            if let Err(e) = self.check_for_shadowed_autorefd_method(
1402                                autoref_pick,
1403                                step,
1404                                self_ty,
1405                                &instantiate_self_ty_obligations,
1406                                hir::Mutability::Mut,
1407                                track_unstable_candidates,
1408                            ) {
1409                                return Some(Err(e));
1410                            }
1411                        }
1412                    }
1413                    return Some(autoref_pick);
1414                }
1415
1416                // Note that no shadowing errors are produced from here on,
1417                // as we consider const ptr methods.
1418                // We allow new methods that take *mut T to shadow
1419                // methods which took *const T, so there is no entry in
1420                // this list for the results of `pick_const_ptr_method`.
1421                // The reason is that the standard pointer cast method
1422                // (on a mutable pointer) always already shadows the
1423                // cast method (on a const pointer). So, if we added
1424                // `pick_const_ptr_method` to this method, the anti-
1425                // shadowing algorithm would always complain about
1426                // the conflict between *const::cast and *mut::cast.
1427                // In practice therefore this does constrain us:
1428                // we cannot add new
1429                //   self: *mut Self
1430                // methods to types such as NonNull or anything else
1431                // which implements Receiver, because this might in future
1432                // shadow existing methods taking
1433                //   self: *const NonNull<Self>
1434                // in the pointee. In practice, methods taking raw pointers
1435                // are rare, and it seems that it should be easily possible
1436                // to avoid such compatibility breaks.
1437                // We also don't check for reborrowed pin methods which
1438                // may be shadowed; these also seem unlikely to occur.
1439                self.pick_autorefd_method(
1440                    step,
1441                    self_ty,
1442                    &instantiate_self_ty_obligations,
1443                    hir::Mutability::Mut,
1444                    pick_diag_hints,
1445                    None,
1446                )
1447                .or_else(|| {
1448                    self.pick_const_ptr_method(
1449                        step,
1450                        self_ty,
1451                        &instantiate_self_ty_obligations,
1452                        pick_diag_hints,
1453                    )
1454                })
1455                .or_else(|| {
1456                    self.pick_reborrow_pin_method(
1457                        step,
1458                        self_ty,
1459                        &instantiate_self_ty_obligations,
1460                        pick_diag_hints,
1461                    )
1462                })
1463            })
1464    }
1465
1466    /// Check for cases where arbitrary self types allows shadowing
1467    /// of methods that might be a compatibility break. Specifically,
1468    /// we have something like:
1469    /// ```ignore (illustrative)
1470    /// struct A;
1471    /// impl A {
1472    ///   fn foo(self: &NonNull<A>) {}
1473    ///      // note this is by reference
1474    /// }
1475    /// ```
1476    /// then we've come along and added this method to `NonNull`:
1477    /// ```ignore (illustrative)
1478    ///   fn foo(self)  // note this is by value
1479    /// ```
1480    /// Report an error in this case.
1481    fn check_for_shadowed_autorefd_method(
1482        &self,
1483        possible_shadower: &Pick<'tcx>,
1484        step: &CandidateStep<'tcx>,
1485        self_ty: Ty<'tcx>,
1486        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1487        mutbl: hir::Mutability,
1488        track_unstable_candidates: bool,
1489    ) -> Result<(), MethodError<'tcx>> {
1490        // The errors emitted by this function are part of
1491        // the arbitrary self types work, and should not impact
1492        // other users.
1493        if !self.tcx.features().arbitrary_self_types()
1494            && !self.tcx.features().arbitrary_self_types_pointers()
1495        {
1496            return Ok(());
1497        }
1498
1499        // We don't want to remember any of the diagnostic hints from this
1500        // shadow search, but we do need to provide Some/None for the
1501        // unstable_candidates in order to reflect the behavior of the
1502        // main search.
1503        let mut pick_diag_hints = PickDiagHints {
1504            unstable_candidates: if track_unstable_candidates { Some(Vec::new()) } else { None },
1505            unsatisfied_predicates: &mut Vec::new(),
1506        };
1507        // Set criteria for how we find methods possibly shadowed by 'possible_shadower'
1508        let pick_constraints = PickConstraintsForShadowed {
1509            // It's the same `self` type...
1510            autoderefs: possible_shadower.autoderefs,
1511            // ... but the method was found in an impl block determined
1512            // by searching further along the Receiver chain than the other,
1513            // showing that it's a smart pointer type causing the problem...
1514            receiver_steps: possible_shadower.receiver_steps,
1515            // ... and they don't end up pointing to the same item in the
1516            // first place (could happen with things like blanket impls for T)
1517            def_id: possible_shadower.item.def_id,
1518        };
1519        // A note on the autoderefs above. Within pick_by_value_method, an extra
1520        // autoderef may be applied in order to reborrow a reference with
1521        // a different lifetime. That seems as though it would break the
1522        // logic of these constraints, since the number of autoderefs could
1523        // no longer be used to identify the fundamental type of the receiver.
1524        // However, this extra autoderef is applied only to by-value calls
1525        // where the receiver is already a reference. So this situation would
1526        // only occur in cases where the shadowing looks like this:
1527        // ```
1528        // struct A;
1529        // impl A {
1530        //   fn foo(self: &&NonNull<A>) {}
1531        //      // note this is by DOUBLE reference
1532        // }
1533        // ```
1534        // then we've come along and added this method to `NonNull`:
1535        // ```
1536        //   fn foo(&self)  // note this is by single reference
1537        // ```
1538        // and the call is:
1539        // ```
1540        // let bar = NonNull<Foo>;
1541        // let bar = &foo;
1542        // bar.foo();
1543        // ```
1544        // In these circumstances, the logic is wrong, and we wouldn't spot
1545        // the shadowing, because the autoderef-based maths wouldn't line up.
1546        // This is a niche case and we can live without generating an error
1547        // in the case of such shadowing.
1548        let potentially_shadowed_pick = self.pick_autorefd_method(
1549            step,
1550            self_ty,
1551            instantiate_self_ty_obligations,
1552            mutbl,
1553            &mut pick_diag_hints,
1554            Some(&pick_constraints),
1555        );
1556        // Look for actual pairs of shadower/shadowed which are
1557        // the sort of shadowing case we want to avoid. Specifically...
1558        if let Some(Ok(possible_shadowed)) = potentially_shadowed_pick.as_ref() {
1559            let sources = [possible_shadower, possible_shadowed]
1560                .into_iter()
1561                .map(|p| self.candidate_source_from_pick(p))
1562                .collect();
1563            return Err(MethodError::Ambiguity(sources));
1564        }
1565        Ok(())
1566    }
1567
1568    /// For each type `T` in the step list, this attempts to find a method where
1569    /// the (transformed) self type is exactly `T`. We do however do one
1570    /// transformation on the adjustment: if we are passing a region pointer in,
1571    /// we will potentially *reborrow* it to a shorter lifetime. This allows us
1572    /// to transparently pass `&mut` pointers, in particular, without consuming
1573    /// them for their entire lifetime.
1574    fn pick_by_value_method(
1575        &self,
1576        step: &CandidateStep<'tcx>,
1577        self_ty: Ty<'tcx>,
1578        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1579        pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1580    ) -> Option<PickResult<'tcx>> {
1581        if step.unsize {
1582            return None;
1583        }
1584
1585        self.pick_method(self_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(|r| {
1586            r.map(|mut pick| {
1587                pick.autoderefs = step.autoderefs;
1588
1589                match *step.self_ty.value.value.kind() {
1590                    // Insert a `&*` or `&mut *` if this is a reference type:
1591                    ty::Ref(_, _, mutbl) => {
1592                        pick.autoderefs += 1;
1593                        pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref {
1594                            mutbl,
1595                            unsize: pick.autoref_or_ptr_adjustment.is_some_and(|a| a.get_unsize()),
1596                        })
1597                    }
1598
1599                    ty::Adt(def, args)
1600                        if self.tcx.features().pin_ergonomics()
1601                            && self.tcx.is_lang_item(def.did(), LangItem::Pin) =>
1602                    {
1603                        // make sure this is a pinned reference (and not a `Pin<Box>` or something)
1604                        if let ty::Ref(_, _, mutbl) = args[0].expect_ty().kind() {
1605                            pick.autoref_or_ptr_adjustment =
1606                                Some(AutorefOrPtrAdjustment::ReborrowPin(*mutbl));
1607                        }
1608                    }
1609
1610                    _ => (),
1611                }
1612
1613                pick
1614            })
1615        })
1616    }
1617
1618    fn pick_autorefd_method(
1619        &self,
1620        step: &CandidateStep<'tcx>,
1621        self_ty: Ty<'tcx>,
1622        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1623        mutbl: hir::Mutability,
1624        pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1625        pick_constraints: Option<&PickConstraintsForShadowed>,
1626    ) -> Option<PickResult<'tcx>> {
1627        let tcx = self.tcx;
1628
1629        if let Some(pick_constraints) = pick_constraints {
1630            if !pick_constraints.may_shadow_based_on_autoderefs(step.autoderefs) {
1631                return None;
1632            }
1633        }
1634
1635        // In general, during probing we erase regions.
1636        let region = tcx.lifetimes.re_erased;
1637
1638        let autoref_ty = Ty::new_ref(tcx, region, self_ty, mutbl);
1639        self.pick_method(
1640            autoref_ty,
1641            instantiate_self_ty_obligations,
1642            pick_diag_hints,
1643            pick_constraints,
1644        )
1645        .map(|r| {
1646            r.map(|mut pick| {
1647                pick.autoderefs = step.autoderefs;
1648                pick.autoref_or_ptr_adjustment =
1649                    Some(AutorefOrPtrAdjustment::Autoref { mutbl, unsize: step.unsize });
1650                pick
1651            })
1652        })
1653    }
1654
1655    /// Looks for applicable methods if we reborrow a `Pin<&mut T>` as a `Pin<&T>`.
1656    {}
#[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("pick_reborrow_pin_method",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1656u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self_ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("instantiate_self_ty_obligations")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("instantiate_self_ty_obligations");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instantiate_self_ty_obligations)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: Option<PickResult<'tcx>> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            if !self.tcx.features().pin_ergonomics() { return None; }
            let inner_ty =
                match self_ty.kind() {
                    ty::Adt(def, args) if
                        self.tcx.is_lang_item(def.did(), LangItem::Pin) => {
                        match args[0].expect_ty().kind() {
                            ty::Ref(_, ty, hir::Mutability::Mut) => *ty,
                            _ => { return None; }
                        }
                    }
                    _ => return None,
                };
            let region = self.tcx.lifetimes.re_erased;
            let autopin_ty =
                Ty::new_pinned_ref(self.tcx, region, inner_ty,
                    hir::Mutability::Not);
            self.pick_method(autopin_ty, instantiate_self_ty_obligations,
                    pick_diag_hints,
                    None).map(|r|
                    {
                        r.map(|mut pick|
                                {
                                    pick.autoderefs = step.autoderefs;
                                    pick.autoref_or_ptr_adjustment =
                                        Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not));
                                    pick
                                })
                    })
        }
    }
}#[instrument(level = "debug", skip(self, step, pick_diag_hints))]
1657    fn pick_reborrow_pin_method(
1658        &self,
1659        step: &CandidateStep<'tcx>,
1660        self_ty: Ty<'tcx>,
1661        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1662        pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1663    ) -> Option<PickResult<'tcx>> {
1664        if !self.tcx.features().pin_ergonomics() {
1665            return None;
1666        }
1667
1668        // make sure self is a Pin<&mut T>
1669        let inner_ty = match self_ty.kind() {
1670            ty::Adt(def, args) if self.tcx.is_lang_item(def.did(), LangItem::Pin) => {
1671                match args[0].expect_ty().kind() {
1672                    ty::Ref(_, ty, hir::Mutability::Mut) => *ty,
1673                    _ => {
1674                        return None;
1675                    }
1676                }
1677            }
1678            _ => return None,
1679        };
1680
1681        let region = self.tcx.lifetimes.re_erased;
1682        let autopin_ty = Ty::new_pinned_ref(self.tcx, region, inner_ty, hir::Mutability::Not);
1683        self.pick_method(autopin_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1684            |r| {
1685                r.map(|mut pick| {
1686                    pick.autoderefs = step.autoderefs;
1687                    pick.autoref_or_ptr_adjustment =
1688                        Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not));
1689                    pick
1690                })
1691            },
1692        )
1693    }
1694
1695    /// If `self_ty` is `*mut T` then this picks `*const T` methods. The reason why we have a
1696    /// special case for this is because going from `*mut T` to `*const T` with autoderefs and
1697    /// autorefs would require dereferencing the pointer, which is not safe.
1698    fn pick_const_ptr_method(
1699        &self,
1700        step: &CandidateStep<'tcx>,
1701        self_ty: Ty<'tcx>,
1702        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1703        pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1704    ) -> Option<PickResult<'tcx>> {
1705        // Don't convert an unsized reference to ptr
1706        if step.unsize {
1707            return None;
1708        }
1709
1710        let &ty::RawPtr(ty, hir::Mutability::Mut) = self_ty.kind() else {
1711            return None;
1712        };
1713
1714        let const_ptr_ty = Ty::new_imm_ptr(self.tcx, ty);
1715        self.pick_method(const_ptr_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1716            |r| {
1717                r.map(|mut pick| {
1718                    pick.autoderefs = step.autoderefs;
1719                    pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::ToConstPtr);
1720                    pick
1721                })
1722            },
1723        )
1724    }
1725
1726    fn pick_method(
1727        &self,
1728        self_ty: Ty<'tcx>,
1729        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1730        pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1731        pick_constraints: Option<&PickConstraintsForShadowed>,
1732    ) -> Option<PickResult<'tcx>> {
1733        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:1733",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(1733u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pick_method(self_ty={0})",
                                                    self.ty_to_string(self_ty)) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("pick_method(self_ty={})", self.ty_to_string(self_ty));
1734
1735        for (kind, candidates) in
1736            [("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
1737        {
1738            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:1738",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(1738u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("searching {0} candidates",
                                                    kind) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("searching {} candidates", kind);
1739            let res = self.consider_candidates(
1740                self_ty,
1741                instantiate_self_ty_obligations,
1742                candidates,
1743                pick_diag_hints,
1744                pick_constraints,
1745            );
1746            if let Some(pick) = res {
1747                return Some(pick);
1748            }
1749        }
1750
1751        if self.private_candidate.get().is_none() {
1752            if let Some(Ok(pick)) = self.consider_candidates(
1753                self_ty,
1754                instantiate_self_ty_obligations,
1755                &self.private_candidates,
1756                &mut PickDiagHints {
1757                    unstable_candidates: None,
1758                    unsatisfied_predicates: &mut ::alloc::vec::Vec::new()vec![],
1759                },
1760                None,
1761            ) {
1762                self.private_candidate.set(Some((pick.item.as_def_kind(), pick.item.def_id)));
1763            }
1764        }
1765        None
1766    }
1767
1768    fn consider_candidates(
1769        &self,
1770        self_ty: Ty<'tcx>,
1771        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1772        candidates: &[Candidate<'tcx>],
1773        pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1774        pick_constraints: Option<&PickConstraintsForShadowed>,
1775    ) -> Option<PickResult<'tcx>> {
1776        let mut applicable_candidates: Vec<_> = candidates
1777            .iter()
1778            .filter(|candidate| {
1779                pick_constraints
1780                    .map(|pick_constraints| pick_constraints.candidate_may_shadow(&candidate))
1781                    .unwrap_or(true)
1782            })
1783            .map(|probe| {
1784                (
1785                    probe,
1786                    self.consider_probe(
1787                        self_ty,
1788                        instantiate_self_ty_obligations,
1789                        probe,
1790                        &mut pick_diag_hints.unsatisfied_predicates,
1791                    ),
1792                )
1793            })
1794            .filter(|&(_, status)| status != ProbeResult::NoMatch)
1795            .collect();
1796
1797        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:1797",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(1797u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("applicable_candidates: {0:?}",
                                                    applicable_candidates) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("applicable_candidates: {:?}", applicable_candidates);
1798
1799        if applicable_candidates.len() > 1 {
1800            if let Some(pick) =
1801                self.collapse_candidates_to_trait_pick(self_ty, &applicable_candidates)
1802            {
1803                return Some(Ok(pick));
1804            }
1805        }
1806
1807        if let Some(uc) = &mut pick_diag_hints.unstable_candidates {
1808            applicable_candidates.retain(|&(candidate, _)| {
1809                if let stability::EvalResult::Deny { feature, .. } =
1810                    self.tcx.eval_stability(candidate.item.def_id, None, self.span, None)
1811                {
1812                    uc.push((candidate.clone(), feature));
1813                    return false;
1814                }
1815                true
1816            });
1817        }
1818
1819        if applicable_candidates.len() > 1 {
1820            // We collapse to a subtrait pick *after* filtering unstable candidates
1821            // to make sure we don't prefer a unstable subtrait method over a stable
1822            // supertrait method.
1823            if self.tcx.features().supertrait_item_shadowing() {
1824                if let Some(pick) =
1825                    self.collapse_candidates_to_subtrait_pick(self_ty, &applicable_candidates)
1826                {
1827                    return Some(Ok(pick));
1828                }
1829            }
1830
1831            let sources =
1832                applicable_candidates.iter().map(|p| self.candidate_source(p.0, self_ty)).collect();
1833            return Some(Err(MethodError::Ambiguity(sources)));
1834        }
1835
1836        applicable_candidates.pop().map(|(probe, status)| match status {
1837            ProbeResult::Match => Ok(probe.to_unadjusted_pick(
1838                self_ty,
1839                pick_diag_hints.unstable_candidates.clone().unwrap_or_default(),
1840            )),
1841            ProbeResult::NoMatch | ProbeResult::BadReturnType => Err(MethodError::BadReturnType),
1842        })
1843    }
1844}
1845
1846impl<'tcx> Pick<'tcx> {
1847    /// In case there were unstable name collisions, emit them as a lint.
1848    /// Checks whether two picks do not refer to the same trait item for the same `Self` type.
1849    /// Only useful for comparisons of picks in order to improve diagnostics.
1850    /// Do not use for type checking.
1851    pub(crate) fn differs_from(&self, other: &Self) -> bool {
1852        let Self {
1853            item: AssocItem { def_id, kind: _, container: _ },
1854            kind: _,
1855            import_ids: _,
1856            autoderefs: _,
1857            autoref_or_ptr_adjustment: _,
1858            self_ty,
1859            unstable_candidates: _,
1860            receiver_steps: _,
1861            shadowed_candidates: _,
1862        } = *self;
1863        self_ty != other.self_ty || def_id != other.item.def_id
1864    }
1865
1866    /// In case there were unstable name collisions, emit them as a lint.
1867    pub(crate) fn maybe_emit_unstable_name_collision_hint(
1868        &self,
1869        tcx: TyCtxt<'tcx>,
1870        span: Span,
1871        scope_expr_id: HirId,
1872    ) {
1873        struct ItemMaybeBeAddedToStd<'a, 'tcx> {
1874            this: &'a Pick<'tcx>,
1875            tcx: TyCtxt<'tcx>,
1876            span: Span,
1877        }
1878
1879        impl<'a, 'b, 'tcx> Diagnostic<'a> for ItemMaybeBeAddedToStd<'b, 'tcx> {
1880            fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a> {
1881                let Self { this, tcx, span } = self;
1882                let def_kind = this.item.as_def_kind();
1883                let mut lint = Diag::new(
1884                    dcx,
1885                    level,
1886                    ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0} {1} with this name may be added to the standard library in the future",
                tcx.def_kind_descr_article(def_kind, this.item.def_id),
                tcx.def_kind_descr(def_kind, this.item.def_id)))
    })format!(
1887                        "{} {} with this name may be added to the standard library in the future",
1888                        tcx.def_kind_descr_article(def_kind, this.item.def_id),
1889                        tcx.def_kind_descr(def_kind, this.item.def_id),
1890                    ),
1891                );
1892
1893                match (this.item.kind, this.item.container) {
1894                    (ty::AssocKind::Fn { .. }, _) => {
1895                        // FIXME: This should be a `span_suggestion` instead of `help`
1896                        // However `this.span` only
1897                        // highlights the method name, so we can't use it. Also consider reusing
1898                        // the code from `report_method_error()`.
1899                        lint.help(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("call with fully qualified syntax `{0}(...)` to keep using the current method",
                tcx.def_path_str(this.item.def_id)))
    })format!(
1900                            "call with fully qualified syntax `{}(...)` to keep using the current \
1901                                 method",
1902                            tcx.def_path_str(this.item.def_id),
1903                        ));
1904                    }
1905                    (ty::AssocKind::Const { name, .. }, ty::AssocContainer::Trait) => {
1906                        let def_id = this.item.container_id(tcx);
1907                        lint.span_suggestion(
1908                            span,
1909                            "use the fully qualified path to the associated const",
1910                            ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("<{0} as {1}>::{2}", this.self_ty,
                tcx.def_path_str(def_id), name))
    })format!("<{} as {}>::{}", this.self_ty, tcx.def_path_str(def_id), name),
1911                            Applicability::MachineApplicable,
1912                        );
1913                    }
1914                    _ => {}
1915                }
1916                tcx.disabled_nightly_features(
1917                    &mut lint,
1918                    this.unstable_candidates.iter().map(|(candidate, feature)| {
1919                        (::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!(" `{0}`",
                tcx.def_path_str(candidate.item.def_id)))
    })format!(" `{}`", tcx.def_path_str(candidate.item.def_id)), *feature)
1920                    }),
1921                );
1922                lint
1923            }
1924        }
1925
1926        if self.unstable_candidates.is_empty() {
1927            return;
1928        }
1929        tcx.emit_node_span_lint(
1930            UNSTABLE_NAME_COLLISIONS,
1931            scope_expr_id,
1932            span,
1933            ItemMaybeBeAddedToStd { this: self, tcx, span },
1934        );
1935    }
1936}
1937
1938impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1939    fn select_trait_candidate_for_diagnostics(
1940        &self,
1941        trait_ref: ty::TraitRef<'tcx>,
1942    ) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
1943        let obligation =
1944            traits::Obligation::new(self.tcx, self.misc(self.span), self.param_env, trait_ref);
1945        let candidate = traits::SelectionContext::new(self).select(&obligation);
1946        if let Ok(Some(traits::ImplSource::UserDefined(impl_source_user_defined_data))) = &candidate
1947            && self.infcx.tcx.do_not_recommend_impl(impl_source_user_defined_data.impl_def_id)
1948        {
1949            return Err(traits::SelectionError::Unimplemented);
1950        }
1951        candidate
1952    }
1953
1954    /// Used for ambiguous method call error reporting. Uses probing that throws away the result internally,
1955    /// so do not use to make a decision that may lead to a successful compilation.
1956    fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource {
1957        match candidate.kind {
1958            InherentImplCandidate { .. } => {
1959                CandidateSource::Impl(candidate.item.container_id(self.tcx))
1960            }
1961            ObjectCandidate(_) | WhereClauseCandidate(_) => {
1962                CandidateSource::Trait(candidate.item.container_id(self.tcx))
1963            }
1964            TraitCandidate { trait_ref, is_ambiguously_imported: _ } => self.probe(|_| {
1965                let trait_ref = self.instantiate_binder_with_fresh_vars(
1966                    self.span,
1967                    BoundRegionConversionTime::FnCall,
1968                    trait_ref,
1969                );
1970                let (xform_self_ty, _) =
1971                    self.xform_self_ty(candidate.item, trait_ref.self_ty(), trait_ref.args);
1972                // Guide the trait selection to show impls that have methods whose type matches
1973                // up with the `self` parameter of the method.
1974                let _ = self.at(&ObligationCause::dummy(), self.param_env).sup(
1975                    DefineOpaqueTypes::Yes,
1976                    xform_self_ty,
1977                    self_ty,
1978                );
1979                match self.select_trait_candidate_for_diagnostics(trait_ref) {
1980                    Ok(Some(traits::ImplSource::UserDefined(ref impl_data))) => {
1981                        // If only a single impl matches, make the error message point
1982                        // to that impl.
1983                        CandidateSource::Impl(impl_data.impl_def_id)
1984                    }
1985                    _ => CandidateSource::Trait(candidate.item.container_id(self.tcx)),
1986                }
1987            }),
1988        }
1989    }
1990
1991    fn candidate_source_from_pick(&self, pick: &Pick<'tcx>) -> CandidateSource {
1992        match pick.kind {
1993            InherentImplPick => CandidateSource::Impl(pick.item.container_id(self.tcx)),
1994            ObjectPick | WhereClausePick(_) | TraitPick { .. } => {
1995                CandidateSource::Trait(pick.item.container_id(self.tcx))
1996            }
1997        }
1998    }
1999
2000    fn consider_probe(
2001        &self,
2002        self_ty: Ty<'tcx>,
2003        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
2004        probe: &Candidate<'tcx>,
2005        possibly_unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
2006    ) -> ProbeResult {
2007        self.probe(|snapshot| {
2008            let outer_universe = self.universe();
2009
2010            let mut result = ProbeResult::Match;
2011            let cause = &self.misc(self.span);
2012            let ocx = ObligationCtxt::new_with_diagnostics(self);
2013
2014            // Subtle: we're not *really* instantiating the current self type while
2015            // probing, but instead fully recompute the autoderef steps once we've got
2016            // a final `Pick`. We can't nicely handle these obligations outside of a probe.
2017            //
2018            // We simply handle them for each candidate here for now. That's kinda scuffed
2019            // and ideally we just put them into the `FnCtxt` right away. We need to consider
2020            // them to deal with defining uses in `method_autoderef_steps`.
2021            if self.next_trait_solver() {
2022                ocx.register_obligations(instantiate_self_ty_obligations.iter().cloned());
2023                let errors = ocx.try_evaluate_obligations();
2024                if !errors.no_errors() {
2025                    {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("unexpected autoderef error {0:?}", errors)));
};unreachable!("unexpected autoderef error {errors:?}");
2026                }
2027            }
2028
2029            let mut trait_predicate = None;
2030            let (mut xform_self_ty, mut xform_ret_ty);
2031
2032            match probe.kind {
2033                InherentImplCandidate { impl_def_id, .. } => {
2034                    let impl_args = self.fresh_args_for_item(self.span, impl_def_id);
2035                    let impl_ty = self
2036                        .tcx
2037                        .type_of(impl_def_id)
2038                        .instantiate(self.tcx, impl_args)
2039                        .skip_norm_wip();
2040                    (xform_self_ty, xform_ret_ty) =
2041                        self.xform_self_ty(probe.item, impl_ty, impl_args);
2042                    xform_self_ty =
2043                        ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2044                    match ocx.relate(cause, self.param_env, self.variance(), self_ty, xform_self_ty)
2045                    {
2046                        Ok(()) => {}
2047                        Err(err) => {
2048                            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:2048",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(2048u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("--> cannot relate self-types {0:?}",
                                                    err) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("--> cannot relate self-types {:?}", err);
2049                            return ProbeResult::NoMatch;
2050                        }
2051                    }
2052                    // FIXME: Weirdly, we normalize the ret ty in this candidate, but no other candidates.
2053                    xform_ret_ty =
2054                        ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_ret_ty));
2055                    // Check whether the impl imposes obligations we have to worry about.
2056                    let impl_def_id = probe.item.container_id(self.tcx);
2057                    let impl_bounds =
2058                        self.tcx.clauses_of(impl_def_id).instantiate(self.tcx, impl_args);
2059                    // Convert the bounds into obligations.
2060                    ocx.register_obligations(traits::predicates_for_generics(
2061                        |idx, span| {
2062                            let code = ObligationCauseCode::WhereClauseInExpr(
2063                                impl_def_id,
2064                                span,
2065                                self.scope_expr_id,
2066                                idx,
2067                            );
2068                            self.cause(self.span, code)
2069                        },
2070                        |clause| ocx.normalize(cause, self.param_env, clause),
2071                        self.param_env,
2072                        impl_bounds,
2073                    ));
2074                }
2075                TraitCandidate { trait_ref: poly_trait_ref, is_ambiguously_imported: _ } => {
2076                    // Some trait methods are excluded for arrays before 2021.
2077                    // (`array.into_iter()` wants a slice iterator for compatibility.)
2078                    if let Some(method_name) = self.method_name {
2079                        if self_ty.is_array() && !method_name.span.at_least_rust_2021() {
2080                            let trait_def = self.tcx.trait_def(poly_trait_ref.def_id());
2081                            if trait_def.skip_array_during_method_dispatch {
2082                                return ProbeResult::NoMatch;
2083                            }
2084                        }
2085
2086                        // Some trait methods are excluded for boxed slices before 2024.
2087                        // (`boxed_slice.into_iter()` wants a slice iterator for compatibility.)
2088                        if self_ty.boxed_ty().is_some_and(Ty::is_slice)
2089                            && !method_name.span.at_least_rust_2024()
2090                        {
2091                            let trait_def = self.tcx.trait_def(poly_trait_ref.def_id());
2092                            if trait_def.skip_boxed_slice_during_method_dispatch {
2093                                return ProbeResult::NoMatch;
2094                            }
2095                        }
2096                    }
2097
2098                    let trait_ref = self.instantiate_binder_with_fresh_vars(
2099                        self.span,
2100                        BoundRegionConversionTime::FnCall,
2101                        poly_trait_ref,
2102                    );
2103                    let trait_ref =
2104                        ocx.normalize(cause, self.param_env, Unnormalized::new_wip(trait_ref));
2105                    (xform_self_ty, xform_ret_ty) =
2106                        self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
2107                    xform_self_ty =
2108                        ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2109                    match self_ty.kind() {
2110                        // HACK: opaque types will match anything for which their bounds hold.
2111                        // Thus we need to prevent them from trying to match the `&_` autoref
2112                        // candidates that get created for `&self` trait methods.
2113                        &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. })
2114                            if !self.next_trait_solver()
2115                                && self.infcx.can_define_opaque_ty(def_id)
2116                                && !xform_self_ty.is_ty_var() =>
2117                        {
2118                            return ProbeResult::NoMatch;
2119                        }
2120                        _ => match ocx.relate(
2121                            cause,
2122                            self.param_env,
2123                            self.variance(),
2124                            self_ty,
2125                            xform_self_ty,
2126                        ) {
2127                            Ok(()) => {}
2128                            Err(err) => {
2129                                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:2129",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(2129u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("--> cannot relate self-types {0:?}",
                                                    err) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("--> cannot relate self-types {:?}", err);
2130                                return ProbeResult::NoMatch;
2131                            }
2132                        },
2133                    }
2134                    let obligation = traits::Obligation::new(
2135                        self.tcx,
2136                        cause.clone(),
2137                        self.param_env,
2138                        ty::Binder::dummy(trait_ref),
2139                    );
2140
2141                    // We only need this hack to deal with fatal overflow in the old solver.
2142                    if self.infcx.next_trait_solver() || self.infcx.predicate_may_hold(&obligation)
2143                    {
2144                        ocx.register_obligation(obligation);
2145                    } else {
2146                        result = ProbeResult::NoMatch;
2147                        if let Ok(Some(candidate)) =
2148                            self.select_trait_candidate_for_diagnostics(trait_ref)
2149                        {
2150                            for nested_obligation in candidate.nested_obligations() {
2151                                if !self.infcx.predicate_may_hold(&nested_obligation) {
2152                                    possibly_unsatisfied_predicates.push((
2153                                        self.deeply_resolve_ignoring_regions(
2154                                            nested_obligation.predicate,
2155                                        ),
2156                                        Some(
2157                                            self.deeply_resolve_ignoring_regions(
2158                                                obligation.predicate,
2159                                            ),
2160                                        ),
2161                                        Some(nested_obligation.cause),
2162                                    ));
2163                                }
2164                            }
2165                        }
2166                    }
2167
2168                    trait_predicate = Some(trait_ref.upcast(self.tcx));
2169                }
2170                ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {
2171                    let trait_ref = self.instantiate_binder_with_fresh_vars(
2172                        self.span,
2173                        BoundRegionConversionTime::FnCall,
2174                        poly_trait_ref,
2175                    );
2176                    (xform_self_ty, xform_ret_ty) =
2177                        self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
2178
2179                    if #[allow(non_exhaustive_omitted_patterns)] match probe.kind {
    WhereClauseCandidate(_) => true,
    _ => false,
}matches!(probe.kind, WhereClauseCandidate(_)) {
2180                        // `WhereClauseCandidate` requires that the self type is a param,
2181                        // because it has special behavior with candidate preference as an
2182                        // inherent pick.
2183                        let ty = ocx.normalize(
2184                            cause,
2185                            self.param_env,
2186                            Unnormalized::new_wip(trait_ref.self_ty()),
2187                        );
2188                        if !#[allow(non_exhaustive_omitted_patterns)] match ty.kind() {
    ty::Param(_) => true,
    _ => false,
}matches!(ty.kind(), ty::Param(_)) {
2189                            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:2189",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(2189u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("--> not a param ty: {0:?}",
                                                    xform_self_ty) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("--> not a param ty: {xform_self_ty:?}");
2190                            return ProbeResult::NoMatch;
2191                        }
2192                    }
2193
2194                    xform_self_ty =
2195                        ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2196                    match ocx.relate(cause, self.param_env, self.variance(), self_ty, xform_self_ty)
2197                    {
2198                        Ok(()) => {}
2199                        Err(err) => {
2200                            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:2200",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(2200u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("--> cannot relate self-types {0:?}",
                                                    err) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("--> cannot relate self-types {:?}", err);
2201                            return ProbeResult::NoMatch;
2202                        }
2203                    }
2204                }
2205            }
2206
2207            // Evaluate those obligations to see if they might possibly hold.
2208            for error in ocx.try_evaluate_obligations() {
2209                result = ProbeResult::NoMatch;
2210                let nested_predicate =
2211                    self.deeply_resolve_ignoring_regions(error.obligation.predicate);
2212                if let Some(trait_predicate) = trait_predicate
2213                    && nested_predicate == self.deeply_resolve_ignoring_regions(trait_predicate)
2214                {
2215                    // Don't report possibly unsatisfied predicates if the root
2216                    // trait obligation from a `TraitCandidate` is unsatisfied.
2217                    // That just means the candidate doesn't hold.
2218                } else {
2219                    possibly_unsatisfied_predicates.push((
2220                        nested_predicate,
2221                        Some(self.deeply_resolve_ignoring_regions(error.root_obligation.predicate))
2222                            .filter(|root_predicate| *root_predicate != nested_predicate),
2223                        Some(error.obligation.cause),
2224                    ));
2225                }
2226            }
2227
2228            if let ProbeResult::Match = result
2229                && let Some(return_ty) = self.return_type
2230                && let Some(mut xform_ret_ty) = xform_ret_ty
2231            {
2232                // `xform_ret_ty` has only been normalized for `InherentImplCandidate`.
2233                // We don't normalize the other candidates for perf/backwards-compat reasons...
2234                // but `self.return_type` is only set on the diagnostic-path, so we
2235                // should be okay doing it here.
2236                if !#[allow(non_exhaustive_omitted_patterns)] match probe.kind {
    InherentImplCandidate { .. } => true,
    _ => false,
}matches!(probe.kind, InherentImplCandidate { .. }) {
2237                    xform_ret_ty =
2238                        ocx.normalize(&cause, self.param_env, Unnormalized::new_wip(xform_ret_ty));
2239                }
2240
2241                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:2241",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(2241u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("comparing return_ty {0:?} with xform ret ty {1:?}",
                                                    return_ty, xform_ret_ty) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("comparing return_ty {:?} with xform ret ty {:?}", return_ty, xform_ret_ty);
2242                match ocx.relate(cause, self.param_env, self.variance(), xform_ret_ty, return_ty) {
2243                    Ok(()) => {}
2244                    Err(_) => {
2245                        result = ProbeResult::BadReturnType;
2246                    }
2247                }
2248
2249                // Evaluate those obligations to see if they might possibly hold.
2250                for error in ocx.try_evaluate_obligations() {
2251                    result = ProbeResult::NoMatch;
2252                    possibly_unsatisfied_predicates.push((
2253                        error.obligation.predicate,
2254                        Some(error.root_obligation.predicate)
2255                            .filter(|predicate| *predicate != error.obligation.predicate),
2256                        Some(error.root_obligation.cause),
2257                    ));
2258                }
2259            }
2260
2261            if self.infcx.next_trait_solver() {
2262                if self.should_reject_candidate_due_to_opaque_treated_as_rigid(trait_predicate) {
2263                    result = ProbeResult::NoMatch;
2264                }
2265            }
2266
2267            // Previously, method probe used `evaluate_predicate` to determine if a predicate
2268            // was impossible to satisfy. This did a leak check, so we must also do a leak
2269            // check here to prevent backwards-incompatible ambiguity being introduced. See
2270            // `tests/ui/methods/leak-check-disquality.rs` for a simple example of when this
2271            // may happen.
2272            if let Err(_) = self.leak_check(outer_universe, Some(snapshot)) {
2273                result = ProbeResult::NoMatch;
2274            }
2275
2276            result
2277        })
2278    }
2279
2280    /// Trait candidates for not-yet-defined opaque types are a somewhat hacky.
2281    ///
2282    /// We want to only accept trait methods if they were hold even if the
2283    /// opaque types were rigid. To handle this, we both check that for trait
2284    /// candidates the goal were to hold even when treating opaques as rigid,
2285    /// see [OpaqueTypesJank](rustc_trait_selection::solve::OpaqueTypesJank).
2286    ///
2287    /// We also check that all opaque types encountered as self types in the
2288    /// autoderef chain don't get constrained when applying the candidate.
2289    /// Importantly, this also handles calling methods taking `&self` on
2290    /// `impl Trait` to reject the "by-self" candidate.
2291    ///
2292    /// This needs to happen at the end of `consider_probe` as we need to take
2293    /// all the constraints from that into account.
2294    {}
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("should_reject_candidate_due_to_opaque_treated_as_rigid",
                                "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                ::tracing_core::__macro_support::Option::Some(2294u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("trait_predicate")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("trait_predicate");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_predicate)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return: bool = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if let Some(predicate) = trait_predicate {
                            let goal = Goal { param_env: self.param_env, predicate };
                            if !self.infcx.goal_may_hold_opaque_types_jank(goal) {
                                return true;
                            }
                        }
                        for step in self.steps {
                            if step.self_ty_is_opaque {
                                {
                                    use ::tracing::__macro_support::Callsite as _;
                                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                        {
                                            static META: ::tracing::Metadata<'static> =
                                                {
                                                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:2321",
                                                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                                        ::tracing_core::__macro_support::Option::Some(2321u32),
                                                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                                        ::tracing_core::field::FieldSet::new(&["message",
                                                                        {
                                                                            const NAME:
                                                                                ::tracing::__macro_support::FieldName<{
                                                                                    ::tracing::__macro_support::FieldName::len("step.autoderefs")
                                                                                }> =
                                                                                ::tracing::__macro_support::FieldName::new("step.autoderefs");
                                                                            NAME.as_str()
                                                                        },
                                                                        {
                                                                            const NAME:
                                                                                ::tracing::__macro_support::FieldName<{
                                                                                    ::tracing::__macro_support::FieldName::len("step.self_ty")
                                                                                }> =
                                                                                ::tracing::__macro_support::FieldName::new("step.self_ty");
                                                                            NAME.as_str()
                                                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                        ::tracing::metadata::Kind::EVENT)
                                                };
                                            ::tracing::callsite::DefaultCallsite::new(&META)
                                        };
                                    let enabled =
                                        ::tracing::Level::DEBUG <=
                                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                ::tracing::Level::DEBUG <=
                                                    ::tracing::level_filters::LevelFilter::current() &&
                                            {
                                                let interest = __CALLSITE.interest();
                                                !interest.is_never() &&
                                                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                        interest)
                                            };
                                    if enabled {
                                        (|value_set: ::tracing::field::ValueSet|
                                                    {
                                                        let meta = __CALLSITE.metadata();
                                                        ::tracing::Event::dispatch(meta, &value_set);
                                                        ;
                                                    })({
                                                #[allow(unused_imports)]
                                                use ::tracing::field::{debug, display, Value};
                                                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("self_type_is_opaque")
                                                                            as &dyn ::tracing::field::Value)),
                                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&step.autoderefs)
                                                                            as &dyn ::tracing::field::Value)),
                                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&step.self_ty)
                                                                            as &dyn ::tracing::field::Value))])
                                            });
                                    } else { ; }
                                };
                                let constrained_opaque =
                                    self.probe(|_|
                                            {
                                                let Ok(ok) =
                                                    self.fcx.probe_instantiate_query_response(self.span,
                                                        self.orig_steps_var_values,
                                                        &step.self_ty) else {
                                                        {
                                                            use ::tracing::__macro_support::Callsite as _;
                                                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                                                {
                                                                    static META: ::tracing::Metadata<'static> =
                                                                        {
                                                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:2332",
                                                                                "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                                                                ::tracing_core::__macro_support::Option::Some(2332u32),
                                                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                                                                ::tracing_core::field::FieldSet::new(&["message"],
                                                                                    ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                                                ::tracing::metadata::Kind::EVENT)
                                                                        };
                                                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                                                };
                                                            let enabled =
                                                                ::tracing::Level::DEBUG <=
                                                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                                        ::tracing::Level::DEBUG <=
                                                                            ::tracing::level_filters::LevelFilter::current() &&
                                                                    {
                                                                        let interest = __CALLSITE.interest();
                                                                        !interest.is_never() &&
                                                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                                                interest)
                                                                    };
                                                            if enabled {
                                                                (|value_set: ::tracing::field::ValueSet|
                                                                            {
                                                                                let meta = __CALLSITE.metadata();
                                                                                ::tracing::Event::dispatch(meta, &value_set);
                                                                                ;
                                                                            })({
                                                                        #[allow(unused_imports)]
                                                                        use ::tracing::field::{debug, display, Value};
                                                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("failed to instantiate self_ty")
                                                                                                    as &dyn ::tracing::field::Value))])
                                                                    });
                                                            } else { ; }
                                                        };
                                                        return false;
                                                    };
                                                let ocx = ObligationCtxt::new(self);
                                                let self_ty = ocx.register_infer_ok_obligations(ok);
                                                if !ocx.try_evaluate_obligations().no_errors() {
                                                    {
                                                        use ::tracing::__macro_support::Callsite as _;
                                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                                            {
                                                                static META: ::tracing::Metadata<'static> =
                                                                    {
                                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:2338",
                                                                            "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                                                            ::tracing_core::__macro_support::Option::Some(2338u32),
                                                                            ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                                                            ::tracing_core::field::FieldSet::new(&["message"],
                                                                                ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                                            ::tracing::metadata::Kind::EVENT)
                                                                    };
                                                                ::tracing::callsite::DefaultCallsite::new(&META)
                                                            };
                                                        let enabled =
                                                            ::tracing::Level::DEBUG <=
                                                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                                    ::tracing::Level::DEBUG <=
                                                                        ::tracing::level_filters::LevelFilter::current() &&
                                                                {
                                                                    let interest = __CALLSITE.interest();
                                                                    !interest.is_never() &&
                                                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                                            interest)
                                                                };
                                                        if enabled {
                                                            (|value_set: ::tracing::field::ValueSet|
                                                                        {
                                                                            let meta = __CALLSITE.metadata();
                                                                            ::tracing::Event::dispatch(meta, &value_set);
                                                                            ;
                                                                        })({
                                                                    #[allow(unused_imports)]
                                                                    use ::tracing::field::{debug, display, Value};
                                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("failed to prove instantiate self_ty obligations")
                                                                                                as &dyn ::tracing::field::Value))])
                                                                });
                                                        } else { ; }
                                                    };
                                                    return false;
                                                }
                                                !self.deeply_resolve_ignoring_regions(self_ty).is_ty_var()
                                            });
                                if constrained_opaque {
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:2345",
                                                            "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(2345u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                                            ::tracing_core::field::FieldSet::new(&["message"],
                                                                ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                            ::tracing::metadata::Kind::EVENT)
                                                    };
                                                ::tracing::callsite::DefaultCallsite::new(&META)
                                            };
                                        let enabled =
                                            ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                    ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::LevelFilter::current() &&
                                                {
                                                    let interest = __CALLSITE.interest();
                                                    !interest.is_never() &&
                                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                            interest)
                                                };
                                        if enabled {
                                            (|value_set: ::tracing::field::ValueSet|
                                                        {
                                                            let meta = __CALLSITE.metadata();
                                                            ::tracing::Event::dispatch(meta, &value_set);
                                                            ;
                                                        })({
                                                    #[allow(unused_imports)]
                                                    use ::tracing::field::{debug, display, Value};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("opaque type has been constrained")
                                                                                as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    return true;
                                }
                            }
                        }
                        false
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:2294",
                        "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                        ::tracing_core::__macro_support::Option::Some(2294u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
2295    fn should_reject_candidate_due_to_opaque_treated_as_rigid(
2296        &self,
2297        trait_predicate: Option<ty::Predicate<'tcx>>,
2298    ) -> bool {
2299        // This function is what hacky and doesn't perfectly do what we want it to.
2300        // It's not soundness critical and we should be able to freely improve this
2301        // in the future.
2302        //
2303        // Some concrete edge cases include the fact that `goal_may_hold_opaque_types_jank`
2304        // also fails if there are any constraints opaques which are never used as a self
2305        // type. We also allow where-bounds which are currently ambiguous but end up
2306        // constraining an opaque later on.
2307
2308        // Check whether the trait candidate would not be applicable if the
2309        // opaque type were rigid.
2310        if let Some(predicate) = trait_predicate {
2311            let goal = Goal { param_env: self.param_env, predicate };
2312            if !self.infcx.goal_may_hold_opaque_types_jank(goal) {
2313                return true;
2314            }
2315        }
2316
2317        // Check whether any opaque types in the autoderef chain have been
2318        // constrained.
2319        for step in self.steps {
2320            if step.self_ty_is_opaque {
2321                debug!(?step.autoderefs, ?step.self_ty, "self_type_is_opaque");
2322                let constrained_opaque = self.probe(|_| {
2323                    // If we fail to instantiate the self type of this
2324                    // step, this part of the deref-chain is no longer
2325                    // reachable. In this case we don't care about opaque
2326                    // types there.
2327                    let Ok(ok) = self.fcx.probe_instantiate_query_response(
2328                        self.span,
2329                        self.orig_steps_var_values,
2330                        &step.self_ty,
2331                    ) else {
2332                        debug!("failed to instantiate self_ty");
2333                        return false;
2334                    };
2335                    let ocx = ObligationCtxt::new(self);
2336                    let self_ty = ocx.register_infer_ok_obligations(ok);
2337                    if !ocx.try_evaluate_obligations().no_errors() {
2338                        debug!("failed to prove instantiate self_ty obligations");
2339                        return false;
2340                    }
2341
2342                    !self.deeply_resolve_ignoring_regions(self_ty).is_ty_var()
2343                });
2344                if constrained_opaque {
2345                    debug!("opaque type has been constrained");
2346                    return true;
2347                }
2348            }
2349        }
2350
2351        false
2352    }
2353
2354    /// Sometimes we get in a situation where we have multiple probes that are all impls of the
2355    /// same trait, but we don't know which impl to use. In this case, since in all cases the
2356    /// external interface of the method can be determined from the trait, it's ok not to decide.
2357    /// We can basically just collapse all of the probes for various impls into one where-clause
2358    /// probe. This will result in a pending obligation so when more type-info is available we can
2359    /// make the final decision.
2360    ///
2361    /// Example (`tests/ui/methods/method-two-trait-defer-resolution-1.rs`):
2362    ///
2363    /// ```ignore (illustrative)
2364    /// trait Foo { ... }
2365    /// impl Foo for Vec<i32> { ... }
2366    /// impl Foo for Vec<usize> { ... }
2367    /// ```
2368    ///
2369    /// Now imagine the receiver is `Vec<_>`. It doesn't really matter at this time which impl we
2370    /// use, so it's ok to just commit to "using the method from the trait Foo".
2371    fn collapse_candidates_to_trait_pick(
2372        &self,
2373        self_ty: Ty<'tcx>,
2374        probes: &[(&Candidate<'tcx>, ProbeResult)],
2375    ) -> Option<Pick<'tcx>> {
2376        // Do all probes correspond to the same trait?
2377        let container = probes[0].0.item.trait_container(self.tcx)?;
2378        for (p, _) in &probes[1..] {
2379            let p_container = p.item.trait_container(self.tcx)?;
2380            if p_container != container {
2381                return None;
2382            }
2383        }
2384
2385        // We try and find the ambiguous candidate in order to report the pick as ambiguous.
2386        let ambiguous_candidate = probes.iter().find_map(|(p, _)| match p.kind {
2387            TraitCandidate { is_ambiguously_imported: true, .. } => Some(p),
2388            _ => None,
2389        });
2390
2391        // If there isn't any, then we just use the first probe.
2392        let (is_ambiguously_imported, candidate) =
2393            ambiguous_candidate.map(|c| (true, *c)).unwrap_or_else(|| (false, probes[0].0));
2394
2395        // FIXME: check the return type here somehow.
2396        // If so, just use this trait and call it a day.
2397        Some(Pick {
2398            item: candidate.item,
2399            kind: TraitPick { is_ambiguously_imported },
2400            import_ids: candidate.import_ids,
2401            autoderefs: 0,
2402            autoref_or_ptr_adjustment: None,
2403            self_ty,
2404            unstable_candidates: ::alloc::vec::Vec::new()vec![],
2405            receiver_steps: None,
2406            shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2407        })
2408    }
2409
2410    /// Much like `collapse_candidates_to_trait_pick`, this method allows us to collapse
2411    /// multiple conflicting picks if there is one pick whose trait container is a subtrait
2412    /// of the trait containers of all of the other picks.
2413    ///
2414    /// This is the method-probe analogue of
2415    /// `rustc_hir_analysis::hir_ty_lowering::HirTyLowerer::collapse_candidates_to_subtrait_pick`;
2416    /// keep both implementations in sync.
2417    ///
2418    /// This implements RFC #3624.
2419    fn collapse_candidates_to_subtrait_pick(
2420        &self,
2421        self_ty: Ty<'tcx>,
2422        probes: &[(&Candidate<'tcx>, ProbeResult)],
2423    ) -> Option<Pick<'tcx>> {
2424        let mut child_candidate = probes[0].0;
2425        let mut child_trait = child_candidate.item.trait_container(self.tcx)?;
2426        let mut supertraits: SsoHashSet<_> = supertrait_def_ids(self.tcx, child_trait).collect();
2427
2428        let mut remaining_candidates: Vec<_> = probes[1..].iter().map(|&(p, _)| p).collect();
2429        while !remaining_candidates.is_empty() {
2430            let mut made_progress = false;
2431            let mut next_round = ::alloc::vec::Vec::new()vec![];
2432
2433            for remaining_candidate in remaining_candidates {
2434                let remaining_trait = remaining_candidate.item.trait_container(self.tcx)?;
2435                if supertraits.contains(&remaining_trait) {
2436                    made_progress = true;
2437                    continue;
2438                }
2439
2440                // This candidate is not a supertrait of the `child_trait`.
2441                // Check if it's a subtrait of the `child_trait`, instead.
2442                // If it is, then it must have been a subtrait of every
2443                // other pick we've eliminated at this point. It will
2444                // take over at this point.
2445                let remaining_trait_supertraits: SsoHashSet<_> =
2446                    supertrait_def_ids(self.tcx, remaining_trait).collect();
2447                if remaining_trait_supertraits.contains(&child_trait) {
2448                    child_candidate = remaining_candidate;
2449                    child_trait = remaining_trait;
2450                    supertraits = remaining_trait_supertraits;
2451                    made_progress = true;
2452                    continue;
2453                }
2454
2455                // Neither `child_trait` or the current candidate are
2456                // supertraits of each other.
2457                // Don't bail here, since we may be comparing two supertraits
2458                // of a common subtrait. These two supertraits won't be related
2459                // at all, but we will pick them up next round when we find their
2460                // child as we continue iterating in this round.
2461                next_round.push(remaining_candidate);
2462            }
2463
2464            if made_progress {
2465                // If we've made progress, iterate again.
2466                remaining_candidates = next_round;
2467            } else {
2468                // Otherwise, we must have at least two candidates which
2469                // are not related to each other at all.
2470                return None;
2471            }
2472        }
2473
2474        let is_ambiguously_imported = match child_candidate.kind {
2475            TraitCandidate { is_ambiguously_imported, .. } => is_ambiguously_imported,
2476            _ => false,
2477        };
2478
2479        Some(Pick {
2480            item: child_candidate.item,
2481            kind: TraitPick { is_ambiguously_imported },
2482            import_ids: child_candidate.import_ids,
2483            autoderefs: 0,
2484            autoref_or_ptr_adjustment: None,
2485            self_ty,
2486            unstable_candidates: ::alloc::vec::Vec::new()vec![],
2487            shadowed_candidates: probes
2488                .iter()
2489                .map(|(c, _)| c.item)
2490                .filter(|item| item.def_id != child_candidate.item.def_id)
2491                .collect(),
2492            receiver_steps: None,
2493        })
2494    }
2495
2496    /// Similarly to `probe_for_return_type`, this method attempts to find the best matching
2497    /// candidate method where the method name may have been misspelled. Similarly to other
2498    /// edit distance based suggestions, we provide at most one such suggestion.
2499    {}
#[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("probe_for_similar_candidate",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2499u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::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_all(&[]) })
                } 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<Option<ty::AssocItem>, MethodError<'tcx>> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:2503",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2503u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("probing for method names similar to {0:?}",
                                                                self.method_name) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            self.probe(|_|
                    {
                        let mut pcx =
                            ProbeContext::new(self.fcx, self.span, self.mode,
                                self.method_name, self.return_type,
                                self.orig_steps_var_values, self.steps, self.scope_expr_id,
                                IsSuggestion(true));
                        pcx.allow_similar_names = true;
                        pcx.assemble_inherent_candidates();
                        pcx.assemble_extension_candidates_for_all_traits();
                        let method_names = pcx.candidate_method_names(|_| true);
                        pcx.allow_similar_names = false;
                        let applicable_close_candidates: Vec<ty::AssocItem> =
                            method_names.iter().filter_map(|&method_name|
                                        {
                                            pcx.reset();
                                            pcx.method_name = Some(method_name);
                                            pcx.assemble_inherent_candidates();
                                            pcx.assemble_extension_candidates_for_all_traits();
                                            pcx.pick_core(&mut Vec::new()).and_then(|pick|
                                                        pick.ok()).map(|pick| pick.item)
                                        }).collect();
                        if applicable_close_candidates.is_empty() {
                            Ok(None)
                        } else {
                            let best_name =
                                applicable_close_candidates.iter().find(|cand|
                                                self.matches_by_doc_alias(cand.def_id)).map(|cand|
                                            cand.name()).or_else(||
                                        {
                                            let names =
                                                applicable_close_candidates.iter().map(|cand|
                                                            cand.name()).collect::<Vec<Symbol>>();
                                            find_best_match_for_name_with_substrings(&names,
                                                self.method_name.unwrap().name, None)
                                        });
                            Ok(best_name.and_then(|best_name|
                                        {
                                            applicable_close_candidates.into_iter().find(|method|
                                                    method.name() == best_name)
                                        }))
                        }
                    })
        }
    }
}#[instrument(level = "debug", skip(self))]
2500    pub(crate) fn probe_for_similar_candidate(
2501        &mut self,
2502    ) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
2503        debug!("probing for method names similar to {:?}", self.method_name);
2504
2505        self.probe(|_| {
2506            let mut pcx = ProbeContext::new(
2507                self.fcx,
2508                self.span,
2509                self.mode,
2510                self.method_name,
2511                self.return_type,
2512                self.orig_steps_var_values,
2513                self.steps,
2514                self.scope_expr_id,
2515                IsSuggestion(true),
2516            );
2517            pcx.allow_similar_names = true;
2518            pcx.assemble_inherent_candidates();
2519            pcx.assemble_extension_candidates_for_all_traits();
2520
2521            let method_names = pcx.candidate_method_names(|_| true);
2522            pcx.allow_similar_names = false;
2523            let applicable_close_candidates: Vec<ty::AssocItem> = method_names
2524                .iter()
2525                .filter_map(|&method_name| {
2526                    pcx.reset();
2527                    pcx.method_name = Some(method_name);
2528                    pcx.assemble_inherent_candidates();
2529                    pcx.assemble_extension_candidates_for_all_traits();
2530                    pcx.pick_core(&mut Vec::new()).and_then(|pick| pick.ok()).map(|pick| pick.item)
2531                })
2532                .collect();
2533
2534            if applicable_close_candidates.is_empty() {
2535                Ok(None)
2536            } else {
2537                let best_name = applicable_close_candidates
2538                    .iter()
2539                    .find(|cand| self.matches_by_doc_alias(cand.def_id))
2540                    .map(|cand| cand.name())
2541                    .or_else(|| {
2542                        let names = applicable_close_candidates
2543                            .iter()
2544                            .map(|cand| cand.name())
2545                            .collect::<Vec<Symbol>>();
2546                        find_best_match_for_name_with_substrings(
2547                            &names,
2548                            self.method_name.unwrap().name,
2549                            None,
2550                        )
2551                    });
2552                Ok(best_name.and_then(|best_name| {
2553                    applicable_close_candidates
2554                        .into_iter()
2555                        .find(|method| method.name() == best_name)
2556                }))
2557            }
2558        })
2559    }
2560
2561    ///////////////////////////////////////////////////////////////////////////
2562    // MISCELLANY
2563    fn has_applicable_self(&self, item: &ty::AssocItem) -> bool {
2564        // "Fast track" -- check for usage of sugar when in method call
2565        // mode.
2566        //
2567        // In Path mode (i.e., resolving a value like `T::next`), consider any
2568        // associated value (i.e., methods, constants) but not types.
2569        match self.mode {
2570            Mode::MethodCall => item.is_method(),
2571            Mode::Path => match item.kind {
2572                ty::AssocKind::Type { .. } => false,
2573                ty::AssocKind::Fn { .. } | ty::AssocKind::Const { .. } => true,
2574            },
2575        }
2576        // FIXME -- check for types that deref to `Self`,
2577        // like `Rc<Self>` and so on.
2578        //
2579        // Note also that the current code will break if this type
2580        // includes any of the type parameters defined on the method
2581        // -- but this could be overcome.
2582    }
2583
2584    fn record_static_candidate(&self, source: CandidateSource) {
2585        self.static_candidates.borrow_mut().push(source);
2586    }
2587
2588    {}
#[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("xform_self_ty",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2588u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("item")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("item");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("impl_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("impl_ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("args")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("args");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: (Ty<'tcx>, Option<Ty<'tcx>>) =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            if item.is_fn() && self.mode == Mode::MethodCall {
                let sig = self.xform_method_sig(item.def_id, args);
                (self.self_ty_override.unwrap_or(sig.inputs()[0]),
                    Some(sig.output()))
            } else { (impl_ty, None) }
        }
    }
}#[instrument(level = "debug", skip(self))]
2589    fn xform_self_ty(
2590        &self,
2591        item: ty::AssocItem,
2592        impl_ty: Ty<'tcx>,
2593        args: GenericArgsRef<'tcx>,
2594    ) -> (Ty<'tcx>, Option<Ty<'tcx>>) {
2595        if item.is_fn() && self.mode == Mode::MethodCall {
2596            let sig = self.xform_method_sig(item.def_id, args);
2597            (self.self_ty_override.unwrap_or(sig.inputs()[0]), Some(sig.output()))
2598        } else {
2599            (impl_ty, None)
2600        }
2601    }
2602
2603    {}
#[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("xform_method_sig",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2603u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("method")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("method");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("args")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("args");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&method)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: ty::FnSig<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let fn_sig = self.tcx.fn_sig(method);
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs:2606",
                                    "rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/method/probe.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2606u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("fn_sig")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("fn_sig");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_sig)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            if !!args.has_escaping_bound_vars() {
                ::core::panicking::panic("assertion failed: !args.has_escaping_bound_vars()")
            };
            let generics = self.tcx.generics_of(method);
            {
                match (&args.len(), &generics.parent_count) {
                    (left_val, right_val) => {
                        if !(*left_val == *right_val) {
                            let kind = ::core::panicking::AssertKind::Eq;
                            ::core::panicking::assert_failed(kind, &*left_val,
                                &*right_val, ::core::option::Option::None);
                        }
                    }
                }
            };
            let xform_fn_sig =
                if generics.is_own_empty() {
                    fn_sig.instantiate(self.tcx, args).skip_norm_wip()
                } else {
                    let args =
                        GenericArgs::for_item(self.tcx, method,
                            |param, _|
                                {
                                    let i = param.index as usize;
                                    if i < args.len() {
                                        args[i]
                                    } else {
                                        match param.kind {
                                            GenericParamDefKind::Lifetime => {
                                                self.tcx.lifetimes.re_erased.into()
                                            }
                                            GenericParamDefKind::Type { .. } |
                                                GenericParamDefKind::Const { .. } => {
                                                self.var_for_def(self.span, param)
                                            }
                                        }
                                    }
                                });
                    fn_sig.instantiate(self.tcx, args).skip_norm_wip()
                };
            self.tcx.instantiate_bound_regions_with_erased(xform_fn_sig)
        }
    }
}#[instrument(level = "debug", skip(self))]
2604    fn xform_method_sig(&self, method: DefId, args: GenericArgsRef<'tcx>) -> ty::FnSig<'tcx> {
2605        let fn_sig = self.tcx.fn_sig(method);
2606        debug!(?fn_sig);
2607
2608        assert!(!args.has_escaping_bound_vars());
2609
2610        // It is possible for type parameters or early-bound lifetimes
2611        // to appear in the signature of `self`. The generic parameters
2612        // we are given do not include type/lifetime parameters for the
2613        // method yet. So create fresh variables here for those too,
2614        // if there are any.
2615        let generics = self.tcx.generics_of(method);
2616        assert_eq!(args.len(), generics.parent_count);
2617
2618        let xform_fn_sig = if generics.is_own_empty() {
2619            fn_sig.instantiate(self.tcx, args).skip_norm_wip()
2620        } else {
2621            let args = GenericArgs::for_item(self.tcx, method, |param, _| {
2622                let i = param.index as usize;
2623                if i < args.len() {
2624                    args[i]
2625                } else {
2626                    match param.kind {
2627                        GenericParamDefKind::Lifetime => {
2628                            // In general, during probe we erase regions.
2629                            self.tcx.lifetimes.re_erased.into()
2630                        }
2631                        GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
2632                            self.var_for_def(self.span, param)
2633                        }
2634                    }
2635                }
2636            });
2637            fn_sig.instantiate(self.tcx, args).skip_norm_wip()
2638        };
2639
2640        self.tcx.instantiate_bound_regions_with_erased(xform_fn_sig)
2641    }
2642
2643    /// Determine if the given associated item type is relevant in the current context.
2644    fn is_relevant_kind_for_mode(&self, kind: ty::AssocKind) -> bool {
2645        match (self.mode, kind) {
2646            (Mode::MethodCall, ty::AssocKind::Fn { .. }) => true,
2647            (Mode::Path, ty::AssocKind::Const { .. } | ty::AssocKind::Fn { .. }) => true,
2648            _ => false,
2649        }
2650    }
2651
2652    /// Determine if the associated item with the given DefId matches
2653    /// the desired name via a doc alias or rustc_confusables
2654    fn matches_by_doc_alias(&self, def_id: DefId) -> bool {
2655        let Some(method) = self.method_name else {
2656            return false;
2657        };
2658
2659        if let Some(d) = {
    {
        'done:
            {
            for i in ::rustc_attr_ir::HasAttrs::get_attrs(def_id, &self.tcx) {
                #[allow(unused_imports)]
                use ::rustc_attr_ir::AttributeKind::*;
                let i: &::rustc_attr_ir::Attribute = i;
                match i {
                    ::rustc_attr_ir::Attribute::Parsed(Doc(d)) => {
                        break 'done Some(d);
                    }
                    ::rustc_attr_ir::Attribute::Unparsed(..) =>
                        {}
                        #[deny(unreachable_patterns)]
                        _ => {}
                }
            }
            None
        }
    }
}find_attr!(self.tcx, def_id, Doc(d) => d)
2660            && d.aliases.contains_key(&method.name)
2661        {
2662            return true;
2663        }
2664
2665        if let Some(confusables) =
2666            {
    {
        'done:
            {
            for i in ::rustc_attr_ir::HasAttrs::get_attrs(def_id, &self.tcx) {
                #[allow(unused_imports)]
                use ::rustc_attr_ir::AttributeKind::*;
                let i: &::rustc_attr_ir::Attribute = i;
                match i {
                    ::rustc_attr_ir::Attribute::Parsed(RustcConfusables {
                        confusables }) => {
                        break 'done Some(confusables);
                    }
                    ::rustc_attr_ir::Attribute::Unparsed(..) =>
                        {}
                        #[deny(unreachable_patterns)]
                        _ => {}
                }
            }
            None
        }
    }
}find_attr!(self.tcx, def_id, RustcConfusables{ confusables } => confusables)
2667            && confusables.contains(&method.name)
2668        {
2669            return true;
2670        }
2671
2672        false
2673    }
2674
2675    /// Finds the method with the appropriate name (or return type, as the case may be). If
2676    /// `allow_similar_names` is set, find methods with close-matching names.
2677    // The length of the returned iterator is nearly always 0 or 1 and this
2678    // method is fairly hot.
2679    fn impl_or_trait_item(&self, def_id: DefId) -> SmallVec<[ty::AssocItem; 1]> {
2680        if let Some(name) = self.method_name {
2681            if self.allow_similar_names {
2682                let max_dist = max(name.as_str().len(), 3) / 3;
2683                self.tcx
2684                    .associated_items(def_id)
2685                    .in_definition_order()
2686                    .filter(|x| {
2687                        if !self.is_relevant_kind_for_mode(x.kind) {
2688                            return false;
2689                        }
2690                        if let Some(d) = edit_distance_with_substrings(
2691                            name.as_str(),
2692                            x.name().as_str(),
2693                            max_dist,
2694                        ) {
2695                            return d > 0;
2696                        }
2697                        self.matches_by_doc_alias(x.def_id)
2698                    })
2699                    .copied()
2700                    .collect()
2701            } else {
2702                self.fcx
2703                    .associated_value(def_id, name)
2704                    .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2705                    .map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
2706            }
2707        } else {
2708            self.tcx
2709                .associated_items(def_id)
2710                .in_definition_order()
2711                .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2712                .copied()
2713                .collect()
2714        }
2715    }
2716}
2717
2718impl<'tcx> Candidate<'tcx> {
2719    fn to_unadjusted_pick(
2720        &self,
2721        self_ty: Ty<'tcx>,
2722        unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
2723    ) -> Pick<'tcx> {
2724        Pick {
2725            item: self.item,
2726            kind: match self.kind {
2727                InherentImplCandidate { .. } => InherentImplPick,
2728                ObjectCandidate(_) => ObjectPick,
2729                TraitCandidate { is_ambiguously_imported, .. } => {
2730                    TraitPick { is_ambiguously_imported }
2731                }
2732                WhereClauseCandidate(trait_ref) => {
2733                    // Only trait derived from where-clauses should
2734                    // appear here, so they should not contain any
2735                    // inference variables or other artifacts. This
2736                    // means they are safe to put into the
2737                    // `WhereClausePick`.
2738                    if !(!trait_ref.skip_binder().args.has_infer() &&
            !trait_ref.skip_binder().args.has_placeholders()) {
    ::core::panicking::panic("assertion failed: !trait_ref.skip_binder().args.has_infer() &&\n    !trait_ref.skip_binder().args.has_placeholders()")
};assert!(
2739                        !trait_ref.skip_binder().args.has_infer()
2740                            && !trait_ref.skip_binder().args.has_placeholders()
2741                    );
2742
2743                    WhereClausePick(trait_ref)
2744                }
2745            },
2746            import_ids: self.import_ids,
2747            autoderefs: 0,
2748            autoref_or_ptr_adjustment: None,
2749            self_ty,
2750            unstable_candidates,
2751            receiver_steps: match self.kind {
2752                InherentImplCandidate { receiver_steps, .. } => Some(receiver_steps),
2753                _ => None,
2754            },
2755            shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2756        }
2757    }
2758}