Skip to main content

rustc_hir_typeck/method/
mod.rs

1//! Method lookup: the secret sauce of Rust. See the [rustc dev guide] for more information.
2//!
3//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir-typeck/method-lookup.html
4
5pub(crate) mod confirm;
6mod prelude_edition_lints;
7pub(crate) mod probe;
8mod suggest;
9
10use rustc_errors::{Applicability, Diag, DiagMessage};
11use rustc_hir as hir;
12use rustc_hir::def::{CtorOf, DefKind, Namespace};
13use rustc_hir::def_id::DefId;
14use rustc_infer::infer::{BoundRegionConversionTime, InferOk};
15use rustc_infer::traits::PredicateObligations;
16use rustc_middle::traits::ObligationCause;
17use rustc_middle::ty::{
18    self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TypeVisitableExt, Unnormalized,
19};
20use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, bug, span_bug};
21use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
22use rustc_trait_selection::traits::{self, NormalizeExt};
23use tracing::{debug, instrument};
24
25pub(crate) use self::MethodError::*;
26use self::probe::{IsSuggestion, ProbeScope};
27use crate::FnCtxt;
28use crate::method::probe::UnsatisfiedPredicates;
29
30#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for MethodCallee<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for MethodCallee<'tcx> {
    #[inline]
    fn clone(&self) -> MethodCallee<'tcx> {
        let _: ::core::clone::AssertParamIsClone<DefId>;
        let _: ::core::clone::AssertParamIsClone<GenericArgsRef<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<ty::FnSig<'tcx>>;
        *self
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for MethodCallee<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for MethodCallee<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f, "MethodCallee",
            "def_id", &self.def_id, "args", &self.args, "sig", &&self.sig)
    }
}Debug)]
31pub(crate) struct MethodCallee<'tcx> {
32    /// Impl method ID, for inherent methods, or trait method ID, otherwise.
33    pub def_id: DefId,
34    pub args: GenericArgsRef<'tcx>,
35
36    /// Instantiated method signature, i.e., it has been
37    /// instantiated, normalized, and has had late-bound
38    /// lifetimes replaced with inference variables.
39    pub sig: ty::FnSig<'tcx>,
40}
41
42#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for MethodError<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            MethodError::NoMatch(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "NoMatch", &__self_0),
            MethodError::Ambiguity(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "Ambiguity", &__self_0),
            MethodError::PrivateMatch(__self_0, __self_1, __self_2) =>
                ::core::fmt::Formatter::debug_tuple_field3_finish(f,
                    "PrivateMatch", __self_0, __self_1, &__self_2),
            MethodError::IllegalSizedBound {
                candidates: __self_0,
                needs_mut: __self_1,
                bound_span: __self_2,
                self_expr: __self_3 } =>
                ::core::fmt::Formatter::debug_struct_field4_finish(f,
                    "IllegalSizedBound", "candidates", __self_0, "needs_mut",
                    __self_1, "bound_span", __self_2, "self_expr", &__self_3),
            MethodError::BadReturnType =>
                ::core::fmt::Formatter::write_str(f, "BadReturnType"),
            MethodError::ErrorReported(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "ErrorReported", &__self_0),
        }
    }
}Debug)]
43pub(crate) enum MethodError<'tcx> {
44    /// Did not find an applicable method, but we did find various near-misses that may work.
45    NoMatch(NoMatchData<'tcx>),
46
47    /// Multiple methods might apply.
48    Ambiguity(Vec<CandidateSource>),
49
50    /// Found an applicable method, but it is not visible. The third argument contains a list of
51    /// not-in-scope traits which may work.
52    PrivateMatch(DefKind, DefId, Vec<DefId>),
53
54    /// Found a `Self: Sized` bound where `Self` is a trait object.
55    IllegalSizedBound {
56        candidates: Vec<DefId>,
57        needs_mut: bool,
58        bound_span: Span,
59        self_expr: &'tcx hir::Expr<'tcx>,
60    },
61
62    /// Found a match, but the return type is wrong
63    BadReturnType,
64
65    /// Error has already been emitted, no need to emit another one.
66    ErrorReported(ErrorGuaranteed),
67}
68
69// Contains a list of static methods that may apply, a list of unsatisfied trait predicates which
70// could lead to matches if satisfied, and a list of not-in-scope traits which may work.
71#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for NoMatchData<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field5_finish(f, "NoMatchData",
            "static_candidates", &self.static_candidates,
            "unsatisfied_predicates", &self.unsatisfied_predicates,
            "out_of_scope_traits", &self.out_of_scope_traits,
            "similar_candidate", &self.similar_candidate, "mode", &&self.mode)
    }
}Debug)]
72pub(crate) struct NoMatchData<'tcx> {
73    pub static_candidates: Vec<CandidateSource>,
74    pub unsatisfied_predicates: UnsatisfiedPredicates<'tcx>,
75    pub out_of_scope_traits: Vec<DefId>,
76    pub similar_candidate: Option<ty::AssocItem>,
77    pub mode: probe::Mode,
78}
79
80// A pared down enum describing just the places from which a method
81// candidate can arise. Used for error reporting only.
82#[derive(#[automatically_derived]
impl ::core::marker::Copy for CandidateSource { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for CandidateSource { }
#[automatically_derived]
impl ::core::clone::Clone for CandidateSource {
    #[inline]
    fn clone(&self) -> CandidateSource {
        let _: ::core::clone::AssertParamIsClone<DefId>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for CandidateSource {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            CandidateSource::Impl(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Impl",
                    &__self_0),
            CandidateSource::Trait(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Trait",
                    &__self_0),
        }
    }
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for CandidateSource {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<DefId>;
    }
}Eq, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for CandidateSource { }
#[automatically_derived]
impl ::core::cmp::PartialEq for CandidateSource {
    #[inline]
    fn eq(&self, other: &CandidateSource) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (CandidateSource::Impl(__self_0),
                    CandidateSource::Impl(__arg1_0)) => __self_0 == __arg1_0,
                (CandidateSource::Trait(__self_0),
                    CandidateSource::Trait(__arg1_0)) => __self_0 == __arg1_0,
                _ => unsafe { ::core::intrinsics::unreachable() }
            }
    }
}PartialEq)]
83pub(crate) enum CandidateSource {
84    Impl(DefId),
85    Trait(DefId /* trait id */),
86}
87
88impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
89    /// Determines whether the type `self_ty` supports a visible method named `method_name` or not.
90    {}
#[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("method_exists_for_diagnostic",
                                    "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(90u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("method_name")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("method_name");
                                                        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("call_expr_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("call_expr_id");
                                                        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()
                                                    }], ::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_name)
                                                            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(&call_expr_id)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&return_type)
                                                            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: bool = loop {};
            return __tracing_attr_fake_return;
        }
        {
            match self.probe_for_name(probe::Mode::MethodCall, method_name,
                    return_type, IsSuggestion(true), self_ty, call_expr_id,
                    ProbeScope::TraitsInScope) {
                Ok(pick) => {
                    pick.maybe_emit_unstable_name_collision_hint(self.tcx,
                        method_name.span, call_expr_id);
                    true
                }
                Err(NoMatch(..)) => false,
                Err(Ambiguity(..)) => true,
                Err(PrivateMatch(..)) => false,
                Err(IllegalSizedBound { .. }) => true,
                Err(BadReturnType) => true,
                Err(ErrorReported(_)) => false,
            }
        }
    }
}#[instrument(level = "debug", skip(self))]
91    pub(crate) fn method_exists_for_diagnostic(
92        &self,
93        method_name: Ident,
94        self_ty: Ty<'tcx>,
95        call_expr_id: hir::HirId,
96        return_type: Option<Ty<'tcx>>,
97    ) -> bool {
98        match self.probe_for_name(
99            probe::Mode::MethodCall,
100            method_name,
101            return_type,
102            IsSuggestion(true),
103            self_ty,
104            call_expr_id,
105            ProbeScope::TraitsInScope,
106        ) {
107            Ok(pick) => {
108                pick.maybe_emit_unstable_name_collision_hint(
109                    self.tcx,
110                    method_name.span,
111                    call_expr_id,
112                );
113                true
114            }
115            Err(NoMatch(..)) => false,
116            Err(Ambiguity(..)) => true,
117            Err(PrivateMatch(..)) => false,
118            Err(IllegalSizedBound { .. }) => true,
119            Err(BadReturnType) => true,
120            Err(ErrorReported(_)) => false,
121        }
122    }
123
124    /// Adds a suggestion to call the given method to the provided diagnostic.
125    {}
#[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("suggest_method_call",
                                    "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(125u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("msg")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("msg");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("method_name")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("method_name");
                                                        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("span")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("span");
                                                        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(&msg)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&method_name)
                                                            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(&span)
                                                            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 params =
                self.lookup_probe_for_diagnostic(method_name, self_ty,
                            call_expr, ProbeScope::TraitsInScope,
                            None).map(|pick|
                            {
                                let sig = self.tcx.fn_sig(pick.item.def_id);
                                sig.skip_binder().inputs().skip_binder().len().saturating_sub(1)
                            }).unwrap_or(0);
            let sugg_span = span.unwrap_or(call_expr.span).shrink_to_hi();
            let (suggestion, applicability) =
                (::alloc::__export::must_use({
                            ::alloc::fmt::format(format_args!("({0})",
                                    (0..params).map(|_| "_").collect::<Vec<_>>().join(", ")))
                        }),
                    if params > 0 {
                        Applicability::HasPlaceholders
                    } else { Applicability::MaybeIncorrect });
            err.span_suggestion_verbose(sugg_span, msg, suggestion,
                applicability);
        }
    }
}#[instrument(level = "debug", skip(self, err, call_expr))]
126    pub(crate) fn suggest_method_call(
127        &self,
128        err: &mut Diag<'_>,
129        msg: impl Into<DiagMessage> + std::fmt::Debug,
130        method_name: Ident,
131        self_ty: Ty<'tcx>,
132        call_expr: &hir::Expr<'tcx>,
133        span: Option<Span>,
134    ) {
135        let params = self
136            .lookup_probe_for_diagnostic(
137                method_name,
138                self_ty,
139                call_expr,
140                ProbeScope::TraitsInScope,
141                None,
142            )
143            .map(|pick| {
144                let sig = self.tcx.fn_sig(pick.item.def_id);
145                sig.skip_binder().inputs().skip_binder().len().saturating_sub(1)
146            })
147            .unwrap_or(0);
148
149        // Account for `foo.bar<T>`;
150        let sugg_span = span.unwrap_or(call_expr.span).shrink_to_hi();
151        let (suggestion, applicability) = (
152            format!("({})", (0..params).map(|_| "_").collect::<Vec<_>>().join(", ")),
153            if params > 0 { Applicability::HasPlaceholders } else { Applicability::MaybeIncorrect },
154        );
155
156        err.span_suggestion_verbose(sugg_span, msg, suggestion, applicability);
157    }
158
159    /// Performs method lookup. If lookup is successful, it will return the callee
160    /// and store an appropriate adjustment for the self-expr. In some cases it may
161    /// report an error (e.g., invoking the `drop` method).
162    ///
163    /// # Arguments
164    ///
165    /// Given a method call like `foo.bar::<T1,...Tn>(a, b + 1, ...)`:
166    ///
167    /// * `self`:                  the surrounding `FnCtxt` (!)
168    /// * `self_ty`:               the (unadjusted) type of the self expression (`foo`)
169    /// * `segment`:               the name and generic arguments of the method (`bar::<T1, ...Tn>`)
170    /// * `span`:                  the span for the method call
171    /// * `call_expr`:             the complete method call: (`foo.bar::<T1,...Tn>(...)`)
172    /// * `self_expr`:             the self expression (`foo`)
173    /// * `args`:                  the expressions of the arguments (`a, b + 1, ...`)
174    {}
#[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("lookup_method",
                                    "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(174u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                    ::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("segment")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("segment");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        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("call_expr")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("call_expr");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self_expr")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self_expr");
                                                        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(&self_ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segment)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&call_expr)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_expr)
                                                            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:
                    Result<MethodCallee<'tcx>, MethodError<'tcx>> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let scope =
                if let Some(only_method) = segment.res.opt_def_id() {
                    ProbeScope::Single(only_method, None)
                } else { ProbeScope::TraitsInScope };
            let pick =
                self.lookup_probe(segment.ident, self_ty, call_expr, scope)?;
            self.lint_edition_dependent_dot_call(self_ty, segment, span,
                call_expr, self_expr, &pick, args);
            for &import_id in pick.import_ids {
                {
                    use ::tracing::__macro_support::Callsite as _;
                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                        {
                            static META: ::tracing::Metadata<'static> =
                                {
                                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs:199",
                                        "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                        ::tracing_core::__macro_support::Option::Some(199u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                        ::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!("used_trait_import: {0:?}",
                                                                    import_id) as &dyn ::tracing::field::Value))])
                            });
                    } else { ; }
                };
                self.typeck_results.borrow_mut().used_trait_imports.insert(import_id);
            }
            self.tcx.check_stability(pick.item.def_id, Some(call_expr.hir_id),
                span, None);
            let result =
                self.confirm_method(span, self_expr, call_expr, self_ty,
                    &pick, segment);
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs:206",
                                    "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(206u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                    ::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!("result = {0:?}",
                                                                result) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            if let Some(span) = result.illegal_sized_bound {
                let mut needs_mut = false;
                if let ty::Ref(region, t_type, mutability) = self_ty.kind() {
                    let trait_type =
                        Ty::new_ref(self.tcx, *region, *t_type,
                            mutability.invert());
                    match self.lookup_probe(segment.ident, trait_type,
                            call_expr, ProbeScope::TraitsInScope) {
                        Ok(ref new_pick) if pick.differs_from(new_pick) => {
                            needs_mut =
                                new_pick.self_ty.ref_mutability() !=
                                    self_ty.ref_mutability();
                        }
                        _ => {}
                    }
                }
                let candidates =
                    match self.lookup_probe_for_diagnostic(segment.ident,
                            self_ty, call_expr, ProbeScope::AllTraits, None) {
                        Ok(ref new_pick) if pick.differs_from(new_pick) => {
                            ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                                    [new_pick.item.container_id(self.tcx)]))
                        }
                        Err(Ambiguity(ref sources)) =>
                            sources.iter().filter_map(|source|
                                        {
                                            match *source {
                                                CandidateSource::Impl(def) =>
                                                    Some(self.tcx.impl_trait_id(def)),
                                                CandidateSource::Trait(_) => None,
                                            }
                                        }).collect(),
                        _ => Vec::new(),
                    };
                return Err(IllegalSizedBound {
                            candidates,
                            needs_mut,
                            bound_span: span,
                            self_expr,
                        });
            }
            Ok(result.callee)
        }
    }
}#[instrument(level = "debug", skip(self))]
175    pub(crate) fn lookup_method(
176        &self,
177        self_ty: Ty<'tcx>,
178        segment: &'tcx hir::PathSegment<'tcx>,
179        span: Span,
180        call_expr: &'tcx hir::Expr<'tcx>,
181        self_expr: &'tcx hir::Expr<'tcx>,
182        args: &'tcx [hir::Expr<'tcx>],
183    ) -> Result<MethodCallee<'tcx>, MethodError<'tcx>> {
184        let scope = if let Some(only_method) = segment.res.opt_def_id() {
185            ProbeScope::Single(only_method, None)
186        } else {
187            ProbeScope::TraitsInScope
188        };
189
190        let pick = self.lookup_probe(segment.ident, self_ty, call_expr, scope)?;
191
192        self.lint_edition_dependent_dot_call(
193            self_ty, segment, span, call_expr, self_expr, &pick, args,
194        );
195
196        // NOTE: on the failure path, we also record the possibly-used trait methods
197        // since an unused import warning is kinda distracting from the method error.
198        for &import_id in pick.import_ids {
199            debug!("used_trait_import: {:?}", import_id);
200            self.typeck_results.borrow_mut().used_trait_imports.insert(import_id);
201        }
202
203        self.tcx.check_stability(pick.item.def_id, Some(call_expr.hir_id), span, None);
204
205        let result = self.confirm_method(span, self_expr, call_expr, self_ty, &pick, segment);
206        debug!("result = {:?}", result);
207
208        if let Some(span) = result.illegal_sized_bound {
209            let mut needs_mut = false;
210            if let ty::Ref(region, t_type, mutability) = self_ty.kind() {
211                let trait_type = Ty::new_ref(self.tcx, *region, *t_type, mutability.invert());
212                // We probe again to see if there might be a borrow mutability discrepancy.
213                match self.lookup_probe(
214                    segment.ident,
215                    trait_type,
216                    call_expr,
217                    ProbeScope::TraitsInScope,
218                ) {
219                    Ok(ref new_pick) if pick.differs_from(new_pick) => {
220                        needs_mut = new_pick.self_ty.ref_mutability() != self_ty.ref_mutability();
221                    }
222                    _ => {}
223                }
224            }
225
226            // We probe again, taking all traits into account (not only those in scope).
227            let candidates = match self.lookup_probe_for_diagnostic(
228                segment.ident,
229                self_ty,
230                call_expr,
231                ProbeScope::AllTraits,
232                None,
233            ) {
234                // If we find a different result the caller probably forgot to import a trait.
235                Ok(ref new_pick) if pick.differs_from(new_pick) => {
236                    vec![new_pick.item.container_id(self.tcx)]
237                }
238                Err(Ambiguity(ref sources)) => sources
239                    .iter()
240                    .filter_map(|source| {
241                        match *source {
242                            // Note: this cannot come from an inherent impl,
243                            // because the first probing succeeded.
244                            CandidateSource::Impl(def) => Some(self.tcx.impl_trait_id(def)),
245                            CandidateSource::Trait(_) => None,
246                        }
247                    })
248                    .collect(),
249                _ => Vec::new(),
250            };
251
252            return Err(IllegalSizedBound { candidates, needs_mut, bound_span: span, self_expr });
253        }
254
255        Ok(result.callee)
256    }
257
258    pub(crate) fn lookup_method_for_diagnostic(
259        &self,
260        self_ty: Ty<'tcx>,
261        segment: &hir::PathSegment<'tcx>,
262        span: Span,
263        call_expr: &'tcx hir::Expr<'tcx>,
264        self_expr: &'tcx hir::Expr<'tcx>,
265    ) -> Result<MethodCallee<'tcx>, MethodError<'tcx>> {
266        let pick = self.lookup_probe_for_diagnostic(
267            segment.ident,
268            self_ty,
269            call_expr,
270            ProbeScope::TraitsInScope,
271            None,
272        )?;
273
274        Ok(self
275            .confirm_method_for_diagnostic(span, self_expr, call_expr, self_ty, &pick, segment)
276            .callee)
277    }
278
279    {}
#[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("lookup_probe",
                                    "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(279u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("method_name")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("method_name");
                                                        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")
                                                            }> =
                                                            ::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(&method_name)
                                                            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)
                                                            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: probe::PickResult<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let pick =
                self.probe_for_name(probe::Mode::MethodCall, method_name,
                        None, IsSuggestion(false), self_ty, call_expr.hir_id,
                        scope)?;
            pick.maybe_emit_unstable_name_collision_hint(self.tcx,
                method_name.span, call_expr.hir_id);
            Ok(pick)
        }
    }
}#[instrument(level = "debug", skip(self, call_expr))]
280    pub(crate) fn lookup_probe(
281        &self,
282        method_name: Ident,
283        self_ty: Ty<'tcx>,
284        call_expr: &hir::Expr<'_>,
285        scope: ProbeScope<'tcx>,
286    ) -> probe::PickResult<'tcx> {
287        let pick = self.probe_for_name(
288            probe::Mode::MethodCall,
289            method_name,
290            None,
291            IsSuggestion(false),
292            self_ty,
293            call_expr.hir_id,
294            scope,
295        )?;
296        pick.maybe_emit_unstable_name_collision_hint(self.tcx, method_name.span, call_expr.hir_id);
297        Ok(pick)
298    }
299
300    pub(crate) fn lookup_probe_for_diagnostic(
301        &self,
302        method_name: Ident,
303        self_ty: Ty<'tcx>,
304        call_expr: &hir::Expr<'_>,
305        scope: ProbeScope<'tcx>,
306        return_type: Option<Ty<'tcx>>,
307    ) -> probe::PickResult<'tcx> {
308        let pick = self.probe_for_name(
309            probe::Mode::MethodCall,
310            method_name,
311            return_type,
312            IsSuggestion(true),
313            self_ty,
314            call_expr.hir_id,
315            scope,
316        )?;
317        Ok(pick)
318    }
319}
320
321/// Used by [FnCtxt::lookup_method_for_operator] with `-Znext-solver`.
322///
323/// With `AsRigid` we error on `impl Opaque: NotInItemBounds` while
324/// `AsInfer` just treats it as ambiguous and succeeds. This is necessary
325/// as we want [FnCtxt::check_expr_call] to treat not-yet-defined opaque
326/// types as rigid to support `impl Deref<Target = impl FnOnce()>` and
327/// `Box<impl FnOnce()>`.
328///
329/// We only want to treat opaque types as rigid if we need to eagerly choose
330/// between multiple candidates. We otherwise treat them as ordinary inference
331/// variable to avoid rejecting otherwise correct code.
332#[derive(#[automatically_derived]
impl ::core::fmt::Debug for TreatNotYetDefinedOpaques {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                TreatNotYetDefinedOpaques::AsInfer => "AsInfer",
                TreatNotYetDefinedOpaques::AsRigid => "AsRigid",
            })
    }
}Debug)]
333pub(super) enum TreatNotYetDefinedOpaques {
334    AsInfer,
335    AsRigid,
336}
337
338impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
339    /// `lookup_method_in_trait` is used for overloaded operators.
340    /// It does a very narrow slice of what the normal probe/confirm path does.
341    /// In particular, it doesn't really do any probing: it simply constructs
342    /// an obligation for a particular trait with the given self type and checks
343    /// whether that trait is implemented.
344    {}
#[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("lookup_method_for_operator",
                                    "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(344u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("cause")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("cause");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("method_name")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("method_name");
                                                        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("self_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self_ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("opt_rhs_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("opt_rhs_ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("treat_opaques")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("treat_opaques");
                                                        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(&cause)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&method_name)
                                                            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(&::tracing::field::debug(&self_ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&opt_rhs_ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&treat_opaques)
                                                            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<InferOk<'tcx, MethodCallee<'tcx>>> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let args =
                GenericArgs::for_item(self.tcx, trait_def_id,
                    |param, _|
                        match param.kind {
                            GenericParamDefKind::Lifetime | GenericParamDefKind::Const {
                                .. } => {
                                {
                                    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
                                            format_args!("did not expect operator trait to have lifetime/const")));
                                }
                            }
                            GenericParamDefKind::Type { .. } => {
                                if param.index == 0 {
                                    self_ty.into()
                                } else if let Some(rhs_ty) = opt_rhs_ty {
                                    {
                                        match (&param.index, &1) {
                                            (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::Some(format_args!("did not expect >1 param on operator trait")));
                                                }
                                            }
                                        }
                                    };
                                    rhs_ty.into()
                                } else { self.var_for_def(cause.span, param) }
                            }
                        });
            let obligation =
                traits::Obligation::new(self.tcx, cause, self.param_env,
                    ty::TraitRef::new_from_args(self.tcx, trait_def_id, args));
            let matches_trait =
                match treat_opaques {
                    TreatNotYetDefinedOpaques::AsInfer =>
                        self.predicate_may_hold(&obligation),
                    TreatNotYetDefinedOpaques::AsRigid => {
                        self.predicate_may_hold_opaque_types_jank(&obligation)
                    }
                };
            if !matches_trait {
                {
                    use ::tracing::__macro_support::Callsite as _;
                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                        {
                            static META: ::tracing::Metadata<'static> =
                                {
                                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs:390",
                                        "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                        ::tracing_core::__macro_support::Option::Some(390u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                        ::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 match obligation")
                                                            as &dyn ::tracing::field::Value))])
                            });
                    } else { ; }
                };
                return None;
            }
            let tcx = self.tcx;
            let Some(method_item) =
                self.associated_value(trait_def_id,
                    Ident::with_dummy_span(method_name)) else {
                    bug_impl(None,
                        format_args!("expected associated item for operator trait"),
                        Location::caller())
                };
            let def_id = method_item.def_id;
            if !method_item.is_fn() {
                bug_impl(Some(tcx.def_span(def_id)),
                    format_args!("expected `{0}` to be an associated function",
                        method_name), Location::caller());
            }
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs:414",
                                    "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(414u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                    ::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!("lookup_in_trait_adjusted: method_item={0:?}",
                                                                method_item) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let mut obligations = PredicateObligations::new();
            let fn_sig =
                tcx.fn_sig(def_id).instantiate(self.tcx,
                        args).skip_norm_wip();
            let fn_sig =
                self.instantiate_binder_with_fresh_vars(obligation.cause.span,
                    BoundRegionConversionTime::FnCall, fn_sig);
            let InferOk { value: fn_sig, obligations: o } =
                self.at(&obligation.cause,
                        self.param_env).normalize(Unnormalized::new_wip(fn_sig));
            obligations.extend(o);
            let bounds =
                self.tcx.clauses_of(def_id).instantiate(self.tcx, args);
            let predicates_cause = obligation.cause.clone();
            let mut normalization_obligations = PredicateObligations::new();
            obligations.extend(traits::predicates_for_generics(move |_, _|
                        predicates_cause.clone(),
                    |clause|
                        {
                            let InferOk { value: pred, obligations: o } =
                                self.at(&obligation.cause,
                                        self.param_env).normalize(clause);
                            normalization_obligations.extend(o);
                            if !!pred.has_escaping_bound_vars() {
                                ::core::panicking::panic("assertion failed: !pred.has_escaping_bound_vars()")
                            };
                            pred
                        }, self.param_env, bounds));
            obligations.extend(normalization_obligations);
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs:461",
                                    "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(461u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                    ::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!("lookup_method_in_trait: matched method fn_sig={0:?} obligation={1:?}",
                                                                fn_sig, obligation) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            for ty in fn_sig.inputs_and_output {
                obligations.push(traits::Obligation::new(tcx,
                        obligation.cause.clone(), self.param_env,
                        ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(ty.into())))));
            }
            let callee = MethodCallee { def_id, args, sig: fn_sig };
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs:475",
                                    "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(475u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                    ::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!("callee = {0:?}",
                                                                callee) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            Some(InferOk { obligations, value: callee })
        }
    }
}#[instrument(level = "debug", skip(self))]
345    pub(super) fn lookup_method_for_operator(
346        &self,
347        cause: ObligationCause<'tcx>,
348        method_name: Symbol,
349        trait_def_id: DefId,
350        self_ty: Ty<'tcx>,
351        opt_rhs_ty: Option<Ty<'tcx>>,
352        treat_opaques: TreatNotYetDefinedOpaques,
353    ) -> Option<InferOk<'tcx, MethodCallee<'tcx>>> {
354        // Construct a trait-reference `self_ty : Trait<input_tys>`
355        let args = GenericArgs::for_item(self.tcx, trait_def_id, |param, _| match param.kind {
356            GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => {
357                unreachable!("did not expect operator trait to have lifetime/const")
358            }
359            GenericParamDefKind::Type { .. } => {
360                if param.index == 0 {
361                    self_ty.into()
362                } else if let Some(rhs_ty) = opt_rhs_ty {
363                    assert_eq!(param.index, 1, "did not expect >1 param on operator trait");
364                    rhs_ty.into()
365                } else {
366                    // FIXME: We should stop passing `None` for the failure case
367                    // when probing for call exprs. I.e. `opt_rhs_ty` should always
368                    // be set when it needs to be.
369                    self.var_for_def(cause.span, param)
370                }
371            }
372        });
373
374        let obligation = traits::Obligation::new(
375            self.tcx,
376            cause,
377            self.param_env,
378            ty::TraitRef::new_from_args(self.tcx, trait_def_id, args),
379        );
380
381        // Now we want to know if this can be matched
382        let matches_trait = match treat_opaques {
383            TreatNotYetDefinedOpaques::AsInfer => self.predicate_may_hold(&obligation),
384            TreatNotYetDefinedOpaques::AsRigid => {
385                self.predicate_may_hold_opaque_types_jank(&obligation)
386            }
387        };
388
389        if !matches_trait {
390            debug!("--> Cannot match obligation");
391            // Cannot be matched, no such method resolution is possible.
392            return None;
393        }
394
395        // Trait must have a method named `m_name` and it should not have
396        // type parameters or early-bound regions.
397        let tcx = self.tcx;
398        // We use `Ident::with_dummy_span` since no built-in operator methods have
399        // any macro-specific hygiene, so the span's context doesn't really matter.
400        let Some(method_item) =
401            self.associated_value(trait_def_id, Ident::with_dummy_span(method_name))
402        else {
403            bug!("expected associated item for operator trait")
404        };
405
406        let def_id = method_item.def_id;
407        if !method_item.is_fn() {
408            span_bug!(
409                tcx.def_span(def_id),
410                "expected `{method_name}` to be an associated function"
411            );
412        }
413
414        debug!("lookup_in_trait_adjusted: method_item={:?}", method_item);
415        let mut obligations = PredicateObligations::new();
416
417        // Instantiate late-bound regions and instantiate the trait
418        // parameters into the method type to get the actual method type.
419        //
420        // N.B., instantiate late-bound regions before normalizing the
421        // function signature so that normalization does not need to deal
422        // with bound regions.
423        let fn_sig = tcx.fn_sig(def_id).instantiate(self.tcx, args).skip_norm_wip();
424        let fn_sig = self.instantiate_binder_with_fresh_vars(
425            obligation.cause.span,
426            BoundRegionConversionTime::FnCall,
427            fn_sig,
428        );
429
430        let InferOk { value: fn_sig, obligations: o } =
431            self.at(&obligation.cause, self.param_env).normalize(Unnormalized::new_wip(fn_sig));
432        obligations.extend(o);
433
434        // Register obligations for the parameters. This will include the
435        // `Self` parameter, which in turn has a bound of the main trait,
436        // so this also effectively registers `obligation` as well. (We
437        // used to register `obligation` explicitly, but that resulted in
438        // double error messages being reported.)
439        //
440        // Note that as the method comes from a trait, it should not have
441        // any late-bound regions appearing in its bounds.
442        let bounds = self.tcx.clauses_of(def_id).instantiate(self.tcx, args);
443
444        let predicates_cause = obligation.cause.clone();
445        let mut normalization_obligations = PredicateObligations::new();
446        obligations.extend(traits::predicates_for_generics(
447            move |_, _| predicates_cause.clone(),
448            |clause| {
449                let InferOk { value: pred, obligations: o } =
450                    self.at(&obligation.cause, self.param_env).normalize(clause);
451                normalization_obligations.extend(o);
452                assert!(!pred.has_escaping_bound_vars());
453                pred
454            },
455            self.param_env,
456            bounds,
457        ));
458        obligations.extend(normalization_obligations);
459
460        // Also add an obligation for the method type being well-formed.
461        debug!(
462            "lookup_method_in_trait: matched method fn_sig={:?} obligation={:?}",
463            fn_sig, obligation
464        );
465        for ty in fn_sig.inputs_and_output {
466            obligations.push(traits::Obligation::new(
467                tcx,
468                obligation.cause.clone(),
469                self.param_env,
470                ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(ty.into()))),
471            ));
472        }
473
474        let callee = MethodCallee { def_id, args, sig: fn_sig };
475        debug!("callee = {:?}", callee);
476
477        Some(InferOk { obligations, value: callee })
478    }
479
480    /// Performs a [full-qualified function call] (formerly "universal function call") lookup. If
481    /// lookup is successful, it will return the type of definition and the [`DefId`] of the found
482    /// function definition.
483    ///
484    /// [full-qualified function call]: https://doc.rust-lang.org/reference/expressions/call-expr.html#disambiguating-function-calls
485    ///
486    /// # Arguments
487    ///
488    /// Given a function call like `Foo::bar::<T1,...Tn>(...)`:
489    ///
490    /// * `self`:                  the surrounding `FnCtxt` (!)
491    /// * `span`:                  the span of the call, excluding arguments (`Foo::bar::<T1, ...Tn>`)
492    /// * `method_name`:           the identifier of the function within the container type (`bar`)
493    /// * `self_ty`:               the type to search within (`Foo`)
494    /// * `self_ty_span`           the span for the type being searched within (span of `Foo`)
495    /// * `expr_id`:               the [`hir::HirId`] of the expression composing the entire call
496    {}
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("resolve_fully_qualified_call",
                                "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(496u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                ::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("method_name")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("method_name");
                                                    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("self_ty_span")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("self_ty_span");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("expr_id")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("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(&method_name)
                                                        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(&self_ty_span)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&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();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return:
                                Result<(DefKind, DefId), MethodError<'tcx>> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let tcx = self.tcx;
                        let mut struct_variant = None;
                        if let ty::Adt(adt_def, _) = self_ty.kind() {
                            if adt_def.is_enum() {
                                let variant_def =
                                    adt_def.variants().iter().find(|vd|
                                            tcx.hygienic_eq(method_name, vd.ident(tcx), adt_def.did()));
                                if let Some(variant_def) = variant_def {
                                    if let Some((ctor_kind, ctor_def_id)) = variant_def.ctor {
                                        tcx.check_stability(ctor_def_id, Some(expr_id), span,
                                            Some(method_name.span));
                                        return Ok((DefKind::Ctor(CtorOf::Variant, ctor_kind),
                                                    ctor_def_id));
                                    } else {
                                        struct_variant =
                                            Some((DefKind::Variant, variant_def.def_id));
                                    }
                                }
                            }
                        }
                        let pick =
                            self.probe_for_name(probe::Mode::Path, method_name, None,
                                IsSuggestion(false), self_ty, expr_id,
                                ProbeScope::TraitsInScope);
                        let pick =
                            match (pick, struct_variant) {
                                (Err(_), Some(res)) => return Ok(res),
                                (pick, _) => pick?,
                            };
                        pick.maybe_emit_unstable_name_collision_hint(self.tcx, span,
                            expr_id);
                        self.lint_fully_qualified_call_from_2018(span, method_name,
                            self_ty, self_ty_span, expr_id, &pick);
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs:557",
                                                "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(557u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("pick")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("pick");
                                                                    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(&pick)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        {
                            let mut typeck_results = self.typeck_results.borrow_mut();
                            for &import_id in pick.import_ids {
                                {
                                    use ::tracing::__macro_support::Callsite as _;
                                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                        {
                                            static META: ::tracing::Metadata<'static> =
                                                {
                                                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs:561",
                                                        "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                                                        ::tracing_core::__macro_support::Option::Some(561u32),
                                                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                                                        ::tracing_core::field::FieldSet::new(&[{
                                                                            const NAME:
                                                                                ::tracing::__macro_support::FieldName<{
                                                                                    ::tracing::__macro_support::FieldName::len("used_trait_import")
                                                                                }> =
                                                                                ::tracing::__macro_support::FieldName::new("used_trait_import");
                                                                            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(&import_id)
                                                                            as &dyn ::tracing::field::Value))])
                                            });
                                    } else { ; }
                                };
                                typeck_results.used_trait_imports.insert(import_id);
                            }
                        }
                        let def_kind = pick.item.as_def_kind();
                        tcx.check_stability(pick.item.def_id, Some(expr_id), span,
                            Some(method_name.span));
                        Ok((def_kind, pick.item.def_id))
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs:496",
                        "rustc_hir_typeck::method", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/method/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(496u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method"),
                        ::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)]
497    pub(crate) fn resolve_fully_qualified_call(
498        &self,
499        span: Span,
500        method_name: Ident,
501        self_ty: Ty<'tcx>,
502        self_ty_span: Span,
503        expr_id: hir::HirId,
504    ) -> Result<(DefKind, DefId), MethodError<'tcx>> {
505        let tcx = self.tcx;
506
507        // Check if we have an enum variant.
508        let mut struct_variant = None;
509        if let ty::Adt(adt_def, _) = self_ty.kind() {
510            if adt_def.is_enum() {
511                let variant_def = adt_def
512                    .variants()
513                    .iter()
514                    .find(|vd| tcx.hygienic_eq(method_name, vd.ident(tcx), adt_def.did()));
515                if let Some(variant_def) = variant_def {
516                    if let Some((ctor_kind, ctor_def_id)) = variant_def.ctor {
517                        tcx.check_stability(
518                            ctor_def_id,
519                            Some(expr_id),
520                            span,
521                            Some(method_name.span),
522                        );
523                        return Ok((DefKind::Ctor(CtorOf::Variant, ctor_kind), ctor_def_id));
524                    } else {
525                        struct_variant = Some((DefKind::Variant, variant_def.def_id));
526                    }
527                }
528            }
529        }
530
531        let pick = self.probe_for_name(
532            probe::Mode::Path,
533            method_name,
534            None,
535            IsSuggestion(false),
536            self_ty,
537            expr_id,
538            ProbeScope::TraitsInScope,
539        );
540        let pick = match (pick, struct_variant) {
541            // Fall back to a resolution that will produce an error later.
542            (Err(_), Some(res)) => return Ok(res),
543            (pick, _) => pick?,
544        };
545
546        pick.maybe_emit_unstable_name_collision_hint(self.tcx, span, expr_id);
547
548        self.lint_fully_qualified_call_from_2018(
549            span,
550            method_name,
551            self_ty,
552            self_ty_span,
553            expr_id,
554            &pick,
555        );
556
557        debug!(?pick);
558        {
559            let mut typeck_results = self.typeck_results.borrow_mut();
560            for &import_id in pick.import_ids {
561                debug!(used_trait_import=?import_id);
562                typeck_results.used_trait_imports.insert(import_id);
563            }
564        }
565
566        let def_kind = pick.item.as_def_kind();
567        tcx.check_stability(pick.item.def_id, Some(expr_id), span, Some(method_name.span));
568        Ok((def_kind, pick.item.def_id))
569    }
570
571    /// Finds item with name `item_ident` defined in impl/trait `def_id`
572    /// and return it, or `None`, if no such item was defined there.
573    fn associated_value(&self, def_id: DefId, item_ident: Ident) -> Option<ty::AssocItem> {
574        self.tcx
575            .associated_items(def_id)
576            .find_by_ident_and_namespace(self.tcx, item_ident, Namespace::ValueNS, def_id)
577            .copied()
578    }
579}