@@ -56,7 +56,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
56
56
// closure sooner rather than later, so first examine the expected
57
57
// type, and see if can glean a closure kind from there.
58
58
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
+ }
60
62
None => ( None , None ) ,
61
63
} ;
62
64
let body = self . tcx . hir ( ) . body ( closure. body ) ;
@@ -688,8 +690,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
688
690
span_bug ! ( self . tcx. def_span( expr_def_id) , "async fn generator outside of a fn" )
689
691
} ) ;
690
692
693
+ let closure_span = self . tcx . def_span ( expr_def_id) ;
691
694
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) ;
693
696
694
697
let get_future_output = |predicate : ty:: Predicate < ' tcx > , span| {
695
698
// Search for a pending obligation like
@@ -711,8 +714,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
711
714
}
712
715
} ;
713
716
714
- let span = self . tcx . def_span ( expr_def_id) ;
715
-
716
717
let output_ty = match * ret_ty. kind ( ) {
717
718
ty:: Infer ( ty:: TyVar ( ret_vid) ) => {
718
719
self . obligations_for_self_ty ( ret_vid) . find_map ( |obligation| {
@@ -726,17 +727,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
726
727
. find_map ( |( p, s) | get_future_output ( p. as_predicate ( ) , s) ) ?,
727
728
ty:: Error ( _) => return None ,
728
729
_ => span_bug ! (
729
- span ,
730
+ closure_span ,
730
731
"async fn generator return type not an inference variable: {ret_ty}"
731
732
) ,
732
733
} ;
733
734
734
- let output_ty = self . normalize ( span , output_ty) ;
735
+ let output_ty = self . normalize ( closure_span , output_ty) ;
735
736
736
737
// async fn that have opaque types in their return type need to redo the conversion to inference variables
737
738
// as they fetch the still opaque version from the signature.
738
739
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
+ ) ;
740
746
self . register_predicates ( obligations) ;
741
747
742
748
Some ( output_ty)
0 commit comments