1use std::iter;
2
3use rustc_abi::{CanonAbi, ExternAbi};
4use rustc_ast::util::parser::ExprPrecedence;
5use rustc_errors::{Applicability, Diag, ErrorGuaranteed, StashKey, msg};
6use rustc_hir::def::{self, CtorKind, Namespace, Res};
7use rustc_hir::def_id::DefId;
8use rustc_hir::{self as hir, HirId, LangItem, find_attr};
9use rustc_hir_analysis::autoderef::Autoderef;
10use rustc_infer::infer::BoundRegionConversionTime;
11use rustc_infer::traits::{Obligation, ObligationCause, ObligationCauseCode};
12use rustc_middle::ty::adjustment::{
13 Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
14};
15use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt, Unnormalized};
16use rustc_middle::{bug, span_bug};
17use rustc_span::def_id::LocalDefId;
18use rustc_span::{Span, sym};
19use rustc_target::spec::{AbiMap, AbiMapping};
20use rustc_trait_selection::error_reporting::traits::DefIdOrName;
21use rustc_trait_selection::infer::InferCtxtExt as _;
22use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
23use tracing::{debug, instrument};
24
25use super::method::MethodCallee;
26use super::method::probe::ProbeScope;
27use super::{Expectation, FnCtxt, TupleArgumentsFlag};
28use crate::errors;
29use crate::method::TreatNotYetDefinedOpaques;
30
31pub(crate) fn check_legal_trait_for_method_call(
35 tcx: TyCtxt<'_>,
36 span: Span,
37 receiver: Option<Span>,
38 expr_span: Span,
39 trait_id: DefId,
40 body_id: DefId,
41) -> Result<(), ErrorGuaranteed> {
42 if tcx.is_lang_item(trait_id, LangItem::Drop)
43 && !tcx.is_lang_item(tcx.parent(body_id), LangItem::Drop)
45 {
46 let sugg = if let Some(receiver) = receiver.filter(|s| !s.is_empty()) {
47 errors::ExplicitDestructorCallSugg::Snippet {
48 lo: expr_span.shrink_to_lo().to(receiver.shrink_to_lo()),
49 hi: receiver.shrink_to_hi().to(expr_span.shrink_to_hi()),
50 }
51 } else {
52 errors::ExplicitDestructorCallSugg::Empty(span)
53 };
54 return Err(tcx.dcx().emit_err(errors::ExplicitDestructorCall { span, sugg }));
55 }
56 tcx.ensure_result().coherent_trait(trait_id)
57}
58
59#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for CallStep<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
CallStep::Builtin(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Builtin", &__self_0),
CallStep::DeferredClosure(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"DeferredClosure", __self_0, &__self_1),
CallStep::Overloaded(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Overloaded", &__self_0),
}
}
}Debug)]
60enum CallStep<'tcx> {
61 Builtin(Ty<'tcx>),
62 DeferredClosure(LocalDefId, ty::FnSig<'tcx>),
63 Overloaded(MethodCallee<'tcx>),
65}
66
67impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
68 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::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_call",
"rustc_hir_typeck::callee", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/callee.rs"),
::tracing_core::__macro_support::Option::Some(68u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::callee"),
::tracing_core::field::FieldSet::new(&["call_expr",
"callee_expr", "arg_exprs", "expected"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::INFO <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&call_expr)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&callee_expr)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&arg_exprs)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expected)
as &dyn 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 original_callee_ty =
match &callee_expr.kind {
hir::ExprKind::Path(hir::QPath::Resolved(..) |
hir::QPath::TypeRelative(..)) =>
self.check_expr_with_expectation_and_args(callee_expr,
Expectation::NoExpectation, Some((call_expr, arg_exprs))),
_ => self.check_expr(callee_expr),
};
let expr_ty =
self.resolve_vars_with_obligations(original_callee_ty);
let mut autoderef = self.autoderef(callee_expr.span, expr_ty);
let mut result = None;
while result.is_none() && autoderef.next().is_some() {
result =
self.try_overloaded_call_step(call_expr, callee_expr,
arg_exprs, &autoderef);
}
match *autoderef.final_ty().kind() {
ty::FnDef(def_id, _) => {
let abi =
self.tcx.fn_sig(def_id).skip_binder().skip_binder().abi();
self.check_call_abi(abi, call_expr.span);
}
ty::FnPtr(_, header) => {
self.check_call_abi(header.abi(), call_expr.span);
}
_ => {}
}
if self.is_scalable_vector_ctor(autoderef.final_ty()) {
let mut err =
self.dcx().create_err(errors::ScalableVectorCtor {
span: callee_expr.span,
ty: autoderef.final_ty(),
});
err.span_label(callee_expr.span,
"you can create scalable vectors using intrinsics");
Ty::new_error(self.tcx, err.emit());
}
self.register_predicates(autoderef.into_obligations());
let output =
match result {
None => {
for arg in arg_exprs { self.check_expr(arg); }
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) =
&callee_expr.kind && let [segment] = path.segments {
self.dcx().try_steal_modify_and_emit_err(segment.ident.span,
StashKey::CallIntoMethod,
|err|
{
self.suggest_call_as_method(err, segment, arg_exprs,
call_expr, expected);
});
}
let guar =
self.report_invalid_callee(call_expr, callee_expr, expr_ty,
arg_exprs);
Ty::new_error(self.tcx, guar)
}
Some(CallStep::Builtin(callee_ty)) => {
self.confirm_builtin_call(call_expr, callee_expr, callee_ty,
arg_exprs, expected)
}
Some(CallStep::DeferredClosure(def_id, fn_sig)) => {
self.confirm_deferred_closure_call(call_expr, arg_exprs,
expected, def_id, fn_sig)
}
Some(CallStep::Overloaded(method_callee)) => {
self.confirm_overloaded_call(call_expr, arg_exprs, expected,
method_callee)
}
};
self.register_wf_obligation(output.into(), call_expr.span,
ObligationCauseCode::WellFormed(None));
output
}
}
}#[tracing::instrument(skip(self))]
69 pub(crate) fn check_expr_call(
70 &self,
71 call_expr: &'tcx hir::Expr<'tcx>,
72 callee_expr: &'tcx hir::Expr<'tcx>,
73 arg_exprs: &'tcx [hir::Expr<'tcx>],
74 expected: Expectation<'tcx>,
75 ) -> Ty<'tcx> {
76 let original_callee_ty = match &callee_expr.kind {
77 hir::ExprKind::Path(hir::QPath::Resolved(..) | hir::QPath::TypeRelative(..)) => self
78 .check_expr_with_expectation_and_args(
79 callee_expr,
80 Expectation::NoExpectation,
81 Some((call_expr, arg_exprs)),
82 ),
83 _ => self.check_expr(callee_expr),
84 };
85
86 let expr_ty = self.resolve_vars_with_obligations(original_callee_ty);
87
88 let mut autoderef = self.autoderef(callee_expr.span, expr_ty);
89 let mut result = None;
90 while result.is_none() && autoderef.next().is_some() {
91 result = self.try_overloaded_call_step(call_expr, callee_expr, arg_exprs, &autoderef);
92 }
93
94 match *autoderef.final_ty().kind() {
95 ty::FnDef(def_id, _) => {
96 let abi = self.tcx.fn_sig(def_id).skip_binder().skip_binder().abi();
97 self.check_call_abi(abi, call_expr.span);
98 }
99 ty::FnPtr(_, header) => {
100 self.check_call_abi(header.abi(), call_expr.span);
101 }
102 _ => { }
103 }
104
105 if self.is_scalable_vector_ctor(autoderef.final_ty()) {
106 let mut err = self.dcx().create_err(errors::ScalableVectorCtor {
107 span: callee_expr.span,
108 ty: autoderef.final_ty(),
109 });
110 err.span_label(callee_expr.span, "you can create scalable vectors using intrinsics");
111 Ty::new_error(self.tcx, err.emit());
112 }
113
114 self.register_predicates(autoderef.into_obligations());
115
116 let output = match result {
117 None => {
118 for arg in arg_exprs {
121 self.check_expr(arg);
122 }
123
124 if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &callee_expr.kind
125 && let [segment] = path.segments
126 {
127 self.dcx().try_steal_modify_and_emit_err(
128 segment.ident.span,
129 StashKey::CallIntoMethod,
130 |err| {
131 self.suggest_call_as_method(
133 err, segment, arg_exprs, call_expr, expected,
134 );
135 },
136 );
137 }
138
139 let guar = self.report_invalid_callee(call_expr, callee_expr, expr_ty, arg_exprs);
140 Ty::new_error(self.tcx, guar)
141 }
142
143 Some(CallStep::Builtin(callee_ty)) => {
144 self.confirm_builtin_call(call_expr, callee_expr, callee_ty, arg_exprs, expected)
145 }
146
147 Some(CallStep::DeferredClosure(def_id, fn_sig)) => {
148 self.confirm_deferred_closure_call(call_expr, arg_exprs, expected, def_id, fn_sig)
149 }
150
151 Some(CallStep::Overloaded(method_callee)) => {
152 self.confirm_overloaded_call(call_expr, arg_exprs, expected, method_callee)
153 }
154 };
155
156 self.register_wf_obligation(
158 output.into(),
159 call_expr.span,
160 ObligationCauseCode::WellFormed(None),
161 );
162
163 output
164 }
165
166 pub(crate) fn check_call_abi(&self, abi: ExternAbi, span: Span) {
171 let canon_abi = match AbiMap::from_target(&self.sess().target).canonize_abi(abi, false) {
172 AbiMapping::Direct(canon_abi) | AbiMapping::Deprecated(canon_abi) => canon_abi,
173 AbiMapping::Invalid => {
174 let guar = self.dcx().span_delayed_bug(
177 span,
178 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("invalid abi for platform should have reported an error: {0}",
abi))
})format!("invalid abi for platform should have reported an error: {abi}"),
179 );
180 self.set_tainted_by_errors(guar);
181 return;
182 }
183 };
184
185 match canon_abi {
186 CanonAbi::Custom
188 | CanonAbi::Interrupt(_) => {
191 let err = crate::errors::AbiCannotBeCalled { span, abi };
192 self.tcx.dcx().emit_err(err);
193 }
194
195 CanonAbi::GpuKernel => {
197 let err = crate::errors::GpuKernelAbiCannotBeCalled { span };
198 self.tcx.dcx().emit_err(err);
199 }
200
201 CanonAbi::C
202 | CanonAbi::Rust
203 | CanonAbi::RustCold
204 | CanonAbi::RustPreserveNone
205 | CanonAbi::Swift
206 | CanonAbi::Arm(_)
207 | CanonAbi::X86(_) => {}
208 }
209 }
210
211 x;#[instrument(level = "debug", skip(self, call_expr, callee_expr, arg_exprs, autoderef), ret)]
212 fn try_overloaded_call_step(
213 &self,
214 call_expr: &'tcx hir::Expr<'tcx>,
215 callee_expr: &'tcx hir::Expr<'tcx>,
216 arg_exprs: &'tcx [hir::Expr<'tcx>],
217 autoderef: &Autoderef<'a, 'tcx>,
218 ) -> Option<CallStep<'tcx>> {
219 let adjusted_ty = self.resolve_vars_with_obligations(autoderef.final_ty());
220
221 match *adjusted_ty.kind() {
223 ty::FnDef(..) | ty::FnPtr(..) => {
224 let adjustments = self.adjust_steps(autoderef);
225 self.apply_adjustments(callee_expr, adjustments);
226 return Some(CallStep::Builtin(adjusted_ty));
227 }
228
229 ty::Closure(def_id, args) if self.closure_kind(adjusted_ty).is_none() => {
233 let def_id = def_id.expect_local();
234 let closure_sig = args.as_closure().sig();
235 let closure_sig = self.instantiate_binder_with_fresh_vars(
236 call_expr.span,
237 BoundRegionConversionTime::FnCall,
238 closure_sig,
239 );
240 let adjustments = self.adjust_steps(autoderef);
241 self.record_deferred_call_resolution(
242 def_id,
243 DeferredCallResolution {
244 call_expr,
245 callee_expr,
246 closure_ty: adjusted_ty,
247 adjustments,
248 fn_sig: closure_sig,
249 },
250 );
251 return Some(CallStep::DeferredClosure(def_id, closure_sig));
252 }
253
254 ty::CoroutineClosure(def_id, args) if self.closure_kind(adjusted_ty).is_none() => {
260 let def_id = def_id.expect_local();
261 let closure_args = args.as_coroutine_closure();
262 let coroutine_closure_sig = self.instantiate_binder_with_fresh_vars(
263 call_expr.span,
264 BoundRegionConversionTime::FnCall,
265 closure_args.coroutine_closure_sig(),
266 );
267 let tupled_upvars_ty = self.next_ty_var(callee_expr.span);
268 let kind_ty = self.next_ty_var(callee_expr.span);
273 let call_sig = self.tcx.mk_fn_sig(
274 [coroutine_closure_sig.tupled_inputs_ty],
275 coroutine_closure_sig.to_coroutine(
276 self.tcx,
277 closure_args.parent_args(),
278 kind_ty,
279 self.tcx.coroutine_for_closure(def_id),
280 tupled_upvars_ty,
281 ),
282 coroutine_closure_sig.fn_sig_kind,
283 );
284 let adjustments = self.adjust_steps(autoderef);
285 self.record_deferred_call_resolution(
286 def_id,
287 DeferredCallResolution {
288 call_expr,
289 callee_expr,
290 closure_ty: adjusted_ty,
291 adjustments,
292 fn_sig: call_sig,
293 },
294 );
295 return Some(CallStep::DeferredClosure(def_id, call_sig));
296 }
297
298 ty::Ref(..) if autoderef.step_count() == 0 => {
311 return None;
312 }
313
314 ty::Infer(ty::TyVar(vid)) => {
315 if !self.has_opaques_with_sub_unified_hidden_type(vid) {
318 self.type_must_be_known_at_this_point(autoderef.span(), adjusted_ty);
319 return None;
320 }
321 }
322
323 ty::Error(_) => {
324 return None;
325 }
326
327 _ => {}
328 }
329
330 self.try_overloaded_call_traits(call_expr, adjusted_ty, Some(arg_exprs))
338 .or_else(|| self.try_overloaded_call_traits(call_expr, adjusted_ty, None))
339 .map(|(autoref, method)| {
340 let mut adjustments = self.adjust_steps(autoderef);
341 adjustments.extend(autoref);
342 self.apply_adjustments(callee_expr, adjustments);
343 CallStep::Overloaded(method)
344 })
345 }
346
347 fn try_overloaded_call_traits(
348 &self,
349 call_expr: &hir::Expr<'_>,
350 adjusted_ty: Ty<'tcx>,
351 opt_arg_exprs: Option<&'tcx [hir::Expr<'tcx>]>,
352 ) -> Option<(Option<Adjustment<'tcx>>, MethodCallee<'tcx>)> {
353 let call_trait_choices = if self.shallow_resolve(adjusted_ty).is_coroutine_closure() {
366 [
367 (self.tcx.lang_items().async_fn_trait(), sym::async_call, true),
368 (self.tcx.lang_items().async_fn_mut_trait(), sym::async_call_mut, true),
369 (self.tcx.lang_items().async_fn_once_trait(), sym::async_call_once, false),
370 (self.tcx.lang_items().fn_trait(), sym::call, true),
371 (self.tcx.lang_items().fn_mut_trait(), sym::call_mut, true),
372 (self.tcx.lang_items().fn_once_trait(), sym::call_once, false),
373 ]
374 } else {
375 [
376 (self.tcx.lang_items().fn_trait(), sym::call, true),
377 (self.tcx.lang_items().fn_mut_trait(), sym::call_mut, true),
378 (self.tcx.lang_items().fn_once_trait(), sym::call_once, false),
379 (self.tcx.lang_items().async_fn_trait(), sym::async_call, true),
380 (self.tcx.lang_items().async_fn_mut_trait(), sym::async_call_mut, true),
381 (self.tcx.lang_items().async_fn_once_trait(), sym::async_call_once, false),
382 ]
383 };
384
385 for (opt_trait_def_id, method_name, borrow) in call_trait_choices {
387 let Some(trait_def_id) = opt_trait_def_id else { continue };
388
389 let opt_input_type = opt_arg_exprs.map(|arg_exprs| {
390 Ty::new_tup_from_iter(self.tcx, arg_exprs.iter().map(|e| self.next_ty_var(e.span)))
391 });
392
393 if let Some(ok) = self.lookup_method_for_operator(
400 self.misc(call_expr.span),
401 method_name,
402 trait_def_id,
403 adjusted_ty,
404 opt_input_type,
405 TreatNotYetDefinedOpaques::AsRigid,
406 ) {
407 let method = self.register_infer_ok_obligations(ok);
408 let mut autoref = None;
409 if borrow {
410 let ty::Ref(_, _, mutbl) = *method.sig.inputs()[0].kind() else {
413 ::rustc_middle::util::bug::bug_fmt(format_args!("Expected `FnMut`/`Fn` to take receiver by-ref/by-mut"))bug!("Expected `FnMut`/`Fn` to take receiver by-ref/by-mut")
414 };
415
416 let mutbl = AutoBorrowMutability::new(mutbl, AllowTwoPhase::No);
420
421 autoref = Some(Adjustment {
422 kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
423 target: method.sig.inputs()[0],
424 });
425 }
426
427 return Some((autoref, method));
428 }
429 }
430
431 None
432 }
433
434 fn is_scalable_vector_ctor(&self, callee_ty: Ty<'_>) -> bool {
435 if let ty::FnDef(def_id, _) = *callee_ty.kind()
436 && let def::DefKind::Ctor(def::CtorOf::Struct, _) = self.tcx.def_kind(def_id)
437 {
438 self.tcx
439 .opt_parent(def_id)
440 .and_then(|id| self.tcx.adt_def(id).repr().scalable)
441 .is_some()
442 } else {
443 false
444 }
445 }
446
447 fn identify_bad_closure_def_and_call(
450 &self,
451 err: &mut Diag<'_>,
452 hir_id: hir::HirId,
453 callee_node: &hir::ExprKind<'_>,
454 callee_span: Span,
455 ) {
456 let hir::ExprKind::Block(..) = callee_node else {
457 return;
459 };
460
461 let fn_decl_span = if let hir::Node::Expr(&hir::Expr {
462 kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
463 ..
464 }) = self.tcx.parent_hir_node(hir_id)
465 {
466 fn_decl_span
467 } else if let Some((
468 _,
469 hir::Node::Expr(&hir::Expr {
470 hir_id: parent_hir_id,
471 kind:
472 hir::ExprKind::Closure(&hir::Closure {
473 kind:
474 hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
475 hir::CoroutineDesugaring::Async,
476 hir::CoroutineSource::Closure,
477 )),
478 ..
479 }),
480 ..
481 }),
482 )) = self.tcx.hir_parent_iter(hir_id).nth(3)
483 {
484 let hir::Node::Expr(&hir::Expr {
487 kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
488 ..
489 }) = self.tcx.parent_hir_node(parent_hir_id)
490 else {
491 return;
492 };
493 fn_decl_span
494 } else {
495 return;
496 };
497
498 let start = fn_decl_span.shrink_to_lo();
499 let end = callee_span.shrink_to_hi();
500 err.multipart_suggestion(
501 "if you meant to create this closure and immediately call it, surround the \
502 closure with parentheses",
503 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(start, "(".to_string()), (end, ")".to_string())]))vec![(start, "(".to_string()), (end, ")".to_string())],
504 Applicability::MaybeIncorrect,
505 );
506 }
507
508 fn maybe_suggest_bad_array_definition(
511 &self,
512 err: &mut Diag<'_>,
513 call_expr: &'tcx hir::Expr<'tcx>,
514 callee_expr: &'tcx hir::Expr<'tcx>,
515 ) -> bool {
516 let parent_node = self.tcx.parent_hir_node(call_expr.hir_id);
517 if let (
518 hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Array(_), .. }),
519 hir::ExprKind::Tup(exp),
520 hir::ExprKind::Call(_, args),
521 ) = (parent_node, &callee_expr.kind, &call_expr.kind)
522 && args.len() == exp.len()
523 {
524 let start = callee_expr.span.shrink_to_hi();
525 err.span_suggestion(
526 start,
527 "consider separating array elements with a comma",
528 ",",
529 Applicability::MaybeIncorrect,
530 );
531 return true;
532 }
533 false
534 }
535
536 fn confirm_builtin_call(
537 &self,
538 call_expr: &'tcx hir::Expr<'tcx>,
539 callee_expr: &'tcx hir::Expr<'tcx>,
540 callee_ty: Ty<'tcx>,
541 arg_exprs: &'tcx [hir::Expr<'tcx>],
542 expected: Expectation<'tcx>,
543 ) -> Ty<'tcx> {
544 let (fn_sig, def_id) = match *callee_ty.kind() {
545 ty::FnDef(def_id, args) => {
546 self.enforce_context_effects(Some(call_expr.hir_id), call_expr.span, def_id, args);
547 let fn_sig = self.tcx.fn_sig(def_id).instantiate(self.tcx, args).skip_norm_wip();
548
549 if self.has_rustc_attrs && {
{
'done:
{
for i in
::rustc_hir::attrs::HasAttrs::get_attrs(def_id, &self.tcx) {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(RustcEvaluateWhereClauses) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some()find_attr!(self.tcx, def_id, RustcEvaluateWhereClauses) {
553 let predicates = self.tcx.predicates_of(def_id);
554 let predicates = predicates.instantiate(self.tcx, args);
555 for (predicate, predicate_span) in predicates {
556 let predicate = predicate.skip_norm_wip();
557 let obligation = Obligation::new(
558 self.tcx,
559 ObligationCause::dummy_with_span(callee_expr.span),
560 self.param_env,
561 predicate,
562 );
563 let result = self.evaluate_obligation(&obligation);
564 self.dcx()
565 .struct_span_err(
566 callee_expr.span,
567 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("evaluate({0:?}) = {1:?}",
predicate, result))
})format!("evaluate({predicate:?}) = {result:?}"),
568 )
569 .with_span_label(predicate_span, "predicate")
570 .emit();
571 }
572 }
573 (fn_sig, Some(def_id))
574 }
575
576 ty::FnPtr(sig_tys, hdr) => (sig_tys.with(hdr), None),
578
579 _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
580 };
581
582 let fn_sig = self.instantiate_binder_with_fresh_vars(
588 call_expr.span,
589 BoundRegionConversionTime::FnCall,
590 fn_sig,
591 );
592 let fn_sig = self.normalize(call_expr.span, Unnormalized::new_wip(fn_sig));
593
594 self.check_argument_types(
595 call_expr.span,
596 call_expr,
597 fn_sig.inputs(),
598 fn_sig.output(),
599 expected,
600 arg_exprs,
601 fn_sig.c_variadic(),
602 TupleArgumentsFlag::DontTupleArguments,
603 def_id,
604 );
605
606 if fn_sig.abi() == rustc_abi::ExternAbi::RustCall {
607 let sp = arg_exprs.last().map_or(call_expr.span, |expr| expr.span);
608 if let Some(ty) = fn_sig.inputs().last().copied() {
609 self.register_bound(
610 ty,
611 self.tcx.require_lang_item(hir::LangItem::Tuple, sp),
612 self.cause(sp, ObligationCauseCode::RustCall),
613 );
614 self.require_type_is_sized(ty, sp, ObligationCauseCode::RustCall);
615 } else {
616 self.dcx().emit_err(errors::RustCallIncorrectArgs { span: sp });
617 }
618 }
619
620 fn_sig.output()
621 }
622
623 fn suggest_call_as_method(
626 &self,
627 diag: &mut Diag<'_>,
628 segment: &'tcx hir::PathSegment<'tcx>,
629 arg_exprs: &'tcx [hir::Expr<'tcx>],
630 call_expr: &'tcx hir::Expr<'tcx>,
631 expected: Expectation<'tcx>,
632 ) {
633 if let [callee_expr, rest @ ..] = arg_exprs {
634 let Some(callee_ty) = self.typeck_results.borrow().expr_ty_adjusted_opt(callee_expr)
635 else {
636 return;
637 };
638
639 let Ok(pick) = self.lookup_probe_for_diagnostic(
643 segment.ident,
644 callee_ty,
645 call_expr,
646 ProbeScope::AllTraits,
649 expected.only_has_type(self),
650 ) else {
651 return;
652 };
653
654 let pick = self.confirm_method_for_diagnostic(
655 call_expr.span,
656 callee_expr,
657 call_expr,
658 callee_ty,
659 &pick,
660 segment,
661 );
662 if pick.illegal_sized_bound.is_some() {
663 return;
664 }
665
666 let Some(callee_expr_span) = callee_expr.span.find_ancestor_inside(call_expr.span)
667 else {
668 return;
669 };
670 let up_to_rcvr_span = segment.ident.span.until(callee_expr_span);
671 let rest_span = callee_expr_span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
672 let rest_snippet = if let Some(first) = rest.first() {
673 self.tcx
674 .sess
675 .source_map()
676 .span_to_snippet(first.span.to(call_expr.span.shrink_to_hi()))
677 } else {
678 Ok(")".to_string())
679 };
680
681 if let Ok(rest_snippet) = rest_snippet {
682 let sugg = if self.precedence(callee_expr) >= ExprPrecedence::Unambiguous {
683 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(up_to_rcvr_span, "".to_string()),
(rest_span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".{0}({1}", segment.ident,
rest_snippet))
}))]))vec![
684 (up_to_rcvr_span, "".to_string()),
685 (rest_span, format!(".{}({rest_snippet}", segment.ident)),
686 ]
687 } else {
688 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(up_to_rcvr_span, "(".to_string()),
(rest_span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(").{0}({1}",
segment.ident, rest_snippet))
}))]))vec![
689 (up_to_rcvr_span, "(".to_string()),
690 (rest_span, format!(").{}({rest_snippet}", segment.ident)),
691 ]
692 };
693 let self_ty = self.resolve_vars_if_possible(pick.callee.sig.inputs()[0]);
694 diag.multipart_suggestion(
695 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("use the `.` operator to call the method `{0}{1}` on `{2}`",
self.tcx.associated_item(pick.callee.def_id).trait_container(self.tcx).map_or_else(||
String::new(),
|trait_def_id| self.tcx.def_path_str(trait_def_id) + "::"),
segment.ident, self_ty))
})format!(
696 "use the `.` operator to call the method `{}{}` on `{self_ty}`",
697 self.tcx
698 .associated_item(pick.callee.def_id)
699 .trait_container(self.tcx)
700 .map_or_else(
701 || String::new(),
702 |trait_def_id| self.tcx.def_path_str(trait_def_id) + "::"
703 ),
704 segment.ident
705 ),
706 sugg,
707 Applicability::MaybeIncorrect,
708 );
709 }
710 }
711 }
712
713 fn report_invalid_callee(
714 &self,
715 call_expr: &'tcx hir::Expr<'tcx>,
716 callee_expr: &'tcx hir::Expr<'tcx>,
717 callee_ty: Ty<'tcx>,
718 arg_exprs: &'tcx [hir::Expr<'tcx>],
719 ) -> ErrorGuaranteed {
720 if let Some((_, _, args)) = self.extract_callable_info(callee_ty)
723 && let Err(err) = args.error_reported()
724 {
725 return err;
726 }
727
728 let mut unit_variant = None;
729 if let hir::ExprKind::Path(qpath) = &callee_expr.kind
730 && let Res::Def(def::DefKind::Ctor(kind, CtorKind::Const), _)
731 = self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
732 && arg_exprs.is_empty()
734 && call_expr.span.contains(callee_expr.span)
735 {
736 let descr = match kind {
737 def::CtorOf::Struct => "struct",
738 def::CtorOf::Variant => "enum variant",
739 };
740 let removal_span = callee_expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
741 unit_variant =
742 Some((removal_span, descr, rustc_hir_pretty::qpath_to_string(&self.tcx, qpath)));
743 }
744
745 let callee_ty = self.resolve_vars_if_possible(callee_ty);
746 let mut path = None;
747 let mut err = self.dcx().create_err(errors::InvalidCallee {
748 span: callee_expr.span,
749 ty: callee_ty,
750 found: match &unit_variant {
751 Some((_, kind, path)) => ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0} `{1}`", kind, path))
})format!("{kind} `{path}`"),
752 None => ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`",
self.tcx.short_string(callee_ty, &mut path)))
})format!("`{}`", self.tcx.short_string(callee_ty, &mut path)),
753 },
754 });
755 *err.long_ty_path() = path;
756 if callee_ty.references_error() {
757 err.downgrade_to_delayed_bug();
758 }
759
760 self.identify_bad_closure_def_and_call(
761 &mut err,
762 call_expr.hir_id,
763 &callee_expr.kind,
764 callee_expr.span,
765 );
766
767 if let Some((removal_span, kind, path)) = &unit_variant {
768 err.span_suggestion_verbose(
769 *removal_span,
770 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}` is a unit {1}, and does not take parentheses to be constructed",
path, kind))
})format!(
771 "`{path}` is a unit {kind}, and does not take parentheses to be constructed",
772 ),
773 "",
774 Applicability::MachineApplicable,
775 );
776 }
777
778 if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = callee_expr.kind
779 && let Res::Local(_) = path.res
780 && let [segment] = &path.segments
781 {
782 for id in self.tcx.hir_free_items() {
783 if let Some(node) = self.tcx.hir_get_if_local(id.owner_id.into())
784 && let hir::Node::Item(item) = node
785 && let hir::ItemKind::Fn { ident, .. } = item.kind
786 && ident.name == segment.ident.name
787 {
788 err.span_label(
789 self.tcx.def_span(id.owner_id),
790 "this function of the same name is available here, but it's shadowed by \
791 the local binding",
792 );
793 }
794 }
795 }
796
797 let mut inner_callee_path = None;
798 let def = match callee_expr.kind {
799 hir::ExprKind::Path(ref qpath) => {
800 self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
801 }
802 hir::ExprKind::Call(inner_callee, _) => {
803 if let hir::ExprKind::Path(ref inner_qpath) = inner_callee.kind {
804 inner_callee_path = Some(inner_qpath);
805 self.typeck_results.borrow().qpath_res(inner_qpath, inner_callee.hir_id)
806 } else {
807 Res::Err
808 }
809 }
810 _ => Res::Err,
811 };
812
813 if !self.maybe_suggest_bad_array_definition(&mut err, call_expr, callee_expr) {
814 let call_is_multiline = self
818 .tcx
819 .sess
820 .source_map()
821 .is_multiline(call_expr.span.with_lo(callee_expr.span.hi()))
822 && call_expr.span.eq_ctxt(callee_expr.span);
823 if call_is_multiline {
824 err.span_suggestion(
825 callee_expr.span.shrink_to_hi(),
826 "consider using a semicolon here to finish the statement",
827 ";",
828 Applicability::MaybeIncorrect,
829 );
830 }
831 if let Some((maybe_def, output_ty, _)) = self.extract_callable_info(callee_ty)
832 && !self.type_is_sized_modulo_regions(self.param_env, output_ty)
833 {
834 let descr = match maybe_def {
835 DefIdOrName::DefId(def_id) => self.tcx.def_descr(def_id),
836 DefIdOrName::Name(name) => name,
837 };
838 err.span_label(
839 callee_expr.span,
840 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("this {0} returns an unsized value `{1}`, so it cannot be called",
descr, output_ty))
})format!("this {descr} returns an unsized value `{output_ty}`, so it cannot be called")
841 );
842 if let DefIdOrName::DefId(def_id) = maybe_def
843 && let Some(def_span) = self.tcx.hir_span_if_local(def_id)
844 {
845 err.span_label(def_span, "the callable type is defined here");
846 }
847 } else {
848 err.span_label(call_expr.span, "call expression requires function");
849 }
850 }
851
852 if let Some(span) = self.tcx.hir_res_span(def) {
853 let callee_ty = callee_ty.to_string();
854 let label = match (unit_variant, inner_callee_path) {
855 (Some((_, kind, path)), _) => {
856 err.arg("kind", kind);
857 err.arg("path", path);
858 Some(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$kind} `{$path}` defined here"))msg!("{$kind} `{$path}` defined here"))
859 }
860 (_, Some(hir::QPath::Resolved(_, path))) => {
861 self.tcx.sess.source_map().span_to_snippet(path.span).ok().map(|p| {
862 err.arg("func", p);
863 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$func}` defined here returns `{$ty}`"))msg!("`{$func}` defined here returns `{$ty}`")
864 })
865 }
866 _ => {
867 match def {
868 Res::Local(hir_id) => {
871 err.arg("local_name", self.tcx.hir_name(hir_id));
872 Some(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$local_name}` has type `{$ty}`"))msg!("`{$local_name}` has type `{$ty}`"))
873 }
874 Res::Def(kind, def_id) if kind.ns() == Some(Namespace::ValueNS) => {
875 err.arg("path", self.tcx.def_path_str(def_id));
876 Some(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$path}` defined here"))msg!("`{$path}` defined here"))
877 }
878 _ => {
879 err.arg("path", callee_ty);
880 Some(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$path}` defined here"))msg!("`{$path}` defined here"))
881 }
882 }
883 }
884 };
885 if let Some(label) = label {
886 err.span_label(span, label);
887 }
888 }
889 err.emit()
890 }
891
892 fn confirm_deferred_closure_call(
893 &self,
894 call_expr: &'tcx hir::Expr<'tcx>,
895 arg_exprs: &'tcx [hir::Expr<'tcx>],
896 expected: Expectation<'tcx>,
897 closure_def_id: LocalDefId,
898 fn_sig: ty::FnSig<'tcx>,
899 ) -> Ty<'tcx> {
900 self.check_argument_types(
905 call_expr.span,
906 call_expr,
907 fn_sig.inputs(),
908 fn_sig.output(),
909 expected,
910 arg_exprs,
911 fn_sig.c_variadic(),
912 TupleArgumentsFlag::TupleArguments,
913 Some(closure_def_id.to_def_id()),
914 );
915
916 fn_sig.output()
917 }
918
919 #[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("enforce_context_effects",
"rustc_hir_typeck::callee", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/callee.rs"),
::tracing_core::__macro_support::Option::Some(919u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::callee"),
::tracing_core::field::FieldSet::new(&["call_hir_id",
"callee_did", "callee_args"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&call_hir_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&callee_did)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&callee_args)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if !self.tcx.features().const_trait_impl() { return; }
if self.has_rustc_attrs &&
{
{
'done:
{
for i in
::rustc_hir::attrs::HasAttrs::get_attrs(self.body_id,
&self.tcx) {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(RustcDoNotConstCheck) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some() {
return;
}
let host =
match self.tcx.hir_body_const_context(self.body_id) {
Some(hir::ConstContext::Const { .. } |
hir::ConstContext::Static(_)) => {
ty::BoundConstness::Const
}
Some(hir::ConstContext::ConstFn) =>
ty::BoundConstness::Maybe,
None => return,
};
if self.tcx.is_conditionally_const(callee_did) {
let q = self.tcx.const_conditions(callee_did);
for (idx, (cond, pred_span)) in
q.instantiate(self.tcx, callee_args).into_iter().enumerate()
{
let cause =
self.cause(span,
if let Some(hir_id) = call_hir_id {
ObligationCauseCode::HostEffectInExpr(callee_did, pred_span,
hir_id, idx)
} else {
ObligationCauseCode::WhereClause(callee_did, pred_span)
});
self.register_predicate(Obligation::new(self.tcx, cause,
self.param_env,
cond.to_host_effect_clause(self.tcx,
host).skip_norm_wip()));
}
} else {}
}
}
}#[tracing::instrument(level = "debug", skip(self, span))]
920 pub(super) fn enforce_context_effects(
921 &self,
922 call_hir_id: Option<HirId>,
923 span: Span,
924 callee_did: DefId,
925 callee_args: GenericArgsRef<'tcx>,
926 ) {
927 if !self.tcx.features().const_trait_impl() {
932 return;
933 }
934
935 if self.has_rustc_attrs && find_attr!(self.tcx, self.body_id, RustcDoNotConstCheck) {
937 return;
938 }
939
940 let host = match self.tcx.hir_body_const_context(self.body_id) {
941 Some(hir::ConstContext::Const { .. } | hir::ConstContext::Static(_)) => {
942 ty::BoundConstness::Const
943 }
944 Some(hir::ConstContext::ConstFn) => ty::BoundConstness::Maybe,
945 None => return,
946 };
947
948 if self.tcx.is_conditionally_const(callee_did) {
951 let q = self.tcx.const_conditions(callee_did);
952 for (idx, (cond, pred_span)) in
953 q.instantiate(self.tcx, callee_args).into_iter().enumerate()
954 {
955 let cause = self.cause(
956 span,
957 if let Some(hir_id) = call_hir_id {
958 ObligationCauseCode::HostEffectInExpr(callee_did, pred_span, hir_id, idx)
959 } else {
960 ObligationCauseCode::WhereClause(callee_did, pred_span)
961 },
962 );
963 self.register_predicate(Obligation::new(
964 self.tcx,
965 cause,
966 self.param_env,
967 cond.to_host_effect_clause(self.tcx, host).skip_norm_wip(),
968 ));
969 }
970 } else {
971 }
974 }
975
976 fn confirm_overloaded_call(
977 &self,
978 call_expr: &'tcx hir::Expr<'tcx>,
979 arg_exprs: &'tcx [hir::Expr<'tcx>],
980 expected: Expectation<'tcx>,
981 method: MethodCallee<'tcx>,
982 ) -> Ty<'tcx> {
983 self.check_argument_types(
984 call_expr.span,
985 call_expr,
986 &method.sig.inputs()[1..],
987 method.sig.output(),
988 expected,
989 arg_exprs,
990 method.sig.c_variadic(),
991 TupleArgumentsFlag::TupleArguments,
992 Some(method.def_id),
993 );
994
995 self.write_method_call_and_enforce_effects(call_expr.hir_id, call_expr.span, method);
996
997 method.sig.output()
998 }
999}
1000
1001#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for DeferredCallResolution<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field5_finish(f,
"DeferredCallResolution", "call_expr", &self.call_expr,
"callee_expr", &self.callee_expr, "closure_ty", &self.closure_ty,
"adjustments", &self.adjustments, "fn_sig", &&self.fn_sig)
}
}Debug)]
1002pub(crate) struct DeferredCallResolution<'tcx> {
1003 call_expr: &'tcx hir::Expr<'tcx>,
1004 callee_expr: &'tcx hir::Expr<'tcx>,
1005 closure_ty: Ty<'tcx>,
1006 adjustments: Vec<Adjustment<'tcx>>,
1007 fn_sig: ty::FnSig<'tcx>,
1008}
1009
1010impl<'a, 'tcx> DeferredCallResolution<'tcx> {
1011 pub(crate) fn resolve(self, fcx: &FnCtxt<'a, 'tcx>) {
1012 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/callee.rs:1012",
"rustc_hir_typeck::callee", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/callee.rs"),
::tracing_core::__macro_support::Option::Some(1012u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::callee"),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("DeferredCallResolution::resolve() {0:?}",
self) as &dyn Value))])
});
} else { ; }
};debug!("DeferredCallResolution::resolve() {:?}", self);
1013
1014 if !fcx.closure_kind(self.closure_ty).is_some() {
::core::panicking::panic("assertion failed: fcx.closure_kind(self.closure_ty).is_some()")
};assert!(fcx.closure_kind(self.closure_ty).is_some());
1017
1018 match fcx.try_overloaded_call_traits(self.call_expr, self.closure_ty, None) {
1020 Some((autoref, method_callee)) => {
1021 let method_sig = method_callee.sig;
1030
1031 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/callee.rs:1031",
"rustc_hir_typeck::callee", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/callee.rs"),
::tracing_core::__macro_support::Option::Some(1031u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::callee"),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("attempt_resolution: method_callee={0:?}",
method_callee) as &dyn Value))])
});
} else { ; }
};debug!("attempt_resolution: method_callee={:?}", method_callee);
1032
1033 for (method_arg_ty, self_arg_ty) in
1034 iter::zip(method_sig.inputs().iter().skip(1), self.fn_sig.inputs())
1035 {
1036 fcx.demand_eqtype(self.call_expr.span, *self_arg_ty, *method_arg_ty);
1037 }
1038
1039 fcx.demand_eqtype(self.call_expr.span, method_sig.output(), self.fn_sig.output());
1040
1041 let mut adjustments = self.adjustments;
1042 adjustments.extend(autoref);
1043 fcx.apply_adjustments(self.callee_expr, adjustments);
1044
1045 fcx.write_method_call_and_enforce_effects(
1046 self.call_expr.hir_id,
1047 self.call_expr.span,
1048 method_callee,
1049 );
1050 }
1051 None => {
1052 ::rustc_middle::util::bug::span_bug_fmt(self.call_expr.span,
format_args!("Expected to find a suitable `Fn`/`FnMut`/`FnOnce` implementation for `{0}`",
self.closure_ty))span_bug!(
1053 self.call_expr.span,
1054 "Expected to find a suitable `Fn`/`FnMut`/`FnOnce` implementation for `{}`",
1055 self.closure_ty
1056 )
1057 }
1058 }
1059 }
1060}