Skip to main content

rustc_hir_typeck/
closure.rs

1//! Code for type-checking closure expressions.
2
3use std::iter;
4use std::ops::ControlFlow;
5
6use rustc_abi::ExternAbi;
7use rustc_attr_ir::lang_items::LangItem;
8use rustc_errors::ErrorGuaranteed;
9use rustc_hir as hir;
10use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
11use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, InferResult};
12use rustc_infer::traits::{ObligationCauseCode, PredicateObligations};
13use rustc_macros::{TypeFoldable, TypeVisitable};
14use rustc_middle::ty::{
15    self, ClosureKind, FnSigKind, GenericArgs, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
16    TypeVisitableExt, TypeVisitor, Unnormalized,
17};
18use rustc_span::def_id::LocalDefId;
19use rustc_span::{DUMMY_SP, Span, span_bug};
20use rustc_trait_selection::error_reporting::traits::ArgKind;
21use rustc_trait_selection::traits;
22use tracing::{debug, instrument, trace};
23
24use super::{CoroutineTypes, Expectation, FnCtxt, check_fn};
25use crate::fn_ctxt::UseSubtyping;
26
27/// What signature do we *expect* the closure to have from context?
28#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ExpectedSig<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "ExpectedSig",
            "cause_span", &self.cause_span, "sig", &&self.sig)
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for ExpectedSig<'tcx> {
    #[inline]
    fn clone(&self) -> Self {
        Self {
            cause_span: ::core::clone::Clone::clone(&self.cause_span),
            sig: ::core::clone::Clone::clone(&self.sig),
        }
    }
}Clone, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
            for ExpectedSig<'tcx> {
            fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        ExpectedSig { cause_span: __binding_0, sig: __binding_1 } =>
                            {
                            ExpectedSig {
                                cause_span: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                sig: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    ExpectedSig { cause_span: __binding_0, sig: __binding_1 } =>
                        {
                        ExpectedSig {
                            cause_span: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            sig: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
            for ExpectedSig<'tcx> {
            fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    ExpectedSig {
                        cause_span: ref __binding_0, sig: ref __binding_1 } => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_middle::ty::VisitorResult>::output()
            }
        }
    };TypeVisitable)]
29struct ExpectedSig<'tcx> {
30    /// Span that gave us this expectation, if we know that.
31    cause_span: Option<Span>,
32    sig: ty::PolyFnSig<'tcx>,
33}
34
35#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ClosureSignatures<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "ClosureSignatures", "bound_sig", &self.bound_sig,
            "liberated_sig", &&self.liberated_sig)
    }
}Debug)]
36struct ClosureSignatures<'tcx> {
37    /// The signature users of the closure see.
38    bound_sig: ty::PolyFnSig<'tcx>,
39    /// The signature within the function body.
40    /// This mostly differs in the sense that lifetimes are now early bound and any
41    /// opaque types from the signature expectation are overridden in case there are
42    /// explicit hidden types written by the user in the closure signature.
43    liberated_sig: ty::FnSig<'tcx>,
44}
45
46impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
47    {}
#[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("check_expr_closure",
                                    "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                    ::tracing_core::__macro_support::Option::Some(47u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("expr_span")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("expr_span");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("expected")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("expected");
                                                        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(&expr_span)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expected)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: Ty<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let tcx = self.tcx;
            let body = tcx.hir_body(closure.body);
            let expr_def_id = closure.def_id;
            let (expected_sig, expected_kind) =
                match expected.to_option(self) {
                    Some(ty) =>
                        self.deduce_closure_signature(self.deeply_resolve_ignoring_regions_with_obligations(ty),
                            closure.kind),
                    None => (None, None),
                };
            let ClosureSignatures { bound_sig, mut liberated_sig } =
                self.sig_of_closure(expr_def_id, closure.fn_decl,
                    closure.kind, expected_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/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:72",
                                    "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                    ::tracing_core::__macro_support::Option::Some(72u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("bound_sig")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("bound_sig");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("liberated_sig")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("liberated_sig");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bound_sig)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&liberated_sig)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let parent_args =
                GenericArgs::identity_for_item(tcx,
                    tcx.typeck_root_def_id_local(expr_def_id));
            let tupled_upvars_ty = self.next_ty_var(expr_span);
            let (closure_ty, coroutine_types) =
                match closure.kind {
                    hir::ClosureKind::Closure => {
                        let sig =
                            bound_sig.map_bound(|sig|
                                    {
                                        tcx.mk_fn_sig([Ty::new_tup(tcx, sig.inputs())],
                                            sig.output(), sig.fn_sig_kind)
                                    });
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:91",
                                                "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                                ::tracing_core::__macro_support::Option::Some(91u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("sig")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("sig");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("expected_kind")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("expected_kind");
                                                                    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(&sig)
                                                                    as &dyn ::tracing::field::Value)),
                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expected_kind)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let closure_kind_ty =
                            match expected_kind {
                                Some(kind) => Ty::from_closure_kind(tcx, kind),
                                None => self.next_ty_var(expr_span),
                            };
                        let closure_args =
                            ty::ClosureArgs::new(tcx,
                                ty::ClosureArgsParts {
                                    parent_args,
                                    closure_kind_ty,
                                    closure_sig_as_fn_ptr_ty: Ty::new_fn_ptr(tcx, sig),
                                    tupled_upvars_ty,
                                });
                        (Ty::new_closure(tcx, expr_def_id.to_def_id(),
                                closure_args.args), None)
                    }
                    hir::ClosureKind::Coroutine(kind) => {
                        let yield_ty =
                            match kind {
                                hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen,
                                    _) | hir::CoroutineKind::Coroutine(_) => {
                                    let yield_ty = self.next_ty_var(expr_span);
                                    self.require_type_is_sized(yield_ty, expr_span,
                                        ObligationCauseCode::SizedYieldType);
                                    yield_ty
                                }
                                hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen,
                                    _) => {
                                    let yield_ty = self.next_ty_var(expr_span);
                                    self.require_type_is_sized(yield_ty, expr_span,
                                        ObligationCauseCode::SizedYieldType);
                                    Ty::new_adt(tcx,
                                        tcx.adt_def(tcx.require_lang_item(LangItem::Poll,
                                                expr_span)),
                                        tcx.mk_args(&[Ty::new_adt(tcx,
                                                                tcx.adt_def(tcx.require_lang_item(LangItem::Option,
                                                                        expr_span)), tcx.mk_args(&[yield_ty.into()])).into()]))
                                }
                                hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async,
                                    _) => {
                                    tcx.types.unit
                                }
                            };
                        let resume_ty =
                            liberated_sig.inputs().get(0).copied().unwrap_or(tcx.types.unit);
                        let kind_ty =
                            match kind {
                                hir::CoroutineKind::Desugared(_,
                                    hir::CoroutineSource::Closure) => {
                                    self.next_ty_var(expr_span)
                                }
                                _ => tcx.types.unit,
                            };
                        let coroutine_args =
                            ty::CoroutineArgs::new(tcx,
                                ty::CoroutineArgsParts {
                                    parent_args,
                                    kind_ty,
                                    resume_ty,
                                    yield_ty,
                                    return_ty: liberated_sig.output(),
                                    tupled_upvars_ty,
                                });
                        (Ty::new_coroutine(tcx, expr_def_id.to_def_id(),
                                coroutine_args.args),
                            Some(CoroutineTypes { resume_ty, yield_ty }))
                    }
                    hir::ClosureKind::CoroutineClosure(kind) => {
                        let (bound_return_ty, bound_yield_ty) =
                            match kind {
                                hir::CoroutineDesugaring::Gen => {
                                    (tcx.types.unit, self.infcx.next_ty_var(expr_span))
                                }
                                hir::CoroutineDesugaring::Async => {
                                    (bound_sig.skip_binder().output(), tcx.types.unit)
                                }
                                hir::CoroutineDesugaring::AsyncGen => {
                                    {
                                        ::core::panicking::panic_fmt(format_args!("not implemented: {0}",
                                                format_args!("`async gen` closures not supported yet")));
                                    }
                                }
                            };
                        let resume_ty = self.next_ty_var(expr_span);
                        let closure_kind_ty =
                            match expected_kind {
                                Some(kind) => Ty::from_closure_kind(tcx, kind),
                                None => self.next_ty_var(expr_span),
                            };
                        let coroutine_captures_by_ref_ty =
                            self.next_ty_var(expr_span);
                        let closure_args =
                            ty::CoroutineClosureArgs::new(tcx,
                                ty::CoroutineClosureArgsParts {
                                    parent_args,
                                    closure_kind_ty,
                                    signature_parts_ty: Ty::new_fn_ptr(tcx,
                                        bound_sig.map_bound(|sig|
                                                {
                                                    tcx.mk_fn_sig([resume_ty,
                                                                Ty::new_tup_from_iter(tcx, sig.inputs().iter().copied())],
                                                        Ty::new_tup(tcx, &[bound_yield_ty, bound_return_ty]),
                                                        sig.fn_sig_kind)
                                                })),
                                    tupled_upvars_ty,
                                    coroutine_captures_by_ref_ty,
                                });
                        let coroutine_kind_ty =
                            match expected_kind {
                                Some(kind) => Ty::from_coroutine_closure_kind(tcx, kind),
                                None => self.next_ty_var(expr_span),
                            };
                        let coroutine_upvars_ty = self.next_ty_var(expr_span);
                        let coroutine_output_ty =
                            tcx.liberate_late_bound_regions(expr_def_id.to_def_id(),
                                closure_args.coroutine_closure_sig().map_bound(|sig|
                                        {
                                            sig.to_coroutine(tcx, parent_args, coroutine_kind_ty,
                                                tcx.coroutine_for_closure(expr_def_id), coroutine_upvars_ty)
                                        }));
                        liberated_sig =
                            tcx.mk_fn_sig(liberated_sig.inputs().iter().copied(),
                                coroutine_output_ty, liberated_sig.fn_sig_kind);
                        (Ty::new_coroutine_closure(tcx, expr_def_id.to_def_id(),
                                closure_args.args), None)
                    }
                };
            check_fn(&mut FnCtxt::new(self, self.param_env, closure.def_id),
                liberated_sig, coroutine_types, closure.fn_decl, expr_def_id,
                body, false);
            closure_ty
        }
    }
}#[instrument(skip(self, closure), level = "debug")]
48    pub(crate) fn check_expr_closure(
49        &self,
50        closure: &hir::Closure<'tcx>,
51        expr_span: Span,
52        expected: Expectation<'tcx>,
53    ) -> Ty<'tcx> {
54        let tcx = self.tcx;
55        let body = tcx.hir_body(closure.body);
56        let expr_def_id = closure.def_id;
57
58        // It's always helpful for inference if we know the kind of
59        // closure sooner rather than later, so first examine the expected
60        // type, and see if can glean a closure kind from there.
61        let (expected_sig, expected_kind) = match expected.to_option(self) {
62            Some(ty) => self.deduce_closure_signature(
63                self.deeply_resolve_ignoring_regions_with_obligations(ty),
64                closure.kind,
65            ),
66            None => (None, None),
67        };
68
69        let ClosureSignatures { bound_sig, mut liberated_sig } =
70            self.sig_of_closure(expr_def_id, closure.fn_decl, closure.kind, expected_sig);
71
72        debug!(?bound_sig, ?liberated_sig);
73
74        let parent_args =
75            GenericArgs::identity_for_item(tcx, tcx.typeck_root_def_id_local(expr_def_id));
76
77        let tupled_upvars_ty = self.next_ty_var(expr_span);
78
79        // FIXME: We could probably actually just unify this further --
80        // instead of having a `FnSig` and a `Option<CoroutineTypes>`,
81        // we can have a `ClosureSignature { Coroutine { .. }, Closure { .. } }`,
82        // similar to how `ty::GenSig` is a distinct data structure.
83        let (closure_ty, coroutine_types) = match closure.kind {
84            hir::ClosureKind::Closure => {
85                // Tuple up the arguments and insert the resulting function type into
86                // the `closures` table.
87                let sig = bound_sig.map_bound(|sig| {
88                    tcx.mk_fn_sig([Ty::new_tup(tcx, sig.inputs())], sig.output(), sig.fn_sig_kind)
89                });
90
91                debug!(?sig, ?expected_kind);
92
93                let closure_kind_ty = match expected_kind {
94                    Some(kind) => Ty::from_closure_kind(tcx, kind),
95
96                    // Create a type variable (for now) to represent the closure kind.
97                    // It will be unified during the upvar inference phase (`upvar.rs`)
98                    None => self.next_ty_var(expr_span),
99                };
100
101                let closure_args = ty::ClosureArgs::new(
102                    tcx,
103                    ty::ClosureArgsParts {
104                        parent_args,
105                        closure_kind_ty,
106                        closure_sig_as_fn_ptr_ty: Ty::new_fn_ptr(tcx, sig),
107                        tupled_upvars_ty,
108                    },
109                );
110
111                (Ty::new_closure(tcx, expr_def_id.to_def_id(), closure_args.args), None)
112            }
113            hir::ClosureKind::Coroutine(kind) => {
114                let yield_ty = match kind {
115                    hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
116                    | hir::CoroutineKind::Coroutine(_) => {
117                        let yield_ty = self.next_ty_var(expr_span);
118                        self.require_type_is_sized(
119                            yield_ty,
120                            expr_span,
121                            ObligationCauseCode::SizedYieldType,
122                        );
123                        yield_ty
124                    }
125                    // HACK(-Ztrait-solver=next): In the *old* trait solver, we must eagerly
126                    // guide inference on the yield type so that we can handle `AsyncIterator`
127                    // in this block in projection correctly. In the new trait solver, it is
128                    // not a problem.
129                    hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _) => {
130                        let yield_ty = self.next_ty_var(expr_span);
131                        self.require_type_is_sized(
132                            yield_ty,
133                            expr_span,
134                            ObligationCauseCode::SizedYieldType,
135                        );
136
137                        Ty::new_adt(
138                            tcx,
139                            tcx.adt_def(tcx.require_lang_item(LangItem::Poll, expr_span)),
140                            tcx.mk_args(&[Ty::new_adt(
141                                tcx,
142                                tcx.adt_def(tcx.require_lang_item(LangItem::Option, expr_span)),
143                                tcx.mk_args(&[yield_ty.into()]),
144                            )
145                            .into()]),
146                        )
147                    }
148                    hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _) => {
149                        tcx.types.unit
150                    }
151                };
152
153                // Resume type defaults to `()` if the coroutine has no argument.
154                let resume_ty = liberated_sig.inputs().get(0).copied().unwrap_or(tcx.types.unit);
155
156                // Coroutines that come from coroutine closures have not yet determined
157                // their kind ty, so make a fresh infer var which will be constrained
158                // later during upvar analysis. Regular coroutines always have the kind
159                // ty of `().`
160                let kind_ty = match kind {
161                    hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure) => {
162                        self.next_ty_var(expr_span)
163                    }
164                    _ => tcx.types.unit,
165                };
166
167                let coroutine_args = ty::CoroutineArgs::new(
168                    tcx,
169                    ty::CoroutineArgsParts {
170                        parent_args,
171                        kind_ty,
172                        resume_ty,
173                        yield_ty,
174                        return_ty: liberated_sig.output(),
175                        tupled_upvars_ty,
176                    },
177                );
178
179                (
180                    Ty::new_coroutine(tcx, expr_def_id.to_def_id(), coroutine_args.args),
181                    Some(CoroutineTypes { resume_ty, yield_ty }),
182                )
183            }
184            hir::ClosureKind::CoroutineClosure(kind) => {
185                let (bound_return_ty, bound_yield_ty) = match kind {
186                    hir::CoroutineDesugaring::Gen => {
187                        // `iter!` closures always return unit and yield the `Iterator::Item` type
188                        // that we have to infer.
189                        (tcx.types.unit, self.infcx.next_ty_var(expr_span))
190                    }
191                    hir::CoroutineDesugaring::Async => {
192                        // async closures always return the type ascribed after the `->` (if present),
193                        // and yield `()`.
194                        (bound_sig.skip_binder().output(), tcx.types.unit)
195                    }
196                    hir::CoroutineDesugaring::AsyncGen => {
197                        unimplemented!("`async gen` closures not supported yet")
198                    }
199                };
200                // Compute all of the variables that will be used to populate the coroutine.
201                let resume_ty = self.next_ty_var(expr_span);
202
203                let closure_kind_ty = match expected_kind {
204                    Some(kind) => Ty::from_closure_kind(tcx, kind),
205
206                    // Create a type variable (for now) to represent the closure kind.
207                    // It will be unified during the upvar inference phase (`upvar.rs`)
208                    None => self.next_ty_var(expr_span),
209                };
210
211                let coroutine_captures_by_ref_ty = self.next_ty_var(expr_span);
212                let closure_args = ty::CoroutineClosureArgs::new(
213                    tcx,
214                    ty::CoroutineClosureArgsParts {
215                        parent_args,
216                        closure_kind_ty,
217                        signature_parts_ty: Ty::new_fn_ptr(
218                            tcx,
219                            bound_sig.map_bound(|sig| {
220                                tcx.mk_fn_sig(
221                                    [
222                                        resume_ty,
223                                        Ty::new_tup_from_iter(tcx, sig.inputs().iter().copied()),
224                                    ],
225                                    Ty::new_tup(tcx, &[bound_yield_ty, bound_return_ty]),
226                                    sig.fn_sig_kind,
227                                )
228                            }),
229                        ),
230                        tupled_upvars_ty,
231                        coroutine_captures_by_ref_ty,
232                    },
233                );
234
235                let coroutine_kind_ty = match expected_kind {
236                    Some(kind) => Ty::from_coroutine_closure_kind(tcx, kind),
237
238                    // Create a type variable (for now) to represent the closure kind.
239                    // It will be unified during the upvar inference phase (`upvar.rs`)
240                    None => self.next_ty_var(expr_span),
241                };
242
243                let coroutine_upvars_ty = self.next_ty_var(expr_span);
244
245                // We need to turn the liberated signature that we got from HIR, which
246                // looks something like `|Args...| -> T`, into a signature that is suitable
247                // for type checking the inner body of the closure, which always returns a
248                // coroutine. To do so, we use the `CoroutineClosureSignature` to compute
249                // the coroutine type, filling in the tupled_upvars_ty and kind_ty with infer
250                // vars which will get constrained during upvar analysis.
251                let coroutine_output_ty = tcx.liberate_late_bound_regions(
252                    expr_def_id.to_def_id(),
253                    closure_args.coroutine_closure_sig().map_bound(|sig| {
254                        sig.to_coroutine(
255                            tcx,
256                            parent_args,
257                            coroutine_kind_ty,
258                            tcx.coroutine_for_closure(expr_def_id),
259                            coroutine_upvars_ty,
260                        )
261                    }),
262                );
263                liberated_sig = tcx.mk_fn_sig(
264                    liberated_sig.inputs().iter().copied(),
265                    coroutine_output_ty,
266                    liberated_sig.fn_sig_kind,
267                );
268
269                (Ty::new_coroutine_closure(tcx, expr_def_id.to_def_id(), closure_args.args), None)
270            }
271        };
272
273        check_fn(
274            &mut FnCtxt::new(self, self.param_env, closure.def_id),
275            liberated_sig,
276            coroutine_types,
277            closure.fn_decl,
278            expr_def_id,
279            body,
280            // Closure "rust-call" ABI doesn't support unsized params
281            false,
282        );
283
284        closure_ty
285    }
286
287    /// Given the expected type, figures out what it can about this closure we
288    /// are about to type check:
289    {}
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("deduce_closure_signature",
                                "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                ::tracing_core::__macro_support::Option::Some(289u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("expected_ty")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("expected_ty");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("closure_kind")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("closure_kind");
                                                    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(&expected_ty)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&closure_kind)
                                                        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:
                                (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        match *expected_ty.kind() {
                            ty::Alias(_, ty::AliasTy {
                                kind: ty::Opaque { def_id }, args, .. }) =>
                                self.deduce_closure_signature_from_predicates(expected_ty,
                                    closure_kind,
                                    self.tcx.explicit_item_self_bounds(def_id).iter_instantiated_copied(self.tcx,
                                            args).map(Unnormalized::skip_norm_wip)),
                            ty::Dynamic(object_type, ..) => {
                                let sig =
                                    object_type.projection_bounds().find_map(|pb|
                                            {
                                                let pb =
                                                    pb.with_self_ty(self.tcx,
                                                        self.tcx.types.trait_object_dummy_self);
                                                self.deduce_sig_from_projection(None, closure_kind, pb)
                                            });
                                let kind =
                                    object_type.principal_def_id().and_then(|did|
                                            self.tcx.fn_trait_kind_from_def_id(did));
                                (sig, kind)
                            }
                            ty::Infer(ty::TyVar(vid)) =>
                                self.deduce_closure_signature_from_predicates(Ty::new_var(self.tcx,
                                        self.root_var(vid)), closure_kind,
                                    self.obligations_for_self_ty(vid,
                                                UseSubtyping::No).into_iter().filter_map(|obl|
                                            Some((obl.predicate.as_clause()?, obl.cause.span)))),
                            ty::FnPtr(sig_tys, hdr) =>
                                match closure_kind {
                                    hir::ClosureKind::Closure => {
                                        let expected_sig =
                                            ExpectedSig { cause_span: None, sig: sig_tys.with(hdr) };
                                        (Some(expected_sig), Some(ty::ClosureKind::Fn))
                                    }
                                    hir::ClosureKind::Coroutine(_) |
                                        hir::ClosureKind::CoroutineClosure(_) => {
                                        (None, None)
                                    }
                                },
                            _ => (None, None),
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:289",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(289u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::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(skip(self), level = "debug", ret)]
290    fn deduce_closure_signature(
291        &self,
292        expected_ty: Ty<'tcx>,
293        closure_kind: hir::ClosureKind,
294    ) -> (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) {
295        match *expected_ty.kind() {
296            ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => self
297                .deduce_closure_signature_from_predicates(
298                    expected_ty,
299                    closure_kind,
300                    self.tcx
301                        .explicit_item_self_bounds(def_id)
302                        .iter_instantiated_copied(self.tcx, args)
303                        .map(Unnormalized::skip_norm_wip),
304                ),
305            ty::Dynamic(object_type, ..) => {
306                let sig = object_type.projection_bounds().find_map(|pb| {
307                    let pb = pb.with_self_ty(self.tcx, self.tcx.types.trait_object_dummy_self);
308                    self.deduce_sig_from_projection(None, closure_kind, pb)
309                });
310                let kind = object_type
311                    .principal_def_id()
312                    .and_then(|did| self.tcx.fn_trait_kind_from_def_id(did));
313                (sig, kind)
314            }
315            ty::Infer(ty::TyVar(vid)) => self.deduce_closure_signature_from_predicates(
316                Ty::new_var(self.tcx, self.root_var(vid)),
317                closure_kind,
318                self.obligations_for_self_ty(vid, UseSubtyping::No)
319                    .into_iter()
320                    .filter_map(|obl| Some((obl.predicate.as_clause()?, obl.cause.span))),
321            ),
322            ty::FnPtr(sig_tys, hdr) => match closure_kind {
323                hir::ClosureKind::Closure => {
324                    let expected_sig = ExpectedSig { cause_span: None, sig: sig_tys.with(hdr) };
325                    (Some(expected_sig), Some(ty::ClosureKind::Fn))
326                }
327                hir::ClosureKind::Coroutine(_) | hir::ClosureKind::CoroutineClosure(_) => {
328                    (None, None)
329                }
330            },
331            _ => (None, None),
332        }
333    }
334
335    fn deduce_closure_signature_from_predicates(
336        &self,
337        expected_ty: Ty<'tcx>,
338        closure_kind: hir::ClosureKind,
339        clauses: impl DoubleEndedIterator<Item = (ty::Clause<'tcx>, Span)>,
340    ) -> (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) {
341        let mut expected_sig = None;
342        let mut expected_kind = None;
343
344        for (clause, span) in traits::elaborate(
345            self.tcx,
346            // Reverse the obligations here, since `elaborate_*` uses a stack,
347            // and we want to keep inference generally in the same order of
348            // the registered obligations.
349            clauses.rev(),
350        )
351        // We only care about self bounds
352        .filter_only_self()
353        {
354            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:354",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(354u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("clause")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("clause");
                                            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(&clause)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?clause);
355            let bound_clause = clause.kind();
356
357            // Given a Projection clause, we can potentially infer the complete signature.
358            if expected_sig.is_none()
359                && let ty::ClauseKind::Projection(proj_clause) = bound_clause.skip_binder()
360            {
361                let inferred_sig = self.normalize(
362                    span,
363                    Unnormalized::new_wip(self.deduce_sig_from_projection(
364                        Some(span),
365                        closure_kind,
366                        bound_clause.rebind(proj_clause),
367                    )),
368                );
369
370                // Make sure that we didn't infer a signature that mentions itself.
371                // This can happen when we elaborate certain supertrait bounds that
372                // mention projections containing the `Self` type. See #105401.
373                struct MentionsTy<'tcx> {
374                    expected_ty: Ty<'tcx>,
375                }
376                impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for MentionsTy<'tcx> {
377                    type Result = ControlFlow<()>;
378
379                    fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
380                        if t == self.expected_ty {
381                            ControlFlow::Break(())
382                        } else {
383                            t.super_visit_with(self)
384                        }
385                    }
386                }
387
388                if inferred_sig.visit_with(&mut MentionsTy { expected_ty }).is_continue() {
389                    expected_sig = inferred_sig;
390                }
391            }
392
393            // Even if we can't infer the full signature, we may be able to
394            // infer the kind. This can occur when we elaborate a predicate
395            // like `F : Fn<A>`. Note that due to subtyping we could encounter
396            // many viable options, so pick the most restrictive.
397            let trait_def_id = match bound_clause.skip_binder() {
398                ty::ClauseKind::Projection(data) => {
399                    Some(data.projection_term.trait_def_id(self.tcx))
400                }
401                ty::ClauseKind::Trait(data) => Some(data.def_id()),
402                _ => None,
403            };
404
405            if let Some(trait_def_id) = trait_def_id {
406                let found_kind = match closure_kind {
407                    hir::ClosureKind::Closure
408                    // FIXME(iter_macro): Someday we'll probably want iterator closures instead of
409                    // just using Fn* for iterators.
410                    | hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Gen) => {
411                        self.tcx.fn_trait_kind_from_def_id(trait_def_id)
412                    }
413                    hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async) => self
414                        .tcx
415                        .async_fn_trait_kind_from_def_id(trait_def_id)
416                        .or_else(|| self.tcx.fn_trait_kind_from_def_id(trait_def_id)),
417                    _ => None,
418                };
419
420                if let Some(found_kind) = found_kind {
421                    // always use the closure kind that is more permissive.
422                    match (expected_kind, found_kind) {
423                        (None, _) => expected_kind = Some(found_kind),
424                        (Some(ClosureKind::FnMut), ClosureKind::Fn) => {
425                            expected_kind = Some(ClosureKind::Fn)
426                        }
427                        (Some(ClosureKind::FnOnce), ClosureKind::Fn | ClosureKind::FnMut) => {
428                            expected_kind = Some(found_kind)
429                        }
430                        _ => {}
431                    }
432                }
433            }
434        }
435
436        (expected_sig, expected_kind)
437    }
438
439    /// Given a projection like "<F as Fn(X)>::Result == Y", we can deduce
440    /// everything we need to know about a closure or coroutine.
441    ///
442    /// The `cause_span` should be the span that caused us to
443    /// have this expected signature, or `None` if we can't readily
444    /// know that.
445    {}
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("deduce_sig_from_projection",
                                "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                ::tracing_core::__macro_support::Option::Some(445u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("closure_kind")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("closure_kind");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("projection")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("projection");
                                                    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(&closure_kind)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&projection)
                                                        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: Option<ExpectedSig<'tcx>> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let def_id = projection.item_def_id();
                        match closure_kind {
                            hir::ClosureKind::Closure if
                                self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) => {
                                self.extract_sig_from_projection(cause_span, projection)
                            }
                            hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
                                if
                                self.tcx.is_lang_item(def_id, LangItem::AsyncFnOnceOutput)
                                => {
                                self.extract_sig_from_projection(cause_span, projection)
                            }
                            hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
                                if self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) =>
                                {
                                self.extract_sig_from_projection_and_future_bound(cause_span,
                                    projection)
                            }
                            _ => None,
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:445",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(445u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::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, cause_span), ret)]
446    fn deduce_sig_from_projection(
447        &self,
448        cause_span: Option<Span>,
449        closure_kind: hir::ClosureKind,
450        projection: ty::PolyProjectionClause<'tcx>,
451    ) -> Option<ExpectedSig<'tcx>> {
452        let def_id = projection.item_def_id();
453
454        // For now, we only do signature deduction based off of the `Fn` and `AsyncFn` traits,
455        // for closures and async closures, respectively.
456        match closure_kind {
457            hir::ClosureKind::Closure if self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) => {
458                self.extract_sig_from_projection(cause_span, projection)
459            }
460            hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
461                if self.tcx.is_lang_item(def_id, LangItem::AsyncFnOnceOutput) =>
462            {
463                self.extract_sig_from_projection(cause_span, projection)
464            }
465            // It's possible we've passed the closure to a (somewhat out-of-fashion)
466            // `F: FnOnce() -> Fut, Fut: Future<Output = T>` style bound. Let's still
467            // guide inference here, since it's beneficial for the user.
468            hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
469                if self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) =>
470            {
471                self.extract_sig_from_projection_and_future_bound(cause_span, projection)
472            }
473            _ => None,
474        }
475    }
476
477    /// Given an `FnOnce::Output` or `AsyncFn::Output` projection, extract the args
478    /// and return type to infer a [`ty::PolyFnSig`] for the closure.
479    fn extract_sig_from_projection(
480        &self,
481        cause_span: Option<Span>,
482        projection: ty::PolyProjectionClause<'tcx>,
483    ) -> Option<ExpectedSig<'tcx>> {
484        let projection = self.deeply_resolve_ignoring_regions(projection);
485
486        let arg_param_ty = projection.skip_binder().projection_term.args.type_at(1);
487        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:487",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(487u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("arg_param_ty")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("arg_param_ty");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&arg_param_ty)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?arg_param_ty);
488
489        let ty::Tuple(input_tys) = *arg_param_ty.kind() else {
490            return None;
491        };
492
493        // Since this is a return parameter type it is safe to unwrap.
494        let ret_param_ty = projection.skip_binder().term.expect_type();
495        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:495",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(495u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("ret_param_ty")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("ret_param_ty");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ret_param_ty)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?ret_param_ty);
496
497        let sig = projection.rebind(self.tcx.mk_fn_sig_safe_rust_abi(input_tys, ret_param_ty));
498
499        Some(ExpectedSig { cause_span, sig })
500    }
501
502    /// When an async closure is passed to a function that has a "two-part" `Fn`
503    /// and `Future` trait bound, like:
504    ///
505    /// ```rust
506    /// use std::future::Future;
507    ///
508    /// fn not_exactly_an_async_closure<F, Fut>(_f: F)
509    /// where
510    ///     F: FnOnce(String, u32) -> Fut,
511    ///     Fut: Future<Output = i32>,
512    /// {}
513    /// ```
514    ///
515    /// The we want to be able to extract the signature to guide inference in the async
516    /// closure. We will have two projection predicates registered in this case. First,
517    /// we identify the `FnOnce<Args, Output = ?Fut>` bound, and if the output type is
518    /// an inference variable `?Fut`, we check if that is bounded by a `Future<Output = Ty>`
519    /// projection.
520    ///
521    /// This function is actually best-effort with the return type; if we don't find a
522    /// `Future` projection, we still will return arguments that we extracted from the `FnOnce`
523    /// projection, and the output will be an unconstrained type variable instead.
524    fn extract_sig_from_projection_and_future_bound(
525        &self,
526        cause_span: Option<Span>,
527        projection: ty::PolyProjectionClause<'tcx>,
528    ) -> Option<ExpectedSig<'tcx>> {
529        let projection = self.deeply_resolve_ignoring_regions(projection);
530
531        let arg_param_ty = projection.skip_binder().projection_term.args.type_at(1);
532        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:532",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(532u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("arg_param_ty")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("arg_param_ty");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&arg_param_ty)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?arg_param_ty);
533
534        let ty::Tuple(input_tys) = *arg_param_ty.kind() else {
535            return None;
536        };
537
538        // If the return type is a type variable, look for bounds on it.
539        // We could theoretically support other kinds of return types here,
540        // but none of them would be useful, since async closures return
541        // concrete anonymous future types, and their futures are not coerced
542        // into any other type within the body of the async closure.
543        let ty::Infer(ty::TyVar(return_vid)) = *projection.skip_binder().term.expect_type().kind()
544        else {
545            return None;
546        };
547
548        // FIXME: We may want to elaborate here, though I assume this will be exceedingly rare.
549        let mut return_ty = None;
550        for bound in self.obligations_for_self_ty(return_vid, UseSubtyping::No) {
551            if let Some(ret_projection) = bound.predicate.as_projection_clause()
552                && let Some(ret_projection) = ret_projection.no_bound_vars()
553                && self.tcx.is_lang_item(ret_projection.def_id(), LangItem::FutureOutput)
554            {
555                return_ty = Some(ret_projection.term.expect_type());
556                break;
557            }
558        }
559
560        // SUBTLE: If we didn't find a `Future<Output = ...>` bound for the return
561        // vid, we still want to attempt to provide inference guidance for the async
562        // closure's arguments. Instantiate a new vid to plug into the output type.
563        //
564        // You may be wondering, what if it's higher-ranked? Well, given that we
565        // found a type variable for the `FnOnce::Output` projection above, we know
566        // that the output can't mention any of the vars.
567        //
568        // Also note that we use a fresh var here for the signature since the signature
569        // records the output of the *future*, and `return_vid` above is the type
570        // variable of the future, not its output.
571        //
572        // FIXME: We probably should store this signature inference output in a way
573        // that does not misuse a `FnSig` type, but that can be done separately.
574        let return_ty =
575            return_ty.unwrap_or_else(|| self.next_ty_var(cause_span.unwrap_or(DUMMY_SP)));
576
577        let sig = projection.rebind(self.tcx.mk_fn_sig_safe_rust_abi(input_tys, return_ty));
578
579        Some(ExpectedSig { cause_span, sig })
580    }
581
582    fn sig_of_closure(
583        &self,
584        expr_def_id: LocalDefId,
585        decl: &hir::FnDecl<'tcx>,
586        closure_kind: hir::ClosureKind,
587        expected_sig: Option<ExpectedSig<'tcx>>,
588    ) -> ClosureSignatures<'tcx> {
589        if let Some(e) = expected_sig {
590            self.sig_of_closure_with_expectation(expr_def_id, decl, closure_kind, e)
591        } else {
592            self.sig_of_closure_no_expectation(expr_def_id, decl, closure_kind)
593        }
594    }
595
596    /// If there is no expected signature, then we will convert the
597    /// types that the user gave into a signature.
598    {}
#[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("sig_of_closure_no_expectation",
                                    "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                    ::tracing_core::__macro_support::Option::Some(598u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("closure_kind")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("closure_kind");
                                                        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(&closure_kind)
                                                            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: ClosureSignatures<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let bound_sig =
                self.supplied_sig_of_closure(expr_def_id, decl, closure_kind);
            self.closure_sigs(expr_def_id, bound_sig)
        }
    }
}#[instrument(skip(self, expr_def_id, decl), level = "debug")]
599    fn sig_of_closure_no_expectation(
600        &self,
601        expr_def_id: LocalDefId,
602        decl: &hir::FnDecl<'tcx>,
603        closure_kind: hir::ClosureKind,
604    ) -> ClosureSignatures<'tcx> {
605        let bound_sig = self.supplied_sig_of_closure(expr_def_id, decl, closure_kind);
606
607        self.closure_sigs(expr_def_id, bound_sig)
608    }
609
610    /// Invoked to compute the signature of a closure expression. This
611    /// combines any user-provided type annotations (e.g., `|x: u32|
612    /// -> u32 { .. }`) with the expected signature.
613    ///
614    /// The approach is as follows:
615    ///
616    /// - Let `S` be the (higher-ranked) signature that we derive from the user's annotations.
617    /// - Let `E` be the (higher-ranked) signature that we derive from the expectations, if any.
618    ///   - If we have no expectation `E`, then the signature of the closure is `S`.
619    ///   - Otherwise, the signature of the closure is E. Moreover:
620    ///     - Skolemize the late-bound regions in `E`, yielding `E'`.
621    ///     - Instantiate all the late-bound regions bound in the closure within `S`
622    ///       with fresh (existential) variables, yielding `S'`
623    ///     - Require that `E' = S'`
624    ///       - We could use some kind of subtyping relationship here,
625    ///         I imagine, but equality is easier and works fine for
626    ///         our purposes.
627    ///
628    /// The key intuition here is that the user's types must be valid
629    /// from "the inside" of the closure, but the expectation
630    /// ultimately drives the overall signature.
631    ///
632    /// # Examples
633    ///
634    /// ```ignore (illustrative)
635    /// fn with_closure<F>(_: F)
636    ///   where F: Fn(&u32) -> &u32 { .. }
637    ///
638    /// with_closure(|x: &u32| { ... })
639    /// ```
640    ///
641    /// Here:
642    /// - E would be `fn(&u32) -> &u32`.
643    /// - S would be `fn(&u32) -> ?T`
644    /// - E' is `&'!0 u32 -> &'!0 u32`
645    /// - S' is `&'?0 u32 -> ?T`
646    ///
647    /// S' can be unified with E' with `['?0 = '!0, ?T = &'!10 u32]`.
648    ///
649    /// # Arguments
650    ///
651    /// - `expr_def_id`: the `LocalDefId` of the closure expression
652    /// - `decl`: the HIR declaration of the closure
653    /// - `body`: the body of the closure
654    /// - `expected_sig`: the expected signature (if any). Note that
655    ///   this is missing a binder: that is, there may be late-bound
656    ///   regions with depth 1, which are bound then by the closure.
657    {}
#[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("sig_of_closure_with_expectation",
                                    "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                    ::tracing_core::__macro_support::Option::Some(657u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("closure_kind")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("closure_kind");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("expected_sig")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("expected_sig");
                                                        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(&closure_kind)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expected_sig)
                                                            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: ClosureSignatures<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if expected_sig.sig.c_variadic() != decl.c_variadic() {
                return self.sig_of_closure_no_expectation(expr_def_id, decl,
                        closure_kind);
            } else if expected_sig.sig.skip_binder().inputs_and_output.len()
                    != decl.inputs.len() + 1 {
                return self.sig_of_closure_with_mismatched_number_of_arguments(expr_def_id,
                        decl, expected_sig);
            }
            if !!expected_sig.sig.skip_binder().has_vars_bound_above(ty::INNERMOST)
                {
                ::core::panicking::panic("assertion failed: !expected_sig.sig.skip_binder().has_vars_bound_above(ty::INNERMOST)")
            };
            let bound_sig =
                expected_sig.sig.map_bound(|sig|
                        {
                            let fn_sig_kind =
                                FnSigKind::default().set_abi(ExternAbi::RustCall).set_safety(hir::Safety::Safe).set_c_variadic(sig.c_variadic());
                            self.tcx.mk_fn_sig(sig.inputs().iter().cloned(),
                                sig.output(), fn_sig_kind)
                        });
            let bound_sig = self.tcx.anonymize_bound_vars(bound_sig);
            let closure_sigs = self.closure_sigs(expr_def_id, bound_sig);
            match self.merge_supplied_sig_with_expectation(expr_def_id, decl,
                    closure_kind, closure_sigs) {
                Ok(infer_ok) => self.register_infer_ok_obligations(infer_ok),
                Err(_) =>
                    self.sig_of_closure_no_expectation(expr_def_id, decl,
                        closure_kind),
            }
        }
    }
}#[instrument(skip(self, expr_def_id, decl), level = "debug")]
658    fn sig_of_closure_with_expectation(
659        &self,
660        expr_def_id: LocalDefId,
661        decl: &hir::FnDecl<'tcx>,
662        closure_kind: hir::ClosureKind,
663        expected_sig: ExpectedSig<'tcx>,
664    ) -> ClosureSignatures<'tcx> {
665        // Watch out for some surprises and just ignore the
666        // expectation if things don't see to match up with what we
667        // expect.
668        if expected_sig.sig.c_variadic() != decl.c_variadic() {
669            return self.sig_of_closure_no_expectation(expr_def_id, decl, closure_kind);
670        } else if expected_sig.sig.skip_binder().inputs_and_output.len() != decl.inputs.len() + 1 {
671            return self.sig_of_closure_with_mismatched_number_of_arguments(
672                expr_def_id,
673                decl,
674                expected_sig,
675            );
676        }
677
678        // Create a `PolyFnSig`. Note the oddity that late bound
679        // regions appearing free in `expected_sig` are now bound up
680        // in this binder we are creating.
681        assert!(!expected_sig.sig.skip_binder().has_vars_bound_above(ty::INNERMOST));
682        let bound_sig = expected_sig.sig.map_bound(|sig| {
683            // Ignore splatting, it is unsupported on closures.
684            let fn_sig_kind = FnSigKind::default()
685                .set_abi(ExternAbi::RustCall)
686                .set_safety(hir::Safety::Safe)
687                .set_c_variadic(sig.c_variadic());
688            self.tcx.mk_fn_sig(sig.inputs().iter().cloned(), sig.output(), fn_sig_kind)
689        });
690
691        // `deduce_expectations_from_expected_type` introduces
692        // late-bound lifetimes defined elsewhere, which we now
693        // anonymize away, so as not to confuse the user.
694        let bound_sig = self.tcx.anonymize_bound_vars(bound_sig);
695
696        let closure_sigs = self.closure_sigs(expr_def_id, bound_sig);
697
698        // Up till this point, we have ignored the annotations that the user
699        // gave. This function will check that they unify successfully.
700        // Along the way, it also writes out entries for types that the user
701        // wrote into our typeck results, which are then later used by the privacy
702        // check.
703        match self.merge_supplied_sig_with_expectation(
704            expr_def_id,
705            decl,
706            closure_kind,
707            closure_sigs,
708        ) {
709            Ok(infer_ok) => self.register_infer_ok_obligations(infer_ok),
710            Err(_) => self.sig_of_closure_no_expectation(expr_def_id, decl, closure_kind),
711        }
712    }
713
714    fn sig_of_closure_with_mismatched_number_of_arguments(
715        &self,
716        expr_def_id: LocalDefId,
717        decl: &hir::FnDecl<'tcx>,
718        expected_sig: ExpectedSig<'tcx>,
719    ) -> ClosureSignatures<'tcx> {
720        let expr_map_node = self.tcx.hir_node_by_def_id(expr_def_id);
721        let expected_args: Vec<_> = expected_sig
722            .sig
723            .skip_binder()
724            .inputs()
725            .iter()
726            .map(|ty| ArgKind::from_expected_ty(*ty, None))
727            .collect();
728        let (closure_span, closure_arg_span, found_args) =
729            match self.err_ctxt().get_fn_like_arguments(expr_map_node) {
730                Some((sp, arg_sp, args)) => (Some(sp), arg_sp, args),
731                None => (None, None, Vec::new()),
732            };
733        let expected_span =
734            expected_sig.cause_span.unwrap_or_else(|| self.tcx.def_span(expr_def_id));
735        let guar = self
736            .err_ctxt()
737            .report_arg_count_mismatch(
738                expected_span,
739                closure_span,
740                expected_args,
741                found_args,
742                true,
743                closure_arg_span,
744            )
745            .emit_err();
746
747        let error_sig = self.error_sig_of_closure(decl, guar);
748
749        self.closure_sigs(expr_def_id, error_sig)
750    }
751
752    /// Enforce the user's types against the expectation. See
753    /// `sig_of_closure_with_expectation` for details on the overall
754    /// strategy.
755    {}
#[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("merge_supplied_sig_with_expectation",
                                    "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                    ::tracing_core::__macro_support::Option::Some(755u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("closure_kind")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("closure_kind");
                                                        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(&closure_kind)
                                                            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:
                    InferResult<'tcx, ClosureSignatures<'tcx>> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let supplied_sig =
                self.supplied_sig_of_closure(expr_def_id, decl, closure_kind);
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:769",
                                    "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                    ::tracing_core::__macro_support::Option::Some(769u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("supplied_sig")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("supplied_sig");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&supplied_sig)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            self.commit_if_ok(|_|
                    {
                        let mut all_obligations = PredicateObligations::new();
                        let supplied_sig =
                            self.instantiate_binder_with_fresh_vars(self.tcx.def_span(expr_def_id),
                                BoundRegionConversionTime::FnCall, supplied_sig);
                        for ((hir_ty, &supplied_ty), expected_ty) in
                            iter::zip(iter::zip(decl.inputs, supplied_sig.inputs()),
                                expected_sigs.liberated_sig.inputs()) {
                            let cause = self.misc(hir_ty.span);
                            let InferOk { value: (), obligations } =
                                self.at(&cause,
                                            self.param_env).eq(DefineOpaqueTypes::Yes, *expected_ty,
                                        supplied_ty)?;
                            all_obligations.extend(obligations);
                        }
                        let supplied_output_ty = supplied_sig.output();
                        let cause = &self.misc(decl.output.span());
                        let InferOk { value: (), obligations } =
                            self.at(cause,
                                        self.param_env).eq(DefineOpaqueTypes::Yes,
                                    expected_sigs.liberated_sig.output(), supplied_output_ty)?;
                        all_obligations.extend(obligations);
                        let inputs =
                            supplied_sig.inputs().into_iter().map(|&ty|
                                    self.deeply_resolve_ignoring_regions(ty));
                        let fn_sig_kind =
                            FnSigKind::default().set_abi(ExternAbi::RustCall).set_safety(hir::Safety::Safe).set_c_variadic(expected_sigs.liberated_sig.c_variadic());
                        expected_sigs.liberated_sig =
                            self.tcx.mk_fn_sig(inputs, supplied_output_ty, fn_sig_kind);
                        Ok(InferOk {
                                value: expected_sigs,
                                obligations: all_obligations,
                            })
                    })
        }
    }
}#[instrument(level = "debug", skip(self, expr_def_id, decl, expected_sigs))]
756    fn merge_supplied_sig_with_expectation(
757        &self,
758        expr_def_id: LocalDefId,
759        decl: &hir::FnDecl<'tcx>,
760        closure_kind: hir::ClosureKind,
761        mut expected_sigs: ClosureSignatures<'tcx>,
762    ) -> InferResult<'tcx, ClosureSignatures<'tcx>> {
763        // Get the signature S that the user gave.
764        //
765        // (See comment on `sig_of_closure_with_expectation` for the
766        // meaning of these letters.)
767        let supplied_sig = self.supplied_sig_of_closure(expr_def_id, decl, closure_kind);
768
769        debug!(?supplied_sig);
770
771        // FIXME(#45727): As discussed in [this comment][c1], naively
772        // forcing equality here actually results in suboptimal error
773        // messages in some cases. For now, if there would have been
774        // an obvious error, we fallback to declaring the type of the
775        // closure to be the one the user gave, which allows other
776        // error message code to trigger.
777        //
778        // However, I think [there is potential to do even better
779        // here][c2], since in *this* code we have the precise span of
780        // the type parameter in question in hand when we report the
781        // error.
782        //
783        // [c1]: https://github.com/rust-lang/rust/pull/45072#issuecomment-341089706
784        // [c2]: https://github.com/rust-lang/rust/pull/45072#issuecomment-341096796
785        self.commit_if_ok(|_| {
786            let mut all_obligations = PredicateObligations::new();
787            let supplied_sig = self.instantiate_binder_with_fresh_vars(
788                self.tcx.def_span(expr_def_id),
789                BoundRegionConversionTime::FnCall,
790                supplied_sig,
791            );
792
793            // The liberated version of this signature should be a subtype
794            // of the liberated form of the expectation.
795            for ((hir_ty, &supplied_ty), expected_ty) in iter::zip(
796                iter::zip(decl.inputs, supplied_sig.inputs()),
797                expected_sigs.liberated_sig.inputs(), // `liberated_sig` is E'.
798            ) {
799                // Check that E' = S'.
800                let cause = self.misc(hir_ty.span);
801                let InferOk { value: (), obligations } = self.at(&cause, self.param_env).eq(
802                    DefineOpaqueTypes::Yes,
803                    *expected_ty,
804                    supplied_ty,
805                )?;
806                all_obligations.extend(obligations);
807            }
808
809            let supplied_output_ty = supplied_sig.output();
810            let cause = &self.misc(decl.output.span());
811            let InferOk { value: (), obligations } = self.at(cause, self.param_env).eq(
812                DefineOpaqueTypes::Yes,
813                expected_sigs.liberated_sig.output(),
814                supplied_output_ty,
815            )?;
816            all_obligations.extend(obligations);
817
818            let inputs = supplied_sig
819                .inputs()
820                .into_iter()
821                .map(|&ty| self.deeply_resolve_ignoring_regions(ty));
822
823            let fn_sig_kind = FnSigKind::default()
824                .set_abi(ExternAbi::RustCall)
825                .set_safety(hir::Safety::Safe)
826                .set_c_variadic(expected_sigs.liberated_sig.c_variadic());
827            expected_sigs.liberated_sig =
828                self.tcx.mk_fn_sig(inputs, supplied_output_ty, fn_sig_kind);
829
830            Ok(InferOk { value: expected_sigs, obligations: all_obligations })
831        })
832    }
833
834    /// If there is no expected signature, then we will convert the
835    /// types that the user gave into a signature.
836    ///
837    /// Also, record this closure signature for later.
838    {}
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("supplied_sig_of_closure",
                                "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                ::tracing_core::__macro_support::Option::Some(838u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("expr_def_id")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("expr_def_id");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("closure_kind")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("closure_kind");
                                                    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(&expr_def_id)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&closure_kind)
                                                        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: ty::PolyFnSig<'tcx> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let lowerer = self.lowerer();
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:847",
                                                "rustc_hir_typeck::closure", ::tracing::Level::TRACE,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                                ::tracing_core::__macro_support::Option::Some(847u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                                ::tracing_core::field::FieldSet::new(&["message"],
                                                    ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::TRACE <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::TRACE <=
                                            ::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!("decl = {0:#?}",
                                                                            decl) as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:848",
                                                "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                                ::tracing_core::__macro_support::Option::Some(848u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("closure_kind")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("closure_kind");
                                                                    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(&closure_kind)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let hir_id = self.tcx.local_def_id_to_hir_id(expr_def_id);
                        let bound_vars = self.tcx.late_bound_vars(hir_id);
                        let supplied_arguments =
                            decl.inputs.iter().map(|a| lowerer.lower_ty(a));
                        let supplied_return =
                            match decl.output {
                                hir::FnRetTy::Return(ref output) =>
                                    lowerer.lower_ty(output),
                                hir::FnRetTy::DefaultReturn(_) =>
                                    match closure_kind {
                                        hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async,
                                            hir::CoroutineSource::Fn)) => {
                                            {
                                                use ::tracing::__macro_support::Callsite as _;
                                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                                    {
                                                        static META: ::tracing::Metadata<'static> =
                                                            {
                                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:865",
                                                                    "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                                                    ::tracing_core::__macro_support::Option::Some(865u32),
                                                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                                                    ::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!("closure is async fn body")
                                                                                        as &dyn ::tracing::field::Value))])
                                                        });
                                                } else { ; }
                                            };
                                            self.deduce_future_output_from_obligations(expr_def_id).unwrap_or_else(||
                                                    { lowerer.ty_infer(None, decl.output.span()) })
                                        }
                                        hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen
                                            | hir::CoroutineDesugaring::AsyncGen, _)) =>
                                            self.tcx.types.unit,
                                        hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async,
                                            _)) |
                                            hir::ClosureKind::Coroutine(hir::CoroutineKind::Coroutine(_))
                                            | hir::ClosureKind::Closure |
                                            hir::ClosureKind::CoroutineClosure(_) => {
                                            lowerer.ty_infer(None, decl.output.span())
                                        }
                                    },
                            };
                        let fn_sig_kind =
                            FnSigKind::default().set_abi(ExternAbi::RustCall).set_safety(hir::Safety::Safe).set_c_variadic(decl.c_variadic());
                        let result =
                            ty::Binder::bind_with_vars(self.tcx.mk_fn_sig(supplied_arguments,
                                    supplied_return, fn_sig_kind), bound_vars);
                        let c_result = self.infcx.canonicalize_response(result);
                        self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id,
                            c_result);
                        self.normalize(self.tcx.def_span(expr_def_id),
                            Unnormalized::new_wip(result))
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:838",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(838u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::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(skip(self, decl), level = "debug", ret)]
839    fn supplied_sig_of_closure(
840        &self,
841        expr_def_id: LocalDefId,
842        decl: &hir::FnDecl<'tcx>,
843        closure_kind: hir::ClosureKind,
844    ) -> ty::PolyFnSig<'tcx> {
845        let lowerer = self.lowerer();
846
847        trace!("decl = {:#?}", decl);
848        debug!(?closure_kind);
849
850        let hir_id = self.tcx.local_def_id_to_hir_id(expr_def_id);
851        let bound_vars = self.tcx.late_bound_vars(hir_id);
852
853        // First, convert the types that the user supplied (if any).
854        let supplied_arguments = decl.inputs.iter().map(|a| lowerer.lower_ty(a));
855        let supplied_return = match decl.output {
856            hir::FnRetTy::Return(ref output) => lowerer.lower_ty(output),
857            hir::FnRetTy::DefaultReturn(_) => match closure_kind {
858                // In the case of the async block that we create for a function body,
859                // we expect the return type of the block to match that of the enclosing
860                // function.
861                hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
862                    hir::CoroutineDesugaring::Async,
863                    hir::CoroutineSource::Fn,
864                )) => {
865                    debug!("closure is async fn body");
866                    self.deduce_future_output_from_obligations(expr_def_id).unwrap_or_else(|| {
867                        // AFAIK, deducing the future output
868                        // always succeeds *except* in error cases
869                        // like #65159. I'd like to return Error
870                        // here, but I can't because I can't
871                        // easily (and locally) prove that we
872                        // *have* reported an
873                        // error. --nikomatsakis
874                        lowerer.ty_infer(None, decl.output.span())
875                    })
876                }
877                // All `gen {}` and `async gen {}` must return unit.
878                hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
879                    hir::CoroutineDesugaring::Gen | hir::CoroutineDesugaring::AsyncGen,
880                    _,
881                )) => self.tcx.types.unit,
882
883                // For async blocks, we just fall back to `_` here.
884                // For closures/coroutines, we know nothing about the return
885                // type unless it was supplied.
886                hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
887                    hir::CoroutineDesugaring::Async,
888                    _,
889                ))
890                | hir::ClosureKind::Coroutine(hir::CoroutineKind::Coroutine(_))
891                | hir::ClosureKind::Closure
892                | hir::ClosureKind::CoroutineClosure(_) => {
893                    lowerer.ty_infer(None, decl.output.span())
894                }
895            },
896        };
897
898        let fn_sig_kind = FnSigKind::default()
899            .set_abi(ExternAbi::RustCall)
900            .set_safety(hir::Safety::Safe)
901            .set_c_variadic(decl.c_variadic());
902        let result = ty::Binder::bind_with_vars(
903            self.tcx.mk_fn_sig(supplied_arguments, supplied_return, fn_sig_kind),
904            bound_vars,
905        );
906
907        let c_result = self.infcx.canonicalize_response(result);
908        self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result);
909
910        // Normalize only after registering in `user_provided_sigs`.
911        self.normalize(self.tcx.def_span(expr_def_id), Unnormalized::new_wip(result))
912    }
913
914    /// Invoked when we are translating the coroutine that results
915    /// from desugaring an `async fn`. Returns the "sugared" return
916    /// type of the `async fn` -- that is, the return type that the
917    /// user specified. The "desugared" return type is an `impl
918    /// Future<Output = T>`, so we do this by searching through the
919    /// obligations to extract the `T`.
920    {}
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("deduce_future_output_from_obligations",
                                "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                ::tracing_core::__macro_support::Option::Some(920u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("body_def_id")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("body_def_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(&body_def_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: Option<Ty<'tcx>> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let ret_coercion =
                            self.ret_coercion.as_ref().unwrap_or_else(||
                                    {
                                        ::rustc_span::macros::bug_impl(Some(self.tcx.def_span(body_def_id)),
                                            format_args!("async fn coroutine outside of a fn"),
                                            Location::caller())
                                    });
                        let closure_span = self.tcx.def_span(body_def_id);
                        let ret_ty = ret_coercion.borrow().expected_ty();
                        let ret_ty =
                            self.deeply_resolve_ignoring_regions_with_obligations(ret_ty);
                        let get_future_output =
                            |clause: ty::Clause<'tcx>, span|
                                {
                                    let bound_clause = clause.kind();
                                    if let ty::ClauseKind::Projection(proj_clause) =
                                            bound_clause.skip_binder() {
                                        self.deduce_future_output_from_projection(span,
                                            bound_clause.rebind(proj_clause))
                                    } else { None }
                                };
                        let output_ty =
                            match *ret_ty.kind() {
                                ty::Infer(ty::TyVar(ret_vid)) =>
                                    self.obligations_for_self_ty(ret_vid,
                                                    UseSubtyping::No).into_iter().find_map(|obligation|
                                                {
                                                    obligation.predicate.as_clause().and_then(|clause|
                                                            get_future_output(clause, obligation.cause.span))
                                                })?,
                                ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. }, ..
                                    }) => {
                                    return Some(Ty::new_error_with_message(self.tcx,
                                                closure_span,
                                                "this projection should have been projected to an opaque type"));
                                }
                                ty::Alias(_, ty::AliasTy {
                                    kind: ty::Opaque { def_id }, args, .. }) =>
                                    self.tcx.explicit_item_self_bounds(def_id).iter_instantiated_copied(self.tcx,
                                                    args).map(Unnormalized::skip_norm_wip).find_map(|(c, s)|
                                                get_future_output(c, s))?,
                                ty::Error(_) => return Some(ret_ty),
                                _ => {
                                    ::rustc_span::macros::bug_impl(Some(closure_span),
                                        format_args!("invalid async fn coroutine return type: {0:?}",
                                            ret_ty), Location::caller())
                                }
                            };
                        let output_ty =
                            self.normalize(closure_span,
                                Unnormalized::new_wip(output_ty));
                        let InferOk { value: output_ty, obligations } =
                            self.replace_opaque_types_with_inference_vars(output_ty,
                                body_def_id, closure_span, self.param_env);
                        self.register_predicates(obligations);
                        Some(output_ty)
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:920",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(920u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::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(skip(self), level = "debug", ret)]
921    fn deduce_future_output_from_obligations(&self, body_def_id: LocalDefId) -> Option<Ty<'tcx>> {
922        let ret_coercion = self.ret_coercion.as_ref().unwrap_or_else(|| {
923            span_bug!(self.tcx.def_span(body_def_id), "async fn coroutine outside of a fn")
924        });
925
926        let closure_span = self.tcx.def_span(body_def_id);
927        let ret_ty = ret_coercion.borrow().expected_ty();
928        let ret_ty = self.deeply_resolve_ignoring_regions_with_obligations(ret_ty);
929
930        let get_future_output = |clause: ty::Clause<'tcx>, span| {
931            // Search for a pending obligation like
932            //
933            // `<R as Future>::Output = T`
934            //
935            // where R is the return type we are expecting. This type `T`
936            // will be our output.
937            let bound_clause = clause.kind();
938            if let ty::ClauseKind::Projection(proj_clause) = bound_clause.skip_binder() {
939                self.deduce_future_output_from_projection(span, bound_clause.rebind(proj_clause))
940            } else {
941                None
942            }
943        };
944
945        let output_ty = match *ret_ty.kind() {
946            ty::Infer(ty::TyVar(ret_vid)) => self
947                .obligations_for_self_ty(ret_vid, UseSubtyping::No)
948                .into_iter()
949                .find_map(|obligation| {
950                    obligation
951                        .predicate
952                        .as_clause()
953                        .and_then(|clause| get_future_output(clause, obligation.cause.span))
954                })?,
955            ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. }, .. }) => {
956                return Some(Ty::new_error_with_message(
957                    self.tcx,
958                    closure_span,
959                    "this projection should have been projected to an opaque type",
960                ));
961            }
962            ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => self
963                .tcx
964                .explicit_item_self_bounds(def_id)
965                .iter_instantiated_copied(self.tcx, args)
966                .map(Unnormalized::skip_norm_wip)
967                .find_map(|(c, s)| get_future_output(c, s))?,
968            ty::Error(_) => return Some(ret_ty),
969            _ => {
970                span_bug!(closure_span, "invalid async fn coroutine return type: {ret_ty:?}")
971            }
972        };
973
974        let output_ty = self.normalize(closure_span, Unnormalized::new_wip(output_ty));
975
976        // async fn that have opaque types in their return type need to redo the conversion to inference variables
977        // as they fetch the still opaque version from the signature.
978        let InferOk { value: output_ty, obligations } = self
979            .replace_opaque_types_with_inference_vars(
980                output_ty,
981                body_def_id,
982                closure_span,
983                self.param_env,
984            );
985        self.register_predicates(obligations);
986
987        Some(output_ty)
988    }
989
990    /// Given a projection like
991    ///
992    /// `<X as Future>::Output = T`
993    ///
994    /// where `X` is some type that has no late-bound regions, returns
995    /// `Some(T)`. If the projection is for some other trait, returns
996    /// `None`.
997    fn deduce_future_output_from_projection(
998        &self,
999        cause_span: Span,
1000        predicate: ty::PolyProjectionClause<'tcx>,
1001    ) -> Option<Ty<'tcx>> {
1002        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:1002",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(1002u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::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!("deduce_future_output_from_projection(predicate={0:?})",
                                                    predicate) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("deduce_future_output_from_projection(predicate={:?})", predicate);
1003
1004        // We do not expect any bound regions in our predicate, so
1005        // skip past the bound vars.
1006        let Some(predicate) = predicate.no_bound_vars() else {
1007            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:1007",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(1007u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::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!("deduce_future_output_from_projection: has late-bound regions")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("deduce_future_output_from_projection: has late-bound regions");
1008            return None;
1009        };
1010
1011        // Check that this is a projection from the `Future` trait.
1012        let trait_def_id = predicate.projection_term.trait_def_id(self.tcx);
1013        if !self.tcx.is_lang_item(trait_def_id, LangItem::Future) {
1014            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:1014",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(1014u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::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!("deduce_future_output_from_projection: not a future")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("deduce_future_output_from_projection: not a future");
1015            return None;
1016        }
1017
1018        // The `Future` trait has only one associated item, `Output`,
1019        // so check that this is what we see.
1020        let output_assoc_item = self.tcx.associated_item_def_ids(trait_def_id)[0];
1021        if output_assoc_item != predicate.def_id() {
1022            ::rustc_span::macros::bug_impl(Some(cause_span),
    format_args!("projecting associated item `{0:?}` from future, which is not Output `{1:?}`",
        predicate.projection_term.kind, output_assoc_item),
    Location::caller());span_bug!(
1023                cause_span,
1024                "projecting associated item `{:?}` from future, which is not Output `{:?}`",
1025                predicate.projection_term.kind,
1026                output_assoc_item,
1027            );
1028        }
1029
1030        // Extract the type from the projection. Note that there can
1031        // be no bound variables in this type because the "self type"
1032        // does not have any regions in it.
1033        let output_ty = self.deeply_resolve_ignoring_regions(predicate.term);
1034        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:1034",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(1034u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::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!("deduce_future_output_from_projection: output_ty={0:?}",
                                                    output_ty) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("deduce_future_output_from_projection: output_ty={:?}", output_ty);
1035        // This is a projection on a Fn trait so will always be a type.
1036        Some(output_ty.expect_type())
1037    }
1038
1039    /// Converts the types that the user supplied, in case that doing
1040    /// so should yield an error, but returns back a signature where
1041    /// all parameters are of type `ty::Error`.
1042    fn error_sig_of_closure(
1043        &self,
1044        decl: &hir::FnDecl<'tcx>,
1045        guar: ErrorGuaranteed,
1046    ) -> ty::PolyFnSig<'tcx> {
1047        let lowerer = self.lowerer();
1048        let err_ty = Ty::new_error(self.tcx, guar);
1049
1050        let supplied_arguments = decl.inputs.iter().map(|a| {
1051            // Convert the types that the user supplied (if any), but ignore them.
1052            lowerer.lower_ty(a);
1053            err_ty
1054        });
1055
1056        if let hir::FnRetTy::Return(ref output) = decl.output {
1057            lowerer.lower_ty(output);
1058        }
1059
1060        let fn_sig_kind = FnSigKind::default()
1061            .set_abi(ExternAbi::RustCall)
1062            .set_safety(hir::Safety::Safe)
1063            .set_c_variadic(decl.c_variadic());
1064        let result = ty::Binder::dummy(self.tcx.mk_fn_sig(supplied_arguments, err_ty, fn_sig_kind));
1065
1066        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:1066",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(1066u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::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!("supplied_sig_of_closure: result={0:?}",
                                                    result) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("supplied_sig_of_closure: result={:?}", result);
1067
1068        result
1069    }
1070
1071    {}
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("closure_sigs",
                                "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                                ::tracing_core::__macro_support::Option::Some(1071u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("expr_def_id")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("expr_def_id");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("bound_sig")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("bound_sig");
                                                    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(&expr_def_id)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bound_sig)
                                                        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: ClosureSignatures<'tcx> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let liberated_sig =
                            self.tcx().liberate_late_bound_regions(expr_def_id.to_def_id(),
                                bound_sig);
                        let liberated_sig =
                            self.normalize(self.tcx.def_span(expr_def_id),
                                Unnormalized::new_wip(liberated_sig));
                        ClosureSignatures { bound_sig, liberated_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/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs:1071",
                        "rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/28221559263a3976766cf305940e80e30cf9ba8a/compiler/rustc_hir_typeck/src/closure.rs"),
                        ::tracing_core::__macro_support::Option::Some(1071u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
                        ::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)]
1072    fn closure_sigs(
1073        &self,
1074        expr_def_id: LocalDefId,
1075        bound_sig: ty::PolyFnSig<'tcx>,
1076    ) -> ClosureSignatures<'tcx> {
1077        let liberated_sig =
1078            self.tcx().liberate_late_bound_regions(expr_def_id.to_def_id(), bound_sig);
1079        let liberated_sig =
1080            self.normalize(self.tcx.def_span(expr_def_id), Unnormalized::new_wip(liberated_sig));
1081        ClosureSignatures { bound_sig, liberated_sig }
1082    }
1083}