1use std::iter;
4use std::ops::ControlFlow;
5
6use rustc_abi::ExternAbi;
7use rustc_attr_ir::lang_items::LangItem;
8use rustc_errors::ErrorGuaranteed;
9use rustc_hir as hir;
10use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
11use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, InferResult};
12use rustc_infer::traits::{ObligationCauseCode, PredicateObligations};
13use rustc_macros::{TypeFoldable, TypeVisitable};
14use rustc_middle::ty::{
15 self, ClosureKind, FnSigKind, GenericArgs, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
16 TypeVisitableExt, TypeVisitor, Unnormalized,
17};
18use rustc_span::def_id::LocalDefId;
19use rustc_span::{DUMMY_SP, Span, span_bug};
20use rustc_trait_selection::error_reporting::traits::ArgKind;
21use rustc_trait_selection::traits;
22use tracing::{debug, instrument, trace};
23
24use super::{CoroutineTypes, Expectation, FnCtxt, check_fn};
25use crate::fn_ctxt::UseSubtyping;
26
27#[derive(#[automatically_derived]impl<'tcx> ::core::fmt::Debug for ExpectedSig<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "ExpectedSig",
"cause_span", &self.cause_span, "sig", &&self.sig)
}
}Debug, #[automatically_derived]impl<'tcx> ::core::clone::Clone for ExpectedSig<'tcx>
{
#[inline]
fn clone(&self) -> Self {
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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:72",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:91",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:289",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:354",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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 inferred_sig.visit_with(&mut MentionsTy { expected_ty }).is_continue() {
389 expected_sig = inferred_sig;
390 }
391 }
392
393 let trait_def_id = match bound_clause.skip_binder() {
398 ty::ClauseKind::Projection(data) => {
399 Some(data.projection_term.trait_def_id(self.tcx))
400 }
401 ty::ClauseKind::Trait(data) => Some(data.def_id()),
402 _ => None,
403 };
404
405 if let Some(trait_def_id) = trait_def_id {
406 let found_kind = match closure_kind {
407 hir::ClosureKind::Closure
408 | hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Gen) => {
411 self.tcx.fn_trait_kind_from_def_id(trait_def_id)
412 }
413 hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async) => self
414 .tcx
415 .async_fn_trait_kind_from_def_id(trait_def_id)
416 .or_else(|| self.tcx.fn_trait_kind_from_def_id(trait_def_id)),
417 _ => None,
418 };
419
420 if let Some(found_kind) = found_kind {
421 match (expected_kind, found_kind) {
423 (None, _) => expected_kind = Some(found_kind),
424 (Some(ClosureKind::FnMut), ClosureKind::Fn) => {
425 expected_kind = Some(ClosureKind::Fn)
426 }
427 (Some(ClosureKind::FnOnce), ClosureKind::Fn | ClosureKind::FnMut) => {
428 expected_kind = Some(found_kind)
429 }
430 _ => {}
431 }
432 }
433 }
434 }
435
436 (expected_sig, expected_kind)
437 }
438
439 {}
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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(445u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("closure_kind")
}> =
::tracing::__macro_support::FieldName::new("closure_kind");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("projection")
}> =
::tracing::__macro_support::FieldName::new("projection");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&closure_kind)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&projection)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy
:: needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Option<ExpectedSig<'tcx>> =
loop {};
return __tracing_attr_fake_return;
}
{
let def_id = projection.item_def_id();
match closure_kind {
hir::ClosureKind::Closure if
self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) => {
self.extract_sig_from_projection(cause_span, projection)
}
hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
if
self.tcx.is_lang_item(def_id, LangItem::AsyncFnOnceOutput)
=> {
self.extract_sig_from_projection(cause_span, projection)
}
hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
if self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) =>
{
self.extract_sig_from_projection_and_future_bound(cause_span,
projection)
}
_ => None,
}
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:445",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(445u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self, cause_span), ret)]
446 fn deduce_sig_from_projection(
447 &self,
448 cause_span: Option<Span>,
449 closure_kind: hir::ClosureKind,
450 projection: ty::PolyProjectionClause<'tcx>,
451 ) -> Option<ExpectedSig<'tcx>> {
452 let def_id = projection.item_def_id();
453
454 match closure_kind {
457 hir::ClosureKind::Closure if self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) => {
458 self.extract_sig_from_projection(cause_span, projection)
459 }
460 hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
461 if self.tcx.is_lang_item(def_id, LangItem::AsyncFnOnceOutput) =>
462 {
463 self.extract_sig_from_projection(cause_span, projection)
464 }
465 hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
469 if self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) =>
470 {
471 self.extract_sig_from_projection_and_future_bound(cause_span, projection)
472 }
473 _ => None,
474 }
475 }
476
477 fn extract_sig_from_projection(
480 &self,
481 cause_span: Option<Span>,
482 projection: ty::PolyProjectionClause<'tcx>,
483 ) -> Option<ExpectedSig<'tcx>> {
484 if projection.has_non_region_bound_vars() {
487 return None;
488 }
489 let projection = self.deeply_resolve_ignoring_regions(projection);
490 let arg_param_ty = projection.skip_binder().projection_term.args.type_at(1);
491 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:491",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(491u32),
::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);
492
493 let ty::Tuple(input_tys) = *arg_param_ty.kind() else {
494 return None;
495 };
496
497 let ret_param_ty = projection.skip_binder().term.expect_type();
499 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:499",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(499u32),
::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);
500
501 let sig = projection.rebind(self.tcx.mk_fn_sig_safe_rust_abi(input_tys, ret_param_ty));
502
503 Some(ExpectedSig { cause_span, sig })
504 }
505
506 fn extract_sig_from_projection_and_future_bound(
529 &self,
530 cause_span: Option<Span>,
531 projection: ty::PolyProjectionClause<'tcx>,
532 ) -> Option<ExpectedSig<'tcx>> {
533 if projection.has_non_region_bound_vars() {
536 return None;
537 }
538 let projection = self.deeply_resolve_ignoring_regions(projection);
539
540 let arg_param_ty = projection.skip_binder().projection_term.args.type_at(1);
541 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:541",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(541u32),
::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);
542
543 let ty::Tuple(input_tys) = *arg_param_ty.kind() else {
544 return None;
545 };
546
547 let ty::Infer(ty::TyVar(return_vid)) = *projection.skip_binder().term.expect_type().kind()
553 else {
554 return None;
555 };
556
557 let mut return_ty = None;
559 for bound in self.obligations_for_self_ty(return_vid, UseSubtyping::No) {
560 if let Some(ret_projection) = bound.predicate.as_projection_clause()
561 && let Some(ret_projection) = ret_projection.no_bound_vars()
562 && self.tcx.is_lang_item(ret_projection.def_id(), LangItem::FutureOutput)
563 {
564 return_ty = Some(ret_projection.term.expect_type());
565 break;
566 }
567 }
568
569 let return_ty =
584 return_ty.unwrap_or_else(|| self.next_ty_var(cause_span.unwrap_or(DUMMY_SP)));
585
586 let sig = projection.rebind(self.tcx.mk_fn_sig_safe_rust_abi(input_tys, return_ty));
587
588 Some(ExpectedSig { cause_span, sig })
589 }
590
591 fn sig_of_closure(
592 &self,
593 expr_def_id: LocalDefId,
594 decl: &hir::FnDecl<'tcx>,
595 closure_kind: hir::ClosureKind,
596 expected_sig: Option<ExpectedSig<'tcx>>,
597 ) -> ClosureSignatures<'tcx> {
598 if let Some(e) = expected_sig {
599 self.sig_of_closure_with_expectation(expr_def_id, decl, closure_kind, e)
600 } else {
601 self.sig_of_closure_no_expectation(expr_def_id, decl, closure_kind)
602 }
603 }
604
605 {}
#[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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(607u32),
::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")]
608 fn sig_of_closure_no_expectation(
609 &self,
610 expr_def_id: LocalDefId,
611 decl: &hir::FnDecl<'tcx>,
612 closure_kind: hir::ClosureKind,
613 ) -> ClosureSignatures<'tcx> {
614 let bound_sig = self.supplied_sig_of_closure(expr_def_id, decl, closure_kind);
615
616 self.closure_sigs(expr_def_id, bound_sig)
617 }
618
619 {}
#[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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(666u32),
::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() ||
expected_sig.sig.has_non_region_bound_vars() {
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")]
667 fn sig_of_closure_with_expectation(
668 &self,
669 expr_def_id: LocalDefId,
670 decl: &hir::FnDecl<'tcx>,
671 closure_kind: hir::ClosureKind,
672 expected_sig: ExpectedSig<'tcx>,
673 ) -> ClosureSignatures<'tcx> {
674 if expected_sig.sig.c_variadic() != decl.c_variadic()
681 || expected_sig.sig.has_non_region_bound_vars()
682 {
683 return self.sig_of_closure_no_expectation(expr_def_id, decl, closure_kind);
684 } else if expected_sig.sig.skip_binder().inputs_and_output.len() != decl.inputs.len() + 1 {
685 return self.sig_of_closure_with_mismatched_number_of_arguments(
686 expr_def_id,
687 decl,
688 expected_sig,
689 );
690 }
691
692 assert!(!expected_sig.sig.skip_binder().has_vars_bound_above(ty::INNERMOST));
696 let bound_sig = expected_sig.sig.map_bound(|sig| {
697 let fn_sig_kind = FnSigKind::default()
699 .set_abi(ExternAbi::RustCall)
700 .set_safety(hir::Safety::Safe)
701 .set_c_variadic(sig.c_variadic());
702 self.tcx.mk_fn_sig(sig.inputs().iter().cloned(), sig.output(), fn_sig_kind)
703 });
704
705 let bound_sig = self.tcx.anonymize_bound_vars(bound_sig);
709
710 let closure_sigs = self.closure_sigs(expr_def_id, bound_sig);
711
712 match self.merge_supplied_sig_with_expectation(
718 expr_def_id,
719 decl,
720 closure_kind,
721 closure_sigs,
722 ) {
723 Ok(infer_ok) => self.register_infer_ok_obligations(infer_ok),
724 Err(_) => self.sig_of_closure_no_expectation(expr_def_id, decl, closure_kind),
725 }
726 }
727
728 fn sig_of_closure_with_mismatched_number_of_arguments(
729 &self,
730 expr_def_id: LocalDefId,
731 decl: &hir::FnDecl<'tcx>,
732 expected_sig: ExpectedSig<'tcx>,
733 ) -> ClosureSignatures<'tcx> {
734 let expr_map_node = self.tcx.hir_node_by_def_id(expr_def_id);
735 let expected_args: Vec<_> = expected_sig
736 .sig
737 .skip_binder()
738 .inputs()
739 .iter()
740 .map(|ty| ArgKind::from_expected_ty(*ty, None))
741 .collect();
742 let (closure_span, closure_arg_span, found_args) =
743 match self.err_ctxt().get_fn_like_arguments(expr_map_node) {
744 Some((sp, arg_sp, args)) => (Some(sp), arg_sp, args),
745 None => (None, None, Vec::new()),
746 };
747 let expected_span =
748 expected_sig.cause_span.unwrap_or_else(|| self.tcx.def_span(expr_def_id));
749 let guar = self
750 .err_ctxt()
751 .report_arg_count_mismatch(
752 expected_span,
753 closure_span,
754 expected_args,
755 found_args,
756 true,
757 closure_arg_span,
758 )
759 .emit_err();
760
761 let error_sig = self.error_sig_of_closure(decl, guar);
762
763 self.closure_sigs(expr_def_id, error_sig)
764 }
765
766 {}
#[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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(769u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:783",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(783u32),
::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))]
770 fn merge_supplied_sig_with_expectation(
771 &self,
772 expr_def_id: LocalDefId,
773 decl: &hir::FnDecl<'tcx>,
774 closure_kind: hir::ClosureKind,
775 mut expected_sigs: ClosureSignatures<'tcx>,
776 ) -> InferResult<'tcx, ClosureSignatures<'tcx>> {
777 let supplied_sig = self.supplied_sig_of_closure(expr_def_id, decl, closure_kind);
782
783 debug!(?supplied_sig);
784
785 self.commit_if_ok(|_| {
800 let mut all_obligations = PredicateObligations::new();
801 let supplied_sig = self.instantiate_binder_with_fresh_vars(
802 self.tcx.def_span(expr_def_id),
803 BoundRegionConversionTime::FnCall,
804 supplied_sig,
805 );
806
807 for ((hir_ty, &supplied_ty), expected_ty) in iter::zip(
810 iter::zip(decl.inputs, supplied_sig.inputs()),
811 expected_sigs.liberated_sig.inputs(), ) {
813 let cause = self.misc(hir_ty.span);
815 let InferOk { value: (), obligations } = self.at(&cause, self.param_env).eq(
816 DefineOpaqueTypes::Yes,
817 *expected_ty,
818 supplied_ty,
819 )?;
820 all_obligations.extend(obligations);
821 }
822
823 let supplied_output_ty = supplied_sig.output();
824 let cause = &self.misc(decl.output.span());
825 let InferOk { value: (), obligations } = self.at(cause, self.param_env).eq(
826 DefineOpaqueTypes::Yes,
827 expected_sigs.liberated_sig.output(),
828 supplied_output_ty,
829 )?;
830 all_obligations.extend(obligations);
831
832 let inputs = supplied_sig
833 .inputs()
834 .into_iter()
835 .map(|&ty| self.deeply_resolve_ignoring_regions(ty));
836
837 let fn_sig_kind = FnSigKind::default()
838 .set_abi(ExternAbi::RustCall)
839 .set_safety(hir::Safety::Safe)
840 .set_c_variadic(expected_sigs.liberated_sig.c_variadic());
841 expected_sigs.liberated_sig =
842 self.tcx.mk_fn_sig(inputs, supplied_output_ty, fn_sig_kind);
843
844 Ok(InferOk { value: expected_sigs, obligations: all_obligations })
845 })
846 }
847
848 {}
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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(852u32),
::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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:861",
"rustc_hir_typeck::closure", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(861u32),
::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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:862",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(862u32),
::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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:879",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(879u32),
::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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:852",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(852u32),
::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)]
853 fn supplied_sig_of_closure(
854 &self,
855 expr_def_id: LocalDefId,
856 decl: &hir::FnDecl<'tcx>,
857 closure_kind: hir::ClosureKind,
858 ) -> ty::PolyFnSig<'tcx> {
859 let lowerer = self.lowerer();
860
861 trace!("decl = {:#?}", decl);
862 debug!(?closure_kind);
863
864 let hir_id = self.tcx.local_def_id_to_hir_id(expr_def_id);
865 let bound_vars = self.tcx.late_bound_vars(hir_id);
866
867 let supplied_arguments = decl.inputs.iter().map(|a| lowerer.lower_ty(a));
869 let supplied_return = match decl.output {
870 hir::FnRetTy::Return(ref output) => lowerer.lower_ty(output),
871 hir::FnRetTy::DefaultReturn(_) => match closure_kind {
872 hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
876 hir::CoroutineDesugaring::Async,
877 hir::CoroutineSource::Fn,
878 )) => {
879 debug!("closure is async fn body");
880 self.deduce_future_output_from_obligations(expr_def_id).unwrap_or_else(|| {
881 lowerer.ty_infer(None, decl.output.span())
889 })
890 }
891 hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
893 hir::CoroutineDesugaring::Gen | hir::CoroutineDesugaring::AsyncGen,
894 _,
895 )) => self.tcx.types.unit,
896
897 hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
901 hir::CoroutineDesugaring::Async,
902 _,
903 ))
904 | hir::ClosureKind::Coroutine(hir::CoroutineKind::Coroutine(_))
905 | hir::ClosureKind::Closure
906 | hir::ClosureKind::CoroutineClosure(_) => {
907 lowerer.ty_infer(None, decl.output.span())
908 }
909 },
910 };
911
912 let fn_sig_kind = FnSigKind::default()
913 .set_abi(ExternAbi::RustCall)
914 .set_safety(hir::Safety::Safe)
915 .set_c_variadic(decl.c_variadic());
916 let result = ty::Binder::bind_with_vars(
917 self.tcx.mk_fn_sig(supplied_arguments, supplied_return, fn_sig_kind),
918 bound_vars,
919 );
920
921 let c_result = self.infcx.canonicalize_response(result);
922 self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result);
923
924 self.normalize(self.tcx.def_span(expr_def_id), Unnormalized::new_wip(result))
926 }
927
928 {}
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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(934u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::closure"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("body_def_id")
}> =
::tracing::__macro_support::FieldName::new("body_def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&body_def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy
:: needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Option<Ty<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
let ret_coercion =
self.ret_coercion.as_ref().unwrap_or_else(||
{
::rustc_span::macros::bug_impl(Some(self.tcx.def_span(body_def_id)),
format_args!("async fn coroutine outside of a fn"),
Location::caller())
});
let closure_span = self.tcx.def_span(body_def_id);
let ret_ty = ret_coercion.borrow().expected_ty();
let ret_ty =
self.deeply_resolve_ignoring_regions_with_obligations(ret_ty);
let get_future_output =
|clause: ty::Clause<'tcx>, span|
{
let bound_clause = clause.kind();
if let ty::ClauseKind::Projection(proj_clause) =
bound_clause.skip_binder() {
self.deduce_future_output_from_projection(span,
bound_clause.rebind(proj_clause))
} else { None }
};
let output_ty =
match *ret_ty.kind() {
ty::Infer(ty::TyVar(ret_vid)) =>
self.obligations_for_self_ty(ret_vid,
UseSubtyping::No).into_iter().find_map(|obligation|
{
obligation.predicate.as_clause().and_then(|clause|
get_future_output(clause, obligation.cause.span))
})?,
ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. }, ..
}) => {
return Some(Ty::new_error_with_message(self.tcx,
closure_span,
"this projection should have been projected to an opaque type"));
}
ty::Alias(_, ty::AliasTy {
kind: ty::Opaque { def_id }, args, .. }) =>
self.tcx.explicit_item_self_bounds(def_id).iter_instantiated_copied(self.tcx,
args).map(Unnormalized::skip_norm_wip).find_map(|(c, s)|
get_future_output(c, s))?,
ty::Error(_) => return Some(ret_ty),
_ => {
::rustc_span::macros::bug_impl(Some(closure_span),
format_args!("invalid async fn coroutine return type: {0:?}",
ret_ty), Location::caller())
}
};
let output_ty =
self.normalize(closure_span,
Unnormalized::new_wip(output_ty));
let InferOk { value: output_ty, obligations } =
self.replace_opaque_types_with_inference_vars(output_ty,
body_def_id, closure_span, self.param_env);
self.register_predicates(obligations);
Some(output_ty)
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:934",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(934u32),
::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)]
935 fn deduce_future_output_from_obligations(&self, body_def_id: LocalDefId) -> Option<Ty<'tcx>> {
936 let ret_coercion = self.ret_coercion.as_ref().unwrap_or_else(|| {
937 span_bug!(self.tcx.def_span(body_def_id), "async fn coroutine outside of a fn")
938 });
939
940 let closure_span = self.tcx.def_span(body_def_id);
941 let ret_ty = ret_coercion.borrow().expected_ty();
942 let ret_ty = self.deeply_resolve_ignoring_regions_with_obligations(ret_ty);
943
944 let get_future_output = |clause: ty::Clause<'tcx>, span| {
945 let bound_clause = clause.kind();
952 if let ty::ClauseKind::Projection(proj_clause) = bound_clause.skip_binder() {
953 self.deduce_future_output_from_projection(span, bound_clause.rebind(proj_clause))
954 } else {
955 None
956 }
957 };
958
959 let output_ty = match *ret_ty.kind() {
960 ty::Infer(ty::TyVar(ret_vid)) => self
961 .obligations_for_self_ty(ret_vid, UseSubtyping::No)
962 .into_iter()
963 .find_map(|obligation| {
964 obligation
965 .predicate
966 .as_clause()
967 .and_then(|clause| get_future_output(clause, obligation.cause.span))
968 })?,
969 ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. }, .. }) => {
970 return Some(Ty::new_error_with_message(
971 self.tcx,
972 closure_span,
973 "this projection should have been projected to an opaque type",
974 ));
975 }
976 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => self
977 .tcx
978 .explicit_item_self_bounds(def_id)
979 .iter_instantiated_copied(self.tcx, args)
980 .map(Unnormalized::skip_norm_wip)
981 .find_map(|(c, s)| get_future_output(c, s))?,
982 ty::Error(_) => return Some(ret_ty),
983 _ => {
984 span_bug!(closure_span, "invalid async fn coroutine return type: {ret_ty:?}")
985 }
986 };
987
988 let output_ty = self.normalize(closure_span, Unnormalized::new_wip(output_ty));
989
990 let InferOk { value: output_ty, obligations } = self
993 .replace_opaque_types_with_inference_vars(
994 output_ty,
995 body_def_id,
996 closure_span,
997 self.param_env,
998 );
999 self.register_predicates(obligations);
1000
1001 Some(output_ty)
1002 }
1003
1004 fn deduce_future_output_from_projection(
1012 &self,
1013 cause_span: Span,
1014 predicate: ty::PolyProjectionClause<'tcx>,
1015 ) -> Option<Ty<'tcx>> {
1016 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:1016",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1016u32),
::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);
1017
1018 let Some(predicate) = predicate.no_bound_vars() else {
1021 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:1021",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1021u32),
::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");
1022 return None;
1023 };
1024
1025 let trait_def_id = predicate.projection_term.trait_def_id(self.tcx);
1027 if !self.tcx.is_lang_item(trait_def_id, LangItem::Future) {
1028 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:1028",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1028u32),
::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");
1029 return None;
1030 }
1031
1032 let output_assoc_item = self.tcx.associated_item_def_ids(trait_def_id)[0];
1035 if output_assoc_item != predicate.def_id() {
1036 ::rustc_span::macros::bug_impl(Some(cause_span),
format_args!("projecting associated item `{0:?}` from future, which is not Output `{1:?}`",
predicate.projection_term.kind, output_assoc_item),
Location::caller());span_bug!(
1037 cause_span,
1038 "projecting associated item `{:?}` from future, which is not Output `{:?}`",
1039 predicate.projection_term.kind,
1040 output_assoc_item,
1041 );
1042 }
1043
1044 let output_ty = self.deeply_resolve_ignoring_regions(predicate.term);
1048 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:1048",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1048u32),
::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);
1049 Some(output_ty.expect_type())
1051 }
1052
1053 fn error_sig_of_closure(
1057 &self,
1058 decl: &hir::FnDecl<'tcx>,
1059 guar: ErrorGuaranteed,
1060 ) -> ty::PolyFnSig<'tcx> {
1061 let lowerer = self.lowerer();
1062 let err_ty = Ty::new_error(self.tcx, guar);
1063
1064 let supplied_arguments = decl.inputs.iter().map(|a| {
1065 lowerer.lower_ty(a);
1067 err_ty
1068 });
1069
1070 if let hir::FnRetTy::Return(ref output) = decl.output {
1071 lowerer.lower_ty(output);
1072 }
1073
1074 let fn_sig_kind = FnSigKind::default()
1075 .set_abi(ExternAbi::RustCall)
1076 .set_safety(hir::Safety::Safe)
1077 .set_c_variadic(decl.c_variadic());
1078 let result = ty::Binder::dummy(self.tcx.mk_fn_sig(supplied_arguments, err_ty, fn_sig_kind));
1079
1080 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:1080",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1080u32),
::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);
1081
1082 result
1083 }
1084
1085 {}
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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1085u32),
::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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs:1085",
"rustc_hir_typeck::closure", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/closure.rs"),
::tracing_core::__macro_support::Option::Some(1085u32),
::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)]
1086 fn closure_sigs(
1087 &self,
1088 expr_def_id: LocalDefId,
1089 bound_sig: ty::PolyFnSig<'tcx>,
1090 ) -> ClosureSignatures<'tcx> {
1091 let liberated_sig =
1092 self.tcx().liberate_late_bound_regions(expr_def_id.to_def_id(), bound_sig);
1093 let liberated_sig =
1094 self.normalize(self.tcx.def_span(expr_def_id), Unnormalized::new_wip(liberated_sig));
1095 ClosureSignatures { bound_sig, liberated_sig }
1096 }
1097}