@@ -247,6 +247,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
247
247
adjusted_ty,
248
248
opt_input_type. as_ref ( ) . map ( slice:: from_ref) ,
249
249
) {
250
+ // Check for `self` receiver on the method, otherwise we can't use this as a `Fn*` trait.
251
+ if !self . tcx . associated_item ( ok. value . def_id ) . fn_has_self_parameter {
252
+ self . tcx . sess . delay_span_bug (
253
+ call_expr. span ,
254
+ "input to overloaded call fn is not a self receiver" ,
255
+ ) ;
256
+ return None ;
257
+ }
258
+
250
259
let method = self . register_infer_ok_obligations ( ok) ;
251
260
let mut autoref = None ;
252
261
if borrow {
@@ -257,7 +266,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
257
266
// caused an error elsewhere.
258
267
self . tcx
259
268
. sess
260
- . delay_span_bug ( call_expr. span , "input to call/call_mut is not a ref? " ) ;
269
+ . delay_span_bug ( call_expr. span , "input to call/call_mut is not a ref" ) ;
261
270
return None ;
262
271
} ;
263
272
@@ -271,6 +280,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
271
280
target : method. sig . inputs ( ) [ 0 ] ,
272
281
} ) ;
273
282
}
283
+
274
284
return Some ( ( autoref, method) ) ;
275
285
}
276
286
}
@@ -823,7 +833,7 @@ impl<'a, 'tcx> DeferredCallResolution<'tcx> {
823
833
) ;
824
834
err. help (
825
835
"make sure the `fn`/`fn_mut`/`fn_once` lang items are defined \
826
- and have associated `call`/`call_mut`/`call_once` functions ",
836
+ and have correctly defined `call`/`call_mut`/`call_once` methods ",
827
837
) ;
828
838
err. emit ( ) ;
829
839
}
0 commit comments