HACK: constrain yield type in check_fn so that projection is successful even with no yield
This commit is contained in:
parent
44911b7c67
commit
4c77058562
1 changed files with 23 additions and 3 deletions
|
@ -59,9 +59,7 @@ pub(super) fn check_fn<'a, 'tcx>(
|
||||||
&& can_be_coroutine.is_some()
|
&& can_be_coroutine.is_some()
|
||||||
{
|
{
|
||||||
let yield_ty = match kind {
|
let yield_ty = match kind {
|
||||||
hir::CoroutineKind::Gen(..)
|
hir::CoroutineKind::Gen(..) | hir::CoroutineKind::Coroutine => {
|
||||||
| hir::CoroutineKind::AsyncGen(..)
|
|
||||||
| hir::CoroutineKind::Coroutine => {
|
|
||||||
let yield_ty = fcx.next_ty_var(TypeVariableOrigin {
|
let yield_ty = fcx.next_ty_var(TypeVariableOrigin {
|
||||||
kind: TypeVariableOriginKind::TypeInference,
|
kind: TypeVariableOriginKind::TypeInference,
|
||||||
span,
|
span,
|
||||||
|
@ -69,6 +67,28 @@ pub(super) fn check_fn<'a, 'tcx>(
|
||||||
fcx.require_type_is_sized(yield_ty, span, traits::SizedYieldType);
|
fcx.require_type_is_sized(yield_ty, span, traits::SizedYieldType);
|
||||||
yield_ty
|
yield_ty
|
||||||
}
|
}
|
||||||
|
// HACK(-Ztrait-solver=next): In the *old* trait solver, we must eagerly
|
||||||
|
// guide inference on the yield type so that we can handle `AsyncIterator`
|
||||||
|
// in this block in projection correctly. In the new trait solver, it is
|
||||||
|
// not a problem.
|
||||||
|
hir::CoroutineKind::AsyncGen(..) => {
|
||||||
|
let yield_ty = fcx.next_ty_var(TypeVariableOrigin {
|
||||||
|
kind: TypeVariableOriginKind::TypeInference,
|
||||||
|
span,
|
||||||
|
});
|
||||||
|
fcx.require_type_is_sized(yield_ty, span, traits::SizedYieldType);
|
||||||
|
|
||||||
|
Ty::new_adt(
|
||||||
|
tcx,
|
||||||
|
tcx.adt_def(tcx.require_lang_item(hir::LangItem::Poll, Some(span))),
|
||||||
|
tcx.mk_args(&[Ty::new_adt(
|
||||||
|
tcx,
|
||||||
|
tcx.adt_def(tcx.require_lang_item(hir::LangItem::Option, Some(span))),
|
||||||
|
tcx.mk_args(&[yield_ty.into()]),
|
||||||
|
)
|
||||||
|
.into()]),
|
||||||
|
)
|
||||||
|
}
|
||||||
hir::CoroutineKind::Async(..) => Ty::new_unit(tcx),
|
hir::CoroutineKind::Async(..) => Ty::new_unit(tcx),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue