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