about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-12-07 18:36:55 +0000
committerMichael Goulet <michael@errs.io>2023-12-08 17:23:26 +0000
commit4c770585622ea6159b78af6b8323722c6636c33c (patch)
treed28690fa113264f2b631e0260f67e56b87bb2585 /compiler
parent44911b7c67a0041d06ce959aaec5a3521155a09f (diff)
downloadrust-4c770585622ea6159b78af6b8323722c6636c33c.tar.gz
rust-4c770585622ea6159b78af6b8323722c6636c33c.zip
HACK: constrain yield type in check_fn so that projection is successful even with no yield
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_typeck/src/check.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/compiler/rustc_hir_typeck/src/check.rs b/compiler/rustc_hir_typeck/src/check.rs
index 91c96d6f76f..19b566ff9fa 100644
--- a/compiler/rustc_hir_typeck/src/check.rs
+++ b/compiler/rustc_hir_typeck/src/check.rs
@@ -59,9 +59,7 @@ pub(super) fn check_fn<'a, 'tcx>(
         && can_be_coroutine.is_some()
     {
         let yield_ty = match kind {
-            hir::CoroutineKind::Gen(..)
-            | hir::CoroutineKind::AsyncGen(..)
-            | hir::CoroutineKind::Coroutine => {
+            hir::CoroutineKind::Gen(..) | hir::CoroutineKind::Coroutine => {
                 let yield_ty = fcx.next_ty_var(TypeVariableOrigin {
                     kind: TypeVariableOriginKind::TypeInference,
                     span,
@@ -69,6 +67,28 @@ pub(super) fn check_fn<'a, 'tcx>(
                 fcx.require_type_is_sized(yield_ty, span, traits::SizedYieldType);
                 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),
         };