1use std::iter;
4use std::ops::ControlFlow;
5
6use rustc_abi::ExternAbi;
7use rustc_errors::ErrorGuaranteed;
8use rustc_hir as hir;
9use rustc_hir::attrs::lang_items::LangItem;
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#[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) -> ExpectedSig<'tcx> {
ExpectedSig {
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 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 bound_sig: ty::PolyFnSig<'tcx>,
39 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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:72",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:91",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/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 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 let (closure_ty, coroutine_types) = match closure.kind {
84 hir::ClosureKind::Closure => {
85 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 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 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 let resume_ty = liberated_sig.inputs().get(0).copied().unwrap_or(tcx.types.unit);
155
156 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 (tcx.types.unit, self.infcx.next_ty_var(expr_span))
190 }
191 hir::CoroutineDesugaring::Async => {
192 (bound_sig.skip_binder().output(), tcx.types.unit)
195 }
196 hir::CoroutineDesugaring::AsyncGen => {
197 unimplemented!("`async gen` closures not supported yet")
198 }
199 };
200 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 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 None => self.next_ty_var(expr_span),
241 };
242
243 let coroutine_upvars_ty = self.next_ty_var(expr_span);
244
245 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 false,
282 );
283
284 closure_ty
285 }
286
287 {}
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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:289",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/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 clauses.rev(),
350 )
351 .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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:354",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/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 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 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 self.next_trait_solver()
391 && let Some(inferred_sig) = inferred_sig
392 {
393 let generalized_fnptr_sig = self.next_ty_var(span);
411 let inferred_fnptr_sig = Ty::new_fn_ptr(self.tcx, inferred_sig.sig);
412 self.demand_eqtype(span, inferred_fnptr_sig, generalized_fnptr_sig);
413
414 let resolved_sig = self.deeply_resolve_ignoring_regions(generalized_fnptr_sig);
415
416 if resolved_sig.visit_with(&mut MentionsTy { expected_ty }).is_continue() {
417 expected_sig = Some(ExpectedSig {
418 cause_span: inferred_sig.cause_span,
419 sig: resolved_sig.fn_sig(self.tcx),
420 });
421 }
422 } else {
423 if inferred_sig.visit_with(&mut MentionsTy { expected_ty }).is_continue() {
424 expected_sig = inferred_sig;
425 }
426 }
427 }
428
429 let trait_def_id = match bound_clause.skip_binder() {
434 ty::ClauseKind::Projection(data) => {
435 Some(data.projection_term.trait_def_id(self.tcx))
436 }
437 ty::ClauseKind::Trait(data) => Some(data.def_id()),
438 _ => None,
439 };
440
441 if let Some(trait_def_id) = trait_def_id {
442 let found_kind = match closure_kind {
443 hir::ClosureKind::Closure
444 | hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Gen) => {
447 self.tcx.fn_trait_kind_from_def_id(trait_def_id)
448 }
449 hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async) => self
450 .tcx
451 .async_fn_trait_kind_from_def_id(trait_def_id)
452 .or_else(|| self.tcx.fn_trait_kind_from_def_id(trait_def_id)),
453 _ => None,
454 };
455
456 if let Some(found_kind) = found_kind {
457 match (expected_kind, found_kind) {
459 (None, _) => expected_kind = Some(found_kind),
460 (Some(ClosureKind::FnMut), ClosureKind::Fn) => {
461 expected_kind = Some(ClosureKind::Fn)
462 }
463 (Some(ClosureKind::FnOnce), ClosureKind::Fn | ClosureKind::FnMut) => {
464 expected_kind = Some(found_kind)
465 }
466 _ => {}
467 }
468 }
469 }
470 }
471
472 (expected_sig, expected_kind)
473 }
474
475 {}
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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(481u32),
::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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:481",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(481u32),
::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)]
482 fn deduce_sig_from_projection(
483 &self,
484 cause_span: Option<Span>,
485 closure_kind: hir::ClosureKind,
486 projection: ty::PolyProjectionClause<'tcx>,
487 ) -> Option<ExpectedSig<'tcx>> {
488 let def_id = projection.item_def_id();
489
490 match closure_kind {
493 hir::ClosureKind::Closure if self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) => {
494 self.extract_sig_from_projection(cause_span, projection)
495 }
496 hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
497 if self.tcx.is_lang_item(def_id, LangItem::AsyncFnOnceOutput) =>
498 {
499 self.extract_sig_from_projection(cause_span, projection)
500 }
501 hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
505 if self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) =>
506 {
507 self.extract_sig_from_projection_and_future_bound(cause_span, projection)
508 }
509 _ => None,
510 }
511 }
512
513 fn extract_sig_from_projection(
516 &self,
517 cause_span: Option<Span>,
518 projection: ty::PolyProjectionClause<'tcx>,
519 ) -> Option<ExpectedSig<'tcx>> {
520 let projection = self.deeply_resolve_ignoring_regions(projection);
521
522 let arg_param_ty = projection.skip_binder().projection_term.args.type_at(1);
523 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:523",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(523u32),
::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);
524
525 let ty::Tuple(input_tys) = *arg_param_ty.kind() else {
526 return None;
527 };
528
529 let ret_param_ty = projection.skip_binder().term.expect_type();
531 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:531",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(531u32),
::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);
532
533 let sig = projection.rebind(self.tcx.mk_fn_sig_safe_rust_abi(input_tys, ret_param_ty));
534
535 Some(ExpectedSig { cause_span, sig })
536 }
537
538 fn extract_sig_from_projection_and_future_bound(
561 &self,
562 cause_span: Option<Span>,
563 projection: ty::PolyProjectionClause<'tcx>,
564 ) -> Option<ExpectedSig<'tcx>> {
565 let projection = self.deeply_resolve_ignoring_regions(projection);
566
567 let arg_param_ty = projection.skip_binder().projection_term.args.type_at(1);
568 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:568",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(568u32),
::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);
569
570 let ty::Tuple(input_tys) = *arg_param_ty.kind() else {
571 return None;
572 };
573
574 let ty::Infer(ty::TyVar(return_vid)) = *projection.skip_binder().term.expect_type().kind()
580 else {
581 return None;
582 };
583
584 let mut return_ty = None;
586 for bound in self.obligations_for_self_ty(return_vid, UseSubtyping::No) {
587 if let Some(ret_projection) = bound.predicate.as_projection_clause()
588 && let Some(ret_projection) = ret_projection.no_bound_vars()
589 && self.tcx.is_lang_item(ret_projection.def_id(), LangItem::FutureOutput)
590 {
591 return_ty = Some(ret_projection.term.expect_type());
592 break;
593 }
594 }
595
596 let return_ty =
611 return_ty.unwrap_or_else(|| self.next_ty_var(cause_span.unwrap_or(DUMMY_SP)));
612
613 let sig = projection.rebind(self.tcx.mk_fn_sig_safe_rust_abi(input_tys, return_ty));
614
615 Some(ExpectedSig { cause_span, sig })
616 }
617
618 fn sig_of_closure(
619 &self,
620 expr_def_id: LocalDefId,
621 decl: &hir::FnDecl<'tcx>,
622 closure_kind: hir::ClosureKind,
623 expected_sig: Option<ExpectedSig<'tcx>>,
624 ) -> ClosureSignatures<'tcx> {
625 if let Some(e) = expected_sig {
626 self.sig_of_closure_with_expectation(expr_def_id, decl, closure_kind, e)
627 } else {
628 self.sig_of_closure_no_expectation(expr_def_id, decl, closure_kind)
629 }
630 }
631
632 {}
#[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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(634u32),
::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")]
635 fn sig_of_closure_no_expectation(
636 &self,
637 expr_def_id: LocalDefId,
638 decl: &hir::FnDecl<'tcx>,
639 closure_kind: hir::ClosureKind,
640 ) -> ClosureSignatures<'tcx> {
641 let bound_sig = self.supplied_sig_of_closure(expr_def_id, decl, closure_kind);
642
643 self.closure_sigs(expr_def_id, bound_sig)
644 }
645
646 {}
#[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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(693u32),
::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")]
694 fn sig_of_closure_with_expectation(
695 &self,
696 expr_def_id: LocalDefId,
697 decl: &hir::FnDecl<'tcx>,
698 closure_kind: hir::ClosureKind,
699 expected_sig: ExpectedSig<'tcx>,
700 ) -> ClosureSignatures<'tcx> {
701 if expected_sig.sig.c_variadic() != decl.c_variadic() {
705 return self.sig_of_closure_no_expectation(expr_def_id, decl, closure_kind);
706 } else if expected_sig.sig.skip_binder().inputs_and_output.len() != decl.inputs.len() + 1 {
707 return self.sig_of_closure_with_mismatched_number_of_arguments(
708 expr_def_id,
709 decl,
710 expected_sig,
711 );
712 }
713
714 assert!(!expected_sig.sig.skip_binder().has_vars_bound_above(ty::INNERMOST));
718 let bound_sig = expected_sig.sig.map_bound(|sig| {
719 let fn_sig_kind = FnSigKind::default()
721 .set_abi(ExternAbi::RustCall)
722 .set_safety(hir::Safety::Safe)
723 .set_c_variadic(sig.c_variadic());
724 self.tcx.mk_fn_sig(sig.inputs().iter().cloned(), sig.output(), fn_sig_kind)
725 });
726
727 let bound_sig = self.tcx.anonymize_bound_vars(bound_sig);
731
732 let closure_sigs = self.closure_sigs(expr_def_id, bound_sig);
733
734 match self.merge_supplied_sig_with_expectation(
740 expr_def_id,
741 decl,
742 closure_kind,
743 closure_sigs,
744 ) {
745 Ok(infer_ok) => self.register_infer_ok_obligations(infer_ok),
746 Err(_) => self.sig_of_closure_no_expectation(expr_def_id, decl, closure_kind),
747 }
748 }
749
750 fn sig_of_closure_with_mismatched_number_of_arguments(
751 &self,
752 expr_def_id: LocalDefId,
753 decl: &hir::FnDecl<'tcx>,
754 expected_sig: ExpectedSig<'tcx>,
755 ) -> ClosureSignatures<'tcx> {
756 let expr_map_node = self.tcx.hir_node_by_def_id(expr_def_id);
757 let expected_args: Vec<_> = expected_sig
758 .sig
759 .skip_binder()
760 .inputs()
761 .iter()
762 .map(|ty| ArgKind::from_expected_ty(*ty, None))
763 .collect();
764 let (closure_span, closure_arg_span, found_args) =
765 match self.err_ctxt().get_fn_like_arguments(expr_map_node) {
766 Some((sp, arg_sp, args)) => (Some(sp), arg_sp, args),
767 None => (None, None, Vec::new()),
768 };
769 let expected_span =
770 expected_sig.cause_span.unwrap_or_else(|| self.tcx.def_span(expr_def_id));
771 let guar = self
772 .err_ctxt()
773 .report_arg_count_mismatch(
774 expected_span,
775 closure_span,
776 expected_args,
777 found_args,
778 true,
779 closure_arg_span,
780 )
781 .emit();
782
783 let error_sig = self.error_sig_of_closure(decl, guar);
784
785 self.closure_sigs(expr_def_id, error_sig)
786 }
787
788 {}
#[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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(791u32),
::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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:805",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(805u32),
::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))]
792 fn merge_supplied_sig_with_expectation(
793 &self,
794 expr_def_id: LocalDefId,
795 decl: &hir::FnDecl<'tcx>,
796 closure_kind: hir::ClosureKind,
797 mut expected_sigs: ClosureSignatures<'tcx>,
798 ) -> InferResult<'tcx, ClosureSignatures<'tcx>> {
799 let supplied_sig = self.supplied_sig_of_closure(expr_def_id, decl, closure_kind);
804
805 debug!(?supplied_sig);
806
807 self.commit_if_ok(|_| {
822 let mut all_obligations = PredicateObligations::new();
823 let supplied_sig = self.instantiate_binder_with_fresh_vars(
824 self.tcx.def_span(expr_def_id),
825 BoundRegionConversionTime::FnCall,
826 supplied_sig,
827 );
828
829 for ((hir_ty, &supplied_ty), expected_ty) in iter::zip(
832 iter::zip(decl.inputs, supplied_sig.inputs()),
833 expected_sigs.liberated_sig.inputs(), ) {
835 let cause = self.misc(hir_ty.span);
837 let InferOk { value: (), obligations } = self.at(&cause, self.param_env).eq(
838 DefineOpaqueTypes::Yes,
839 *expected_ty,
840 supplied_ty,
841 )?;
842 all_obligations.extend(obligations);
843 }
844
845 let supplied_output_ty = supplied_sig.output();
846 let cause = &self.misc(decl.output.span());
847 let InferOk { value: (), obligations } = self.at(cause, self.param_env).eq(
848 DefineOpaqueTypes::Yes,
849 expected_sigs.liberated_sig.output(),
850 supplied_output_ty,
851 )?;
852 all_obligations.extend(obligations);
853
854 let inputs = supplied_sig
855 .inputs()
856 .into_iter()
857 .map(|&ty| self.deeply_resolve_ignoring_regions(ty));
858
859 let fn_sig_kind = FnSigKind::default()
860 .set_abi(ExternAbi::RustCall)
861 .set_safety(hir::Safety::Safe)
862 .set_c_variadic(expected_sigs.liberated_sig.c_variadic());
863 expected_sigs.liberated_sig =
864 self.tcx.mk_fn_sig(inputs, supplied_output_ty, fn_sig_kind);
865
866 Ok(InferOk { value: expected_sigs, obligations: all_obligations })
867 })
868 }
869
870 {}
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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(874u32),
::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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:883",
"rustc_hir_typeck::closure", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(883u32),
::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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:884",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(884u32),
::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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:901",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(901u32),
::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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:874",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(874u32),
::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)]
875 fn supplied_sig_of_closure(
876 &self,
877 expr_def_id: LocalDefId,
878 decl: &hir::FnDecl<'tcx>,
879 closure_kind: hir::ClosureKind,
880 ) -> ty::PolyFnSig<'tcx> {
881 let lowerer = self.lowerer();
882
883 trace!("decl = {:#?}", decl);
884 debug!(?closure_kind);
885
886 let hir_id = self.tcx.local_def_id_to_hir_id(expr_def_id);
887 let bound_vars = self.tcx.late_bound_vars(hir_id);
888
889 let supplied_arguments = decl.inputs.iter().map(|a| lowerer.lower_ty(a));
891 let supplied_return = match decl.output {
892 hir::FnRetTy::Return(ref output) => lowerer.lower_ty(output),
893 hir::FnRetTy::DefaultReturn(_) => match closure_kind {
894 hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
898 hir::CoroutineDesugaring::Async,
899 hir::CoroutineSource::Fn,
900 )) => {
901 debug!("closure is async fn body");
902 self.deduce_future_output_from_obligations(expr_def_id).unwrap_or_else(|| {
903 lowerer.ty_infer(None, decl.output.span())
911 })
912 }
913 hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
915 hir::CoroutineDesugaring::Gen | hir::CoroutineDesugaring::AsyncGen,
916 _,
917 )) => self.tcx.types.unit,
918
919 hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
923 hir::CoroutineDesugaring::Async,
924 _,
925 ))
926 | hir::ClosureKind::Coroutine(hir::CoroutineKind::Coroutine(_))
927 | hir::ClosureKind::Closure
928 | hir::ClosureKind::CoroutineClosure(_) => {
929 lowerer.ty_infer(None, decl.output.span())
930 }
931 },
932 };
933
934 let fn_sig_kind = FnSigKind::default()
935 .set_abi(ExternAbi::RustCall)
936 .set_safety(hir::Safety::Safe)
937 .set_c_variadic(decl.c_variadic());
938 let result = ty::Binder::bind_with_vars(
939 self.tcx.mk_fn_sig(supplied_arguments, supplied_return, fn_sig_kind),
940 bound_vars,
941 );
942
943 let c_result = self.infcx.canonicalize_response(result);
944 self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result);
945
946 self.normalize(self.tcx.def_span(expr_def_id), Unnormalized::new_wip(result))
948 }
949
950 {}
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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(956u32),
::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(||
{
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),
_ => {
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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:956",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(956u32),
::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)]
957 fn deduce_future_output_from_obligations(&self, body_def_id: LocalDefId) -> Option<Ty<'tcx>> {
958 let ret_coercion = self.ret_coercion.as_ref().unwrap_or_else(|| {
959 span_bug!(self.tcx.def_span(body_def_id), "async fn coroutine outside of a fn")
960 });
961
962 let closure_span = self.tcx.def_span(body_def_id);
963 let ret_ty = ret_coercion.borrow().expected_ty();
964 let ret_ty = self.deeply_resolve_ignoring_regions_with_obligations(ret_ty);
965
966 let get_future_output = |clause: ty::Clause<'tcx>, span| {
967 let bound_clause = clause.kind();
974 if let ty::ClauseKind::Projection(proj_clause) = bound_clause.skip_binder() {
975 self.deduce_future_output_from_projection(span, bound_clause.rebind(proj_clause))
976 } else {
977 None
978 }
979 };
980
981 let output_ty = match *ret_ty.kind() {
982 ty::Infer(ty::TyVar(ret_vid)) => self
983 .obligations_for_self_ty(ret_vid, UseSubtyping::No)
984 .into_iter()
985 .find_map(|obligation| {
986 obligation
987 .predicate
988 .as_clause()
989 .and_then(|clause| get_future_output(clause, obligation.cause.span))
990 })?,
991 ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. }, .. }) => {
992 return Some(Ty::new_error_with_message(
993 self.tcx,
994 closure_span,
995 "this projection should have been projected to an opaque type",
996 ));
997 }
998 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => self
999 .tcx
1000 .explicit_item_self_bounds(def_id)
1001 .iter_instantiated_copied(self.tcx, args)
1002 .map(Unnormalized::skip_norm_wip)
1003 .find_map(|(c, s)| get_future_output(c, s))?,
1004 ty::Error(_) => return Some(ret_ty),
1005 _ => {
1006 span_bug!(closure_span, "invalid async fn coroutine return type: {ret_ty:?}")
1007 }
1008 };
1009
1010 let output_ty = self.normalize(closure_span, Unnormalized::new_wip(output_ty));
1011
1012 let InferOk { value: output_ty, obligations } = self
1015 .replace_opaque_types_with_inference_vars(
1016 output_ty,
1017 body_def_id,
1018 closure_span,
1019 self.param_env,
1020 );
1021 self.register_predicates(obligations);
1022
1023 Some(output_ty)
1024 }
1025
1026 fn deduce_future_output_from_projection(
1034 &self,
1035 cause_span: Span,
1036 predicate: ty::PolyProjectionClause<'tcx>,
1037 ) -> Option<Ty<'tcx>> {
1038 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:1038",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1038u32),
::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);
1039
1040 let Some(predicate) = predicate.no_bound_vars() else {
1043 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:1043",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1043u32),
::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");
1044 return None;
1045 };
1046
1047 let trait_def_id = predicate.projection_term.trait_def_id(self.tcx);
1049 if !self.tcx.is_lang_item(trait_def_id, LangItem::Future) {
1050 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:1050",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1050u32),
::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");
1051 return None;
1052 }
1053
1054 let output_assoc_item = self.tcx.associated_item_def_ids(trait_def_id)[0];
1057 if output_assoc_item != predicate.def_id() {
1058 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!(
1059 cause_span,
1060 "projecting associated item `{:?}` from future, which is not Output `{:?}`",
1061 predicate.projection_term.kind,
1062 output_assoc_item,
1063 );
1064 }
1065
1066 let output_ty = self.deeply_resolve_ignoring_regions(predicate.term);
1070 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:1070",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1070u32),
::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);
1071 Some(output_ty.expect_type())
1073 }
1074
1075 fn error_sig_of_closure(
1079 &self,
1080 decl: &hir::FnDecl<'tcx>,
1081 guar: ErrorGuaranteed,
1082 ) -> ty::PolyFnSig<'tcx> {
1083 let lowerer = self.lowerer();
1084 let err_ty = Ty::new_error(self.tcx, guar);
1085
1086 let supplied_arguments = decl.inputs.iter().map(|a| {
1087 lowerer.lower_ty(a);
1089 err_ty
1090 });
1091
1092 if let hir::FnRetTy::Return(ref output) = decl.output {
1093 lowerer.lower_ty(output);
1094 }
1095
1096 let fn_sig_kind = FnSigKind::default()
1097 .set_abi(ExternAbi::RustCall)
1098 .set_safety(hir::Safety::Safe)
1099 .set_c_variadic(decl.c_variadic());
1100 let result = ty::Binder::dummy(self.tcx.mk_fn_sig(supplied_arguments, err_ty, fn_sig_kind));
1101
1102 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:1102",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1102u32),
::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);
1103
1104 result
1105 }
1106
1107 {}
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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1107u32),
::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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs:1107",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1107u32),
::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)]
1108 fn closure_sigs(
1109 &self,
1110 expr_def_id: LocalDefId,
1111 bound_sig: ty::PolyFnSig<'tcx>,
1112 ) -> ClosureSignatures<'tcx> {
1113 let liberated_sig =
1114 self.tcx().liberate_late_bound_regions(expr_def_id.to_def_id(), bound_sig);
1115 let liberated_sig =
1116 self.normalize(self.tcx.def_span(expr_def_id), Unnormalized::new_wip(liberated_sig));
1117 ClosureSignatures { bound_sig, liberated_sig }
1118 }
1119}