@@ -813,38 +813,17 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
813813 obligation : & PredicateObligation < ' tcx > ,
814814 mut trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
815815 ) -> Option < ErrorGuaranteed > {
816- // If `AsyncFnKindHelper` is not implemented, that means that the closure kind
817- // doesn't extend the goal kind. This is worth reporting, but we can only do so
818- // if we actually know which closure this goal comes from, so look at the cause
819- // to see if we can extract that information.
820- if self . tcx . is_lang_item ( trait_pred. def_id ( ) , LangItem :: AsyncFnKindHelper )
821- && let Some ( found_kind) =
822- trait_pred. skip_binder ( ) . trait_ref . args . type_at ( 0 ) . to_opt_closure_kind ( )
823- && let Some ( expected_kind) =
824- trait_pred. skip_binder ( ) . trait_ref . args . type_at ( 1 ) . to_opt_closure_kind ( )
825- && !found_kind. extends ( expected_kind)
826- {
827- if let Some ( ( _, Some ( parent) ) ) = obligation. cause . code ( ) . parent_with_predicate ( ) {
828- // If we have a derived obligation, then the parent will be a `AsyncFn*` goal.
816+ // If we end up on an `AsyncFnKindHelper` goal, try to unwrap the parent
817+ // `AsyncFn*` goal.
818+ if self . tcx . is_lang_item ( trait_pred. def_id ( ) , LangItem :: AsyncFnKindHelper ) {
819+ let mut code = obligation. cause . code ( ) ;
820+ // Unwrap a `FunctionArg` cause, which has been refined from a derived obligation.
821+ if let ObligationCauseCode :: FunctionArg { parent_code, .. } = code {
822+ code = & * * parent_code;
823+ }
824+ // If we have a derived obligation, then the parent will be a `AsyncFn*` goal.
825+ if let Some ( ( _, Some ( parent) ) ) = code. parent_with_predicate ( ) {
829826 trait_pred = parent;
830- } else if let & ObligationCauseCode :: FunctionArg { arg_hir_id, .. } =
831- obligation. cause . code ( )
832- && let Some ( typeck_results) = & self . typeck_results
833- && let ty:: Closure ( closure_def_id, _) | ty:: CoroutineClosure ( closure_def_id, _) =
834- * typeck_results. node_type ( arg_hir_id) . kind ( )
835- {
836- // Otherwise, extract the closure kind from the obligation,
837- // but only if we actually have an argument to deduce the
838- // closure type from...
839- let mut err = self . report_closure_error (
840- & obligation,
841- closure_def_id,
842- found_kind,
843- expected_kind,
844- "Async" ,
845- ) ;
846- self . note_obligation_cause ( & mut err, & obligation) ;
847- return Some ( err. emit ( ) ) ;
848827 }
849828 }
850829
0 commit comments