@@ -359,7 +359,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
359
359
360
360
let obligation = traits:: Obligation :: new (
361
361
self . tcx ,
362
- cause,
362
+ cause. clone ( ) ,
363
363
self . param_env ,
364
364
ty:: TraitRef :: new_from_args ( self . tcx , trait_def_id, args) ,
365
365
) ;
@@ -385,6 +385,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
385
385
386
386
debug ! ( "lookup_in_trait_adjusted: method_item={:?}" , method_item) ;
387
387
let mut obligations = PredicateObligations :: new ( ) ;
388
+ // Register the operator's obligation first to constrain the "rhs" argument (or inputs
389
+ // for a fn-like operator). This would happen coincidentally as part of normalizing the
390
+ // signature below if the output type is constrained but a param-env predicate, but for
391
+ // `AsyncFn*`, the output type doesn't actually show up in the signature, so we end up
392
+ // trying to prove other WF predicates first which incompletely constrains the type.
393
+ obligations. push ( obligation) ;
388
394
389
395
// Instantiate late-bound regions and instantiate the trait
390
396
// parameters into the method type to get the actual method type.
@@ -393,11 +399,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
393
399
// function signature so that normalization does not need to deal
394
400
// with bound regions.
395
401
let fn_sig = tcx. fn_sig ( def_id) . instantiate ( self . tcx , args) ;
396
- let fn_sig =
397
- self . instantiate_binder_with_fresh_vars ( obligation. cause . span , infer:: FnCall , fn_sig) ;
402
+ let fn_sig = self . instantiate_binder_with_fresh_vars ( cause. span , infer:: FnCall , fn_sig) ;
398
403
399
404
let InferOk { value : fn_sig, obligations : o } =
400
- self . at ( & obligation . cause , self . param_env ) . normalize ( fn_sig) ;
405
+ self . at ( & cause, self . param_env ) . normalize ( fn_sig) ;
401
406
obligations. extend ( o) ;
402
407
403
408
// Register obligations for the parameters. This will include the
@@ -411,26 +416,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
411
416
let bounds = self . tcx . predicates_of ( def_id) . instantiate ( self . tcx , args) ;
412
417
413
418
let InferOk { value : bounds, obligations : o } =
414
- self . at ( & obligation . cause , self . param_env ) . normalize ( bounds) ;
419
+ self . at ( & cause, self . param_env ) . normalize ( bounds) ;
415
420
obligations. extend ( o) ;
416
421
assert ! ( !bounds. has_escaping_bound_vars( ) ) ;
417
422
418
- let predicates_cause = obligation. cause . clone ( ) ;
419
423
obligations. extend ( traits:: predicates_for_generics (
420
- move |_, _| predicates_cause . clone ( ) ,
424
+ |_, _| cause . clone ( ) ,
421
425
self . param_env ,
422
426
bounds,
423
427
) ) ;
424
428
425
429
// Also add an obligation for the method type being well-formed.
426
430
let method_ty = Ty :: new_fn_ptr ( tcx, ty:: Binder :: dummy ( fn_sig) ) ;
427
- debug ! (
428
- "lookup_method_in_trait: matched method method_ty={:?} obligation={:?}" ,
429
- method_ty, obligation
430
- ) ;
431
+ debug ! ( "lookup_method_in_trait: matched method method_ty={:?}" , method_ty) ;
432
+
431
433
obligations. push ( traits:: Obligation :: new (
432
434
tcx,
433
- obligation . cause ,
435
+ cause. clone ( ) ,
434
436
self . param_env ,
435
437
ty:: Binder :: dummy ( ty:: PredicateKind :: Clause ( ty:: ClauseKind :: WellFormed (
436
438
method_ty. into ( ) ,
0 commit comments