@@ -896,6 +896,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
896
896
sig. tupled_inputs_ty ,
897
897
] )
898
898
} ) ;
899
+
900
+ // Note that unlike below, we don't need to check `Future + Sized` for
901
+ // the output coroutine because they are `Future + Sized` by construction.
902
+
899
903
( trait_ref, args. kind_ty ( ) )
900
904
}
901
905
ty:: FnDef ( ..) | ty:: FnPtr ( ..) => {
@@ -907,14 +911,21 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
907
911
] )
908
912
} ) ;
909
913
910
- // We must additionally check that the return type impls `Future`.
914
+ // We must additionally check that the return type impls `Future + Sized `.
911
915
let future_trait_def_id = tcx. require_lang_item ( LangItem :: Future , None ) ;
912
916
nested. push ( obligation. with (
913
917
tcx,
914
918
sig. output ( ) . map_bound ( |output_ty| {
915
919
ty:: TraitRef :: new ( tcx, future_trait_def_id, [ output_ty] )
916
920
} ) ,
917
921
) ) ;
922
+ let sized_trait_def_id = tcx. require_lang_item ( LangItem :: Sized , None ) ;
923
+ nested. push ( obligation. with (
924
+ tcx,
925
+ sig. output ( ) . map_bound ( |output_ty| {
926
+ ty:: TraitRef :: new ( tcx, sized_trait_def_id, [ output_ty] )
927
+ } ) ,
928
+ ) ) ;
918
929
919
930
( trait_ref, Ty :: from_closure_kind ( tcx, ty:: ClosureKind :: Fn ) )
920
931
}
@@ -928,14 +939,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
928
939
] )
929
940
} ) ;
930
941
931
- // We must additionally check that the return type impls `Future`.
932
- // See FIXME in last branch for why we instantiate the binder eagerly.
942
+ // We must additionally check that the return type impls `Future + Sized`.
933
943
let future_trait_def_id = tcx. require_lang_item ( LangItem :: Future , None ) ;
934
944
let placeholder_output_ty = self . infcx . enter_forall_and_leak_universe ( sig. output ( ) ) ;
935
945
nested. push ( obligation. with (
936
946
tcx,
937
947
ty:: TraitRef :: new ( tcx, future_trait_def_id, [ placeholder_output_ty] ) ,
938
948
) ) ;
949
+ let sized_trait_def_id = tcx. require_lang_item ( LangItem :: Sized , None ) ;
950
+ nested. push ( obligation. with (
951
+ tcx,
952
+ sig. output ( ) . map_bound ( |output_ty| {
953
+ ty:: TraitRef :: new ( tcx, sized_trait_def_id, [ output_ty] )
954
+ } ) ,
955
+ ) ) ;
939
956
940
957
( trait_ref, args. kind_ty ( ) )
941
958
}
0 commit comments