@@ -56,7 +56,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5656 // closure sooner rather than later, so first examine the expected
5757 // type, and see if can glean a closure kind from there.
5858 let ( expected_sig, expected_kind) = match expected. to_option ( self ) {
59- Some ( ty) => self . deduce_closure_signature ( ty) ,
59+ Some ( ty) => {
60+ self . deduce_closure_signature ( self . try_structurally_resolve_type ( expr_span, ty) )
61+ }
6062 None => ( None , None ) ,
6163 } ;
6264 let body = self . tcx . hir ( ) . body ( closure. body ) ;
@@ -688,8 +690,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
688690 span_bug ! ( self . tcx. def_span( expr_def_id) , "async fn generator outside of a fn" )
689691 } ) ;
690692
693+ let closure_span = self . tcx . def_span ( expr_def_id) ;
691694 let ret_ty = ret_coercion. borrow ( ) . expected_ty ( ) ;
692- let ret_ty = self . inh . infcx . shallow_resolve ( ret_ty) ;
695+ let ret_ty = self . try_structurally_resolve_type ( closure_span , ret_ty) ;
693696
694697 let get_future_output = |predicate : ty:: Predicate < ' tcx > , span| {
695698 // Search for a pending obligation like
@@ -711,8 +714,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
711714 }
712715 } ;
713716
714- let span = self . tcx . def_span ( expr_def_id) ;
715-
716717 let output_ty = match * ret_ty. kind ( ) {
717718 ty:: Infer ( ty:: TyVar ( ret_vid) ) => {
718719 self . obligations_for_self_ty ( ret_vid) . find_map ( |obligation| {
@@ -726,17 +727,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
726727 . find_map ( |( p, s) | get_future_output ( p. as_predicate ( ) , s) ) ?,
727728 ty:: Error ( _) => return None ,
728729 _ => span_bug ! (
729- span ,
730+ closure_span ,
730731 "async fn generator return type not an inference variable: {ret_ty}"
731732 ) ,
732733 } ;
733734
734- let output_ty = self . normalize ( span , output_ty) ;
735+ let output_ty = self . normalize ( closure_span , output_ty) ;
735736
736737 // async fn that have opaque types in their return type need to redo the conversion to inference variables
737738 // as they fetch the still opaque version from the signature.
738739 let InferOk { value : output_ty, obligations } = self
739- . replace_opaque_types_with_inference_vars ( output_ty, body_def_id, span, self . param_env ) ;
740+ . replace_opaque_types_with_inference_vars (
741+ output_ty,
742+ body_def_id,
743+ closure_span,
744+ self . param_env ,
745+ ) ;
740746 self . register_predicates ( obligations) ;
741747
742748 Some ( output_ty)
0 commit comments