Skip to content

Commit 6aa29ae

Browse files
Make sure we check the future type is Sized in AsyncFn*
1 parent 93722f7 commit 6aa29ae

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -907,14 +907,21 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
907907
])
908908
});
909909

910-
// We must additionally check that the return type impls `Future`.
910+
// We must additionally check that the return type impls `Future + Sized`.
911911
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
912912
nested.push(obligation.with(
913913
tcx,
914914
sig.output().map_bound(|output_ty| {
915915
ty::TraitRef::new(tcx, future_trait_def_id, [output_ty])
916916
}),
917917
));
918+
let sized_trait_def_id = tcx.require_lang_item(LangItem::Sized, None);
919+
nested.push(obligation.with(
920+
tcx,
921+
sig.output().map_bound(|output_ty| {
922+
ty::TraitRef::new(tcx, sized_trait_def_id, [output_ty])
923+
}),
924+
));
918925

919926
(trait_ref, Ty::from_closure_kind(tcx, ty::ClosureKind::Fn))
920927
}
@@ -928,14 +935,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
928935
])
929936
});
930937

931-
// We must additionally check that the return type impls `Future`.
932-
// See FIXME in last branch for why we instantiate the binder eagerly.
938+
// We must additionally check that the return type impls `Future + Sized`.
933939
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
934940
let placeholder_output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
935941
nested.push(obligation.with(
936942
tcx,
937943
ty::TraitRef::new(tcx, future_trait_def_id, [placeholder_output_ty]),
938944
));
945+
let sized_trait_def_id = tcx.require_lang_item(LangItem::Sized, None);
946+
nested.push(obligation.with(
947+
tcx,
948+
sig.output().map_bound(|output_ty| {
949+
ty::TraitRef::new(tcx, sized_trait_def_id, [output_ty])
950+
}),
951+
));
939952

940953
(trait_ref, args.kind_ty())
941954
}

0 commit comments

Comments
 (0)