@@ -11,7 +11,7 @@ use std::ops::ControlFlow;
1111use hir:: LangItem ;
1212use hir:: def_id:: DefId ;
1313use rustc_data_structures:: fx:: { FxHashSet , FxIndexSet } ;
14- use rustc_hir as hir;
14+ use rustc_hir:: { self as hir, CoroutineDesugaring , CoroutineKind } ;
1515use rustc_infer:: traits:: { Obligation , PolyTraitObligation , SelectionError } ;
1616use rustc_middle:: ty:: fast_reject:: DeepRejectCtxt ;
1717use rustc_middle:: ty:: { self , Ty , TypeVisitableExt , TypingMode , elaborate} ;
@@ -438,6 +438,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
438438 }
439439 }
440440
441+ #[ instrument( level = "debug" , skip( self , candidates) ) ]
441442 fn assemble_async_closure_candidates (
442443 & mut self ,
443444 obligation : & PolyTraitObligation < ' tcx > ,
@@ -446,15 +447,30 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
446447 let goal_kind =
447448 self . tcx ( ) . async_fn_trait_kind_from_def_id ( obligation. predicate . def_id ( ) ) . unwrap ( ) ;
448449
450+ debug ! ( "self_ty = {:?}" , obligation. self_ty( ) . skip_binder( ) . kind( ) ) ;
449451 match * obligation. self_ty ( ) . skip_binder ( ) . kind ( ) {
450- ty:: CoroutineClosure ( _ , args) => {
452+ ty:: CoroutineClosure ( def_id , args) => {
451453 if let Some ( closure_kind) =
452454 args. as_coroutine_closure ( ) . kind_ty ( ) . to_opt_closure_kind ( )
453455 && !closure_kind. extends ( goal_kind)
454456 {
455457 return ;
456458 }
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+ }
458474 }
459475 // Closures and fn pointers implement `AsyncFn*` if their return types
460476 // implement `Future`, which is checked later.
0 commit comments