@@ -11,7 +11,7 @@ use std::ops::ControlFlow;
11
11
use hir:: LangItem ;
12
12
use hir:: def_id:: DefId ;
13
13
use rustc_data_structures:: fx:: { FxHashSet , FxIndexSet } ;
14
- use rustc_hir as hir;
14
+ use rustc_hir:: { self as hir, CoroutineDesugaring , CoroutineKind } ;
15
15
use rustc_infer:: traits:: { Obligation , PolyTraitObligation , SelectionError } ;
16
16
use rustc_middle:: ty:: fast_reject:: DeepRejectCtxt ;
17
17
use rustc_middle:: ty:: { self , Ty , TypeVisitableExt , TypingMode , elaborate} ;
@@ -438,6 +438,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
438
438
}
439
439
}
440
440
441
+ #[ instrument( level = "debug" , skip( self , candidates) ) ]
441
442
fn assemble_async_closure_candidates (
442
443
& mut self ,
443
444
obligation : & PolyTraitObligation < ' tcx > ,
@@ -446,15 +447,30 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
446
447
let goal_kind =
447
448
self . tcx ( ) . async_fn_trait_kind_from_def_id ( obligation. predicate . def_id ( ) ) . unwrap ( ) ;
448
449
450
+ debug ! ( "self_ty = {:?}" , obligation. self_ty( ) . skip_binder( ) . kind( ) ) ;
449
451
match * obligation. self_ty ( ) . skip_binder ( ) . kind ( ) {
450
- ty:: CoroutineClosure ( _ , args) => {
452
+ ty:: CoroutineClosure ( def_id , args) => {
451
453
if let Some ( closure_kind) =
452
454
args. as_coroutine_closure ( ) . kind_ty ( ) . to_opt_closure_kind ( )
453
455
&& !closure_kind. extends ( goal_kind)
454
456
{
455
457
return ;
456
458
}
457
- candidates. vec . push ( AsyncClosureCandidate ) ;
459
+
460
+ // Make sure this is actually an async closure.
461
+ let Some ( coroutine_kind) =
462
+ self . tcx ( ) . coroutine_kind ( self . tcx ( ) . coroutine_for_closure ( def_id) )
463
+ else {
464
+ bug ! ( "coroutine with no kind" ) ;
465
+ } ;
466
+
467
+ debug ! ( ?coroutine_kind) ;
468
+ match coroutine_kind {
469
+ CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) => {
470
+ candidates. vec . push ( AsyncClosureCandidate ) ;
471
+ }
472
+ _ => ( ) ,
473
+ }
458
474
}
459
475
// Closures and fn pointers implement `AsyncFn*` if their return types
460
476
// implement `Future`, which is checked later.
0 commit comments