@@ -923,14 +923,22 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
923
923
[ self_ty, Ty :: new_tup ( tcx, sig. inputs ( ) ) ] ,
924
924
)
925
925
} ) ;
926
+
926
927
// We must additionally check that the return type impls `Future`.
928
+
929
+ // FIXME(async_closures): Investigate this before stabilization.
930
+ // We instantiate this binder eagerly because the `confirm_future_candidate`
931
+ // method doesn't support higher-ranked futures, which the `AsyncFn`
932
+ // traits expressly allow the user to write. To fix this correctly,
933
+ // we'd need to instantiate trait bounds before we get to selection,
934
+ // like the new trait solver does.
927
935
let future_trait_def_id = tcx. require_lang_item ( LangItem :: Future , None ) ;
936
+ let placeholder_output_ty = self . infcx . enter_forall_and_leak_universe ( sig. output ( ) ) ;
928
937
nested. push ( obligation. with (
929
938
tcx,
930
- sig. map_bound ( |sig| {
931
- ty:: TraitRef :: new ( tcx, future_trait_def_id, [ sig. output ( ) ] )
932
- } ) ,
939
+ ty:: TraitRef :: new ( tcx, future_trait_def_id, [ placeholder_output_ty] ) ,
933
940
) ) ;
941
+
934
942
( trait_ref, Ty :: from_closure_kind ( tcx, ty:: ClosureKind :: Fn ) )
935
943
}
936
944
ty:: Closure ( _, args) => {
@@ -943,14 +951,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
943
951
[ self_ty, sig. inputs ( ) [ 0 ] ] ,
944
952
)
945
953
} ) ;
954
+
946
955
// We must additionally check that the return type impls `Future`.
956
+ // See FIXME in last branch for why we instantiate the binder eagerly.
947
957
let future_trait_def_id = tcx. require_lang_item ( LangItem :: Future , None ) ;
958
+ let placeholder_output_ty = self . infcx . enter_forall_and_leak_universe ( sig. output ( ) ) ;
948
959
nested. push ( obligation. with (
949
960
tcx,
950
- sig. map_bound ( |sig| {
951
- ty:: TraitRef :: new ( tcx, future_trait_def_id, [ sig. output ( ) ] )
952
- } ) ,
961
+ ty:: TraitRef :: new ( tcx, future_trait_def_id, [ placeholder_output_ty] ) ,
953
962
) ) ;
963
+
954
964
( trait_ref, args. kind_ty ( ) )
955
965
}
956
966
_ => bug ! ( "expected callable type for AsyncFn candidate" ) ,
0 commit comments