]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_typeck/src/check/callee.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / compiler / rustc_typeck / src / check / callee.rs
1 use super::method::MethodCallee;
2 use super::{Expectation, FnCtxt, TupleArgumentsFlag};
3 use crate::type_error_struct;
4
5 use rustc_errors::{struct_span_err, Applicability, Diagnostic};
6 use rustc_hir as hir;
7 use rustc_hir::def::{self, Namespace, Res};
8 use rustc_hir::def_id::DefId;
9 use rustc_infer::{
10 infer,
11 traits::{self, Obligation},
12 };
13 use rustc_infer::{
14 infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind},
15 traits::ObligationCause,
16 };
17 use rustc_middle::ty::adjustment::{
18 Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
19 };
20 use rustc_middle::ty::subst::{Subst, SubstsRef};
21 use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable};
22 use rustc_span::def_id::LocalDefId;
23 use rustc_span::symbol::{sym, Ident};
24 use rustc_span::Span;
25 use rustc_target::spec::abi;
26 use rustc_trait_selection::autoderef::Autoderef;
27 use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
28
29 use std::iter;
30
31 /// Checks that it is legal to call methods of the trait corresponding
32 /// to `trait_id` (this only cares about the trait, not the specific
33 /// method that is called).
34 pub 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 ) {
41 if tcx.lang_items().drop_trait() == Some(trait_id) {
42 let mut err = struct_span_err!(tcx.sess, span, E0040, "explicit use of destructor method");
43 err.span_label(span, "explicit destructor calls not allowed");
44
45 let (sp, suggestion) = receiver
46 .and_then(|s| tcx.sess.source_map().span_to_snippet(s).ok())
47 .filter(|snippet| !snippet.is_empty())
48 .map(|snippet| (expr_span, format!("drop({snippet})")))
49 .unwrap_or_else(|| (span, "drop".to_string()));
50
51 err.span_suggestion(
52 sp,
53 "consider using `drop` function",
54 suggestion,
55 Applicability::MaybeIncorrect,
56 );
57
58 err.emit();
59 }
60 }
61
62 enum CallStep<'tcx> {
63 Builtin(Ty<'tcx>),
64 DeferredClosure(LocalDefId, ty::FnSig<'tcx>),
65 /// E.g., enum variant constructors.
66 Overloaded(MethodCallee<'tcx>),
67 }
68
69 impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
70 pub fn check_call(
71 &self,
72 call_expr: &'tcx hir::Expr<'tcx>,
73 callee_expr: &'tcx hir::Expr<'tcx>,
74 arg_exprs: &'tcx [hir::Expr<'tcx>],
75 expected: Expectation<'tcx>,
76 ) -> Ty<'tcx> {
77 let original_callee_ty = match &callee_expr.kind {
78 hir::ExprKind::Path(hir::QPath::Resolved(..) | hir::QPath::TypeRelative(..)) => self
79 .check_expr_with_expectation_and_args(
80 callee_expr,
81 Expectation::NoExpectation,
82 arg_exprs,
83 ),
84 _ => self.check_expr(callee_expr),
85 };
86
87 let expr_ty = self.structurally_resolved_type(call_expr.span, original_callee_ty);
88
89 let mut autoderef = self.autoderef(callee_expr.span, expr_ty);
90 let mut result = None;
91 while result.is_none() && autoderef.next().is_some() {
92 result = self.try_overloaded_call_step(call_expr, callee_expr, arg_exprs, &autoderef);
93 }
94 self.register_predicates(autoderef.into_obligations());
95
96 let output = match result {
97 None => {
98 // this will report an error since original_callee_ty is not a fn
99 self.confirm_builtin_call(
100 call_expr,
101 callee_expr,
102 original_callee_ty,
103 arg_exprs,
104 expected,
105 )
106 }
107
108 Some(CallStep::Builtin(callee_ty)) => {
109 self.confirm_builtin_call(call_expr, callee_expr, callee_ty, arg_exprs, expected)
110 }
111
112 Some(CallStep::DeferredClosure(def_id, fn_sig)) => {
113 self.confirm_deferred_closure_call(call_expr, arg_exprs, expected, def_id, fn_sig)
114 }
115
116 Some(CallStep::Overloaded(method_callee)) => {
117 self.confirm_overloaded_call(call_expr, arg_exprs, expected, method_callee)
118 }
119 };
120
121 // we must check that return type of called functions is WF:
122 self.register_wf_obligation(output.into(), call_expr.span, traits::WellFormed(None));
123
124 output
125 }
126
127 fn try_overloaded_call_step(
128 &self,
129 call_expr: &'tcx hir::Expr<'tcx>,
130 callee_expr: &'tcx hir::Expr<'tcx>,
131 arg_exprs: &'tcx [hir::Expr<'tcx>],
132 autoderef: &Autoderef<'a, 'tcx>,
133 ) -> Option<CallStep<'tcx>> {
134 let adjusted_ty =
135 self.structurally_resolved_type(autoderef.span(), autoderef.final_ty(false));
136 debug!(
137 "try_overloaded_call_step(call_expr={:?}, adjusted_ty={:?})",
138 call_expr, adjusted_ty
139 );
140
141 // If the callee is a bare function or a closure, then we're all set.
142 match *adjusted_ty.kind() {
143 ty::FnDef(..) | ty::FnPtr(_) => {
144 let adjustments = self.adjust_steps(autoderef);
145 self.apply_adjustments(callee_expr, adjustments);
146 return Some(CallStep::Builtin(adjusted_ty));
147 }
148
149 ty::Closure(def_id, substs) => {
150 let def_id = def_id.expect_local();
151
152 // Check whether this is a call to a closure where we
153 // haven't yet decided on whether the closure is fn vs
154 // fnmut vs fnonce. If so, we have to defer further processing.
155 if self.closure_kind(substs).is_none() {
156 let closure_sig = substs.as_closure().sig();
157 let closure_sig = self.replace_bound_vars_with_fresh_vars(
158 call_expr.span,
159 infer::FnCall,
160 closure_sig,
161 );
162 let adjustments = self.adjust_steps(autoderef);
163 self.record_deferred_call_resolution(
164 def_id,
165 DeferredCallResolution {
166 call_expr,
167 callee_expr,
168 adjusted_ty,
169 adjustments,
170 fn_sig: closure_sig,
171 closure_substs: substs,
172 },
173 );
174 return Some(CallStep::DeferredClosure(def_id, closure_sig));
175 }
176 }
177
178 // Hack: we know that there are traits implementing Fn for &F
179 // where F:Fn and so forth. In the particular case of types
180 // like `x: &mut FnMut()`, if there is a call `x()`, we would
181 // normally translate to `FnMut::call_mut(&mut x, ())`, but
182 // that winds up requiring `mut x: &mut FnMut()`. A little
183 // over the top. The simplest fix by far is to just ignore
184 // this case and deref again, so we wind up with
185 // `FnMut::call_mut(&mut *x, ())`.
186 ty::Ref(..) if autoderef.step_count() == 0 => {
187 return None;
188 }
189
190 _ => {}
191 }
192
193 // Now, we look for the implementation of a Fn trait on the object's type.
194 // We first do it with the explicit instruction to look for an impl of
195 // `Fn<Tuple>`, with the tuple `Tuple` having an arity corresponding
196 // to the number of call parameters.
197 // If that fails (or_else branch), we try again without specifying the
198 // shape of the tuple (hence the None). This allows to detect an Fn trait
199 // is implemented, and use this information for diagnostic.
200 self.try_overloaded_call_traits(call_expr, adjusted_ty, Some(arg_exprs))
201 .or_else(|| self.try_overloaded_call_traits(call_expr, adjusted_ty, None))
202 .map(|(autoref, method)| {
203 let mut adjustments = self.adjust_steps(autoderef);
204 adjustments.extend(autoref);
205 self.apply_adjustments(callee_expr, adjustments);
206 CallStep::Overloaded(method)
207 })
208 }
209
210 fn try_overloaded_call_traits(
211 &self,
212 call_expr: &hir::Expr<'_>,
213 adjusted_ty: Ty<'tcx>,
214 opt_arg_exprs: Option<&'tcx [hir::Expr<'tcx>]>,
215 ) -> Option<(Option<Adjustment<'tcx>>, MethodCallee<'tcx>)> {
216 // Try the options that are least restrictive on the caller first.
217 for (opt_trait_def_id, method_name, borrow) in [
218 (self.tcx.lang_items().fn_trait(), Ident::with_dummy_span(sym::call), true),
219 (self.tcx.lang_items().fn_mut_trait(), Ident::with_dummy_span(sym::call_mut), true),
220 (self.tcx.lang_items().fn_once_trait(), Ident::with_dummy_span(sym::call_once), false),
221 ] {
222 let Some(trait_def_id) = opt_trait_def_id else { continue };
223
224 let opt_input_types = opt_arg_exprs.map(|arg_exprs| {
225 [self.tcx.mk_tup(arg_exprs.iter().map(|e| {
226 self.next_ty_var(TypeVariableOrigin {
227 kind: TypeVariableOriginKind::TypeInference,
228 span: e.span,
229 })
230 }))]
231 });
232 let opt_input_types = opt_input_types.as_ref().map(AsRef::as_ref);
233
234 if let Some(ok) = self.lookup_method_in_trait(
235 call_expr.span,
236 method_name,
237 trait_def_id,
238 adjusted_ty,
239 opt_input_types,
240 ) {
241 let method = self.register_infer_ok_obligations(ok);
242 let mut autoref = None;
243 if borrow {
244 // Check for &self vs &mut self in the method signature. Since this is either
245 // the Fn or FnMut trait, it should be one of those.
246 let ty::Ref(region, _, mutbl) = method.sig.inputs()[0].kind() else {
247 // The `fn`/`fn_mut` lang item is ill-formed, which should have
248 // caused an error elsewhere.
249 self.tcx
250 .sess
251 .delay_span_bug(call_expr.span, "input to call/call_mut is not a ref?");
252 return None;
253 };
254
255 let mutbl = match mutbl {
256 hir::Mutability::Not => AutoBorrowMutability::Not,
257 hir::Mutability::Mut => AutoBorrowMutability::Mut {
258 // For initial two-phase borrow
259 // deployment, conservatively omit
260 // overloaded function call ops.
261 allow_two_phase_borrow: AllowTwoPhase::No,
262 },
263 };
264 autoref = Some(Adjustment {
265 kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)),
266 target: method.sig.inputs()[0],
267 });
268 }
269 return Some((autoref, method));
270 }
271 }
272
273 None
274 }
275
276 /// Give appropriate suggestion when encountering `||{/* not callable */}()`, where the
277 /// likely intention is to call the closure, suggest `(||{})()`. (#55851)
278 fn identify_bad_closure_def_and_call(
279 &self,
280 err: &mut Diagnostic,
281 hir_id: hir::HirId,
282 callee_node: &hir::ExprKind<'_>,
283 callee_span: Span,
284 ) {
285 let hir = self.tcx.hir();
286 let parent_hir_id = hir.get_parent_node(hir_id);
287 let parent_node = hir.get(parent_hir_id);
288 if let (
289 hir::Node::Expr(hir::Expr {
290 kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, body, .. }),
291 ..
292 }),
293 hir::ExprKind::Block(..),
294 ) = (parent_node, callee_node)
295 {
296 let fn_decl_span = if hir.body(body).generator_kind
297 == Some(hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Closure))
298 {
299 // Actually need to unwrap a few more layers of HIR to get to
300 // the _real_ closure...
301 let async_closure = hir.get_parent_node(hir.get_parent_node(parent_hir_id));
302 if let hir::Node::Expr(hir::Expr {
303 kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
304 ..
305 }) = hir.get(async_closure)
306 {
307 fn_decl_span
308 } else {
309 return;
310 }
311 } else {
312 fn_decl_span
313 };
314
315 let start = fn_decl_span.shrink_to_lo();
316 let end = callee_span.shrink_to_hi();
317 err.multipart_suggestion(
318 "if you meant to create this closure and immediately call it, surround the \
319 closure with parentheses",
320 vec![(start, "(".to_string()), (end, ")".to_string())],
321 Applicability::MaybeIncorrect,
322 );
323 }
324 }
325
326 /// Give appropriate suggestion when encountering `[("a", 0) ("b", 1)]`, where the
327 /// likely intention is to create an array containing tuples.
328 fn maybe_suggest_bad_array_definition(
329 &self,
330 err: &mut Diagnostic,
331 call_expr: &'tcx hir::Expr<'tcx>,
332 callee_expr: &'tcx hir::Expr<'tcx>,
333 ) -> bool {
334 let hir_id = self.tcx.hir().get_parent_node(call_expr.hir_id);
335 let parent_node = self.tcx.hir().get(hir_id);
336 if let (
337 hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Array(_), .. }),
338 hir::ExprKind::Tup(exp),
339 hir::ExprKind::Call(_, args),
340 ) = (parent_node, &callee_expr.kind, &call_expr.kind)
341 && args.len() == exp.len()
342 {
343 let start = callee_expr.span.shrink_to_hi();
344 err.span_suggestion(
345 start,
346 "consider separating array elements with a comma",
347 ",",
348 Applicability::MaybeIncorrect,
349 );
350 return true;
351 }
352 false
353 }
354
355 fn confirm_builtin_call(
356 &self,
357 call_expr: &'tcx hir::Expr<'tcx>,
358 callee_expr: &'tcx hir::Expr<'tcx>,
359 callee_ty: Ty<'tcx>,
360 arg_exprs: &'tcx [hir::Expr<'tcx>],
361 expected: Expectation<'tcx>,
362 ) -> Ty<'tcx> {
363 let (fn_sig, def_id) = match *callee_ty.kind() {
364 ty::FnDef(def_id, subst) => {
365 let fn_sig = self.tcx.bound_fn_sig(def_id).subst(self.tcx, subst);
366
367 // Unit testing: function items annotated with
368 // `#[rustc_evaluate_where_clauses]` trigger special output
369 // to let us test the trait evaluation system.
370 if self.tcx.has_attr(def_id, sym::rustc_evaluate_where_clauses) {
371 let predicates = self.tcx.predicates_of(def_id);
372 let predicates = predicates.instantiate(self.tcx, subst);
373 for (predicate, predicate_span) in
374 predicates.predicates.iter().zip(&predicates.spans)
375 {
376 let obligation = Obligation::new(
377 ObligationCause::dummy_with_span(callee_expr.span),
378 self.param_env,
379 *predicate,
380 );
381 let result = self.evaluate_obligation(&obligation);
382 self.tcx
383 .sess
384 .struct_span_err(
385 callee_expr.span,
386 &format!("evaluate({:?}) = {:?}", predicate, result),
387 )
388 .span_label(*predicate_span, "predicate")
389 .emit();
390 }
391 }
392 (fn_sig, Some(def_id))
393 }
394 ty::FnPtr(sig) => (sig, None),
395 _ => {
396 let mut unit_variant = None;
397 if let hir::ExprKind::Path(qpath) = &callee_expr.kind
398 && let Res::Def(def::DefKind::Ctor(kind, def::CtorKind::Const), _)
399 = self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
400 // Only suggest removing parens if there are no arguments
401 && arg_exprs.is_empty()
402 {
403 let descr = match kind {
404 def::CtorOf::Struct => "struct",
405 def::CtorOf::Variant => "enum variant",
406 };
407 let removal_span =
408 callee_expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
409 unit_variant =
410 Some((removal_span, descr, rustc_hir_pretty::qpath_to_string(qpath)));
411 }
412
413 let callee_ty = self.resolve_vars_if_possible(callee_ty);
414 let mut err = type_error_struct!(
415 self.tcx.sess,
416 callee_expr.span,
417 callee_ty,
418 E0618,
419 "expected function, found {}",
420 match &unit_variant {
421 Some((_, kind, path)) => format!("{kind} `{path}`"),
422 None => format!("`{callee_ty}`"),
423 }
424 );
425
426 self.identify_bad_closure_def_and_call(
427 &mut err,
428 call_expr.hir_id,
429 &callee_expr.kind,
430 callee_expr.span,
431 );
432
433 if let Some((removal_span, kind, path)) = &unit_variant {
434 err.span_suggestion_verbose(
435 *removal_span,
436 &format!(
437 "`{path}` is a unit {kind}, and does not take parentheses to be constructed",
438 ),
439 "",
440 Applicability::MachineApplicable,
441 );
442 }
443
444 let mut inner_callee_path = None;
445 let def = match callee_expr.kind {
446 hir::ExprKind::Path(ref qpath) => {
447 self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
448 }
449 hir::ExprKind::Call(ref inner_callee, _) => {
450 // If the call spans more than one line and the callee kind is
451 // itself another `ExprCall`, that's a clue that we might just be
452 // missing a semicolon (Issue #51055)
453 let call_is_multiline =
454 self.tcx.sess.source_map().is_multiline(call_expr.span);
455 if call_is_multiline {
456 err.span_suggestion(
457 callee_expr.span.shrink_to_hi(),
458 "consider using a semicolon here",
459 ";",
460 Applicability::MaybeIncorrect,
461 );
462 }
463 if let hir::ExprKind::Path(ref inner_qpath) = inner_callee.kind {
464 inner_callee_path = Some(inner_qpath);
465 self.typeck_results.borrow().qpath_res(inner_qpath, inner_callee.hir_id)
466 } else {
467 Res::Err
468 }
469 }
470 _ => Res::Err,
471 };
472
473 if !self.maybe_suggest_bad_array_definition(&mut err, call_expr, callee_expr) {
474 err.span_label(call_expr.span, "call expression requires function");
475 }
476
477 if let Some(span) = self.tcx.hir().res_span(def) {
478 let callee_ty = callee_ty.to_string();
479 let label = match (unit_variant, inner_callee_path) {
480 (Some((_, kind, path)), _) => Some(format!("{kind} `{path}` defined here")),
481 (_, Some(hir::QPath::Resolved(_, path))) => self
482 .tcx
483 .sess
484 .source_map()
485 .span_to_snippet(path.span)
486 .ok()
487 .map(|p| format!("`{p}` defined here returns `{callee_ty}`")),
488 _ => {
489 match def {
490 // Emit a different diagnostic for local variables, as they are not
491 // type definitions themselves, but rather variables *of* that type.
492 Res::Local(hir_id) => Some(format!(
493 "`{}` has type `{}`",
494 self.tcx.hir().name(hir_id),
495 callee_ty
496 )),
497 Res::Def(kind, def_id) if kind.ns() == Some(Namespace::ValueNS) => {
498 Some(format!(
499 "`{}` defined here",
500 self.tcx.def_path_str(def_id),
501 ))
502 }
503 _ => Some(format!("`{callee_ty}` defined here")),
504 }
505 }
506 };
507 if let Some(label) = label {
508 err.span_label(span, label);
509 }
510 }
511 err.emit();
512
513 // This is the "default" function signature, used in case of error.
514 // In that case, we check each argument against "error" in order to
515 // set up all the node type bindings.
516 (
517 ty::Binder::dummy(self.tcx.mk_fn_sig(
518 self.err_args(arg_exprs.len()).into_iter(),
519 self.tcx.ty_error(),
520 false,
521 hir::Unsafety::Normal,
522 abi::Abi::Rust,
523 )),
524 None,
525 )
526 }
527 };
528
529 // Replace any late-bound regions that appear in the function
530 // signature with region variables. We also have to
531 // renormalize the associated types at this point, since they
532 // previously appeared within a `Binder<>` and hence would not
533 // have been normalized before.
534 let fn_sig = self.replace_bound_vars_with_fresh_vars(call_expr.span, infer::FnCall, fn_sig);
535 let fn_sig = self.normalize_associated_types_in(call_expr.span, fn_sig);
536
537 // Call the generic checker.
538 let expected_arg_tys = self.expected_inputs_for_expected_output(
539 call_expr.span,
540 expected,
541 fn_sig.output(),
542 fn_sig.inputs(),
543 );
544 self.check_argument_types(
545 call_expr.span,
546 call_expr,
547 fn_sig.inputs(),
548 expected_arg_tys,
549 arg_exprs,
550 fn_sig.c_variadic,
551 TupleArgumentsFlag::DontTupleArguments,
552 def_id,
553 );
554
555 fn_sig.output()
556 }
557
558 fn confirm_deferred_closure_call(
559 &self,
560 call_expr: &'tcx hir::Expr<'tcx>,
561 arg_exprs: &'tcx [hir::Expr<'tcx>],
562 expected: Expectation<'tcx>,
563 closure_def_id: LocalDefId,
564 fn_sig: ty::FnSig<'tcx>,
565 ) -> Ty<'tcx> {
566 // `fn_sig` is the *signature* of the closure being called. We
567 // don't know the full details yet (`Fn` vs `FnMut` etc), but we
568 // do know the types expected for each argument and the return
569 // type.
570
571 let expected_arg_tys = self.expected_inputs_for_expected_output(
572 call_expr.span,
573 expected,
574 fn_sig.output(),
575 fn_sig.inputs(),
576 );
577
578 self.check_argument_types(
579 call_expr.span,
580 call_expr,
581 fn_sig.inputs(),
582 expected_arg_tys,
583 arg_exprs,
584 fn_sig.c_variadic,
585 TupleArgumentsFlag::TupleArguments,
586 Some(closure_def_id.to_def_id()),
587 );
588
589 fn_sig.output()
590 }
591
592 fn confirm_overloaded_call(
593 &self,
594 call_expr: &'tcx hir::Expr<'tcx>,
595 arg_exprs: &'tcx [hir::Expr<'tcx>],
596 expected: Expectation<'tcx>,
597 method_callee: MethodCallee<'tcx>,
598 ) -> Ty<'tcx> {
599 let output_type = self.check_method_argument_types(
600 call_expr.span,
601 call_expr,
602 Ok(method_callee),
603 arg_exprs,
604 TupleArgumentsFlag::TupleArguments,
605 expected,
606 );
607
608 self.write_method_call(call_expr.hir_id, method_callee);
609 output_type
610 }
611 }
612
613 #[derive(Debug)]
614 pub struct DeferredCallResolution<'tcx> {
615 call_expr: &'tcx hir::Expr<'tcx>,
616 callee_expr: &'tcx hir::Expr<'tcx>,
617 adjusted_ty: Ty<'tcx>,
618 adjustments: Vec<Adjustment<'tcx>>,
619 fn_sig: ty::FnSig<'tcx>,
620 closure_substs: SubstsRef<'tcx>,
621 }
622
623 impl<'a, 'tcx> DeferredCallResolution<'tcx> {
624 pub fn resolve(self, fcx: &FnCtxt<'a, 'tcx>) {
625 debug!("DeferredCallResolution::resolve() {:?}", self);
626
627 // we should not be invoked until the closure kind has been
628 // determined by upvar inference
629 assert!(fcx.closure_kind(self.closure_substs).is_some());
630
631 // We may now know enough to figure out fn vs fnmut etc.
632 match fcx.try_overloaded_call_traits(self.call_expr, self.adjusted_ty, None) {
633 Some((autoref, method_callee)) => {
634 // One problem is that when we get here, we are going
635 // to have a newly instantiated function signature
636 // from the call trait. This has to be reconciled with
637 // the older function signature we had before. In
638 // principle we *should* be able to fn_sigs(), but we
639 // can't because of the annoying need for a TypeTrace.
640 // (This always bites me, should find a way to
641 // refactor it.)
642 let method_sig = method_callee.sig;
643
644 debug!("attempt_resolution: method_callee={:?}", method_callee);
645
646 for (method_arg_ty, self_arg_ty) in
647 iter::zip(method_sig.inputs().iter().skip(1), self.fn_sig.inputs())
648 {
649 fcx.demand_eqtype(self.call_expr.span, *self_arg_ty, *method_arg_ty);
650 }
651
652 fcx.demand_eqtype(self.call_expr.span, method_sig.output(), self.fn_sig.output());
653
654 let mut adjustments = self.adjustments;
655 adjustments.extend(autoref);
656 fcx.apply_adjustments(self.callee_expr, adjustments);
657
658 fcx.write_method_call(self.call_expr.hir_id, method_callee);
659 }
660 None => {
661 // This can happen if `#![no_core]` is used and the `fn/fn_mut/fn_once`
662 // lang items are not defined (issue #86238).
663 let mut err = fcx.inh.tcx.sess.struct_span_err(
664 self.call_expr.span,
665 "failed to find an overloaded call trait for closure call",
666 );
667 err.help(
668 "make sure the `fn`/`fn_mut`/`fn_once` lang items are defined \
669 and have associated `call`/`call_mut`/`call_once` functions",
670 );
671 err.emit();
672 }
673 }
674 }
675 }