@@ -78,7 +78,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
78
78
_ => self . check_expr ( callee_expr) ,
79
79
} ;
80
80
81
- let expr_ty = self . structurally_resolve_type ( call_expr. span , original_callee_ty) ;
81
+ let expr_ty = self . try_structurally_resolve_type ( call_expr. span , original_callee_ty) ;
82
82
83
83
let mut autoderef = self . autoderef ( callee_expr. span , expr_ty) ;
84
84
let mut result = None ;
@@ -200,7 +200,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
200
200
arg_exprs : & ' tcx [ hir:: Expr < ' tcx > ] ,
201
201
autoderef : & Autoderef < ' a , ' tcx > ,
202
202
) -> Option < CallStep < ' tcx > > {
203
- let adjusted_ty = self . structurally_resolve_type ( autoderef. span ( ) , autoderef. final_ty ( ) ) ;
203
+ let adjusted_ty =
204
+ self . try_structurally_resolve_type ( autoderef. span ( ) , autoderef. final_ty ( ) ) ;
204
205
205
206
// If the callee is a function pointer or a closure, then we're all set.
206
207
match * adjusted_ty. kind ( ) {
@@ -297,6 +298,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
297
298
return None ;
298
299
}
299
300
301
+ ty:: Infer ( ty:: TyVar ( vid) ) => {
302
+ // If we end up with an inference variable which is not the hidden type of
303
+ // an opaque, emit an error.
304
+ if !self . has_opaques_with_sub_unified_hidden_type ( vid) {
305
+ self . type_must_be_known_at_this_point ( autoderef. span ( ) , adjusted_ty) ;
306
+ return None ;
307
+ }
308
+ }
309
+
300
310
ty:: Error ( _) => {
301
311
return None ;
302
312
}
@@ -367,35 +377,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
367
377
Ty :: new_tup_from_iter ( self . tcx , arg_exprs. iter ( ) . map ( |e| self . next_ty_var ( e. span ) ) )
368
378
} ) ;
369
379
370
- if let Some ( ok) = self . lookup_method_for_operator (
380
+ let Some ( ok) = self . lookup_method_for_operator (
371
381
self . misc ( call_expr. span ) ,
372
382
method_name,
373
383
trait_def_id,
374
384
adjusted_ty,
375
385
opt_input_type,
376
- ) {
377
- let method = self . register_infer_ok_obligations ( ok) ;
378
- let mut autoref = None ;
379
- if borrow {
380
- // Check for &self vs &mut self in the method signature. Since this is either
381
- // the Fn or FnMut trait, it should be one of those.
382
- let ty:: Ref ( _, _, mutbl) = method. sig . inputs ( ) [ 0 ] . kind ( ) else {
383
- bug ! ( "Expected `FnMut`/`Fn` to take receiver by-ref/by-mut" )
384
- } ;
385
-
386
- // For initial two-phase borrow
387
- // deployment, conservatively omit
388
- // overloaded function call ops.
389
- let mutbl = AutoBorrowMutability :: new ( * mutbl, AllowTwoPhase :: No ) ;
390
-
391
- autoref = Some ( Adjustment {
392
- kind : Adjust :: Borrow ( AutoBorrow :: Ref ( mutbl) ) ,
393
- target : method. sig . inputs ( ) [ 0 ] ,
394
- } ) ;
395
- }
386
+ ) else {
387
+ continue ;
388
+ } ;
389
+ let method = self . register_infer_ok_obligations ( ok) ;
390
+ let mut autoref = None ;
391
+ if borrow {
392
+ // Check for &self vs &mut self in the method signature. Since this is either
393
+ // the Fn or FnMut trait, it should be one of those.
394
+ let ty:: Ref ( _, _, mutbl) = * method. sig . inputs ( ) [ 0 ] . kind ( ) else {
395
+ bug ! ( "Expected `FnMut`/`Fn` to take receiver by-ref/by-mut" )
396
+ } ;
396
397
397
- return Some ( ( autoref, method) ) ;
398
+ // For initial two-phase borrow
399
+ // deployment, conservatively omit
400
+ // overloaded function call ops.
401
+ let mutbl = AutoBorrowMutability :: new ( mutbl, AllowTwoPhase :: No ) ;
402
+
403
+ autoref = Some ( Adjustment {
404
+ kind : Adjust :: Borrow ( AutoBorrow :: Ref ( mutbl) ) ,
405
+ target : method. sig . inputs ( ) [ 0 ] ,
406
+ } ) ;
398
407
}
408
+
409
+ return Some ( ( autoref, method) ) ;
399
410
}
400
411
401
412
None
0 commit comments