about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-10-29 18:38:57 +0100
committerGitHub <noreply@github.com>2024-10-29 18:38:57 +0100
commit5dc36391fe72d3e6e6b65657b119faa1fc3b3e5a (patch)
tree12a04e5e259abde6605dc1d104ca709705ac1e62 /compiler
parent5d6c49938e84c5af5b1c91cb570c995bb59ce1db (diff)
parentad76564900f353d3aca8ddcce48755f9903a6896 (diff)
Rollup merge of #132151 - compiler-errors:coroutine-resume-outlives, r=spastorino
Ensure that resume arg outlives region bound for coroutines

When proving that `{Coroutine}: 'region`, we must also prove that the coroutine's resume ty outlives that region as well. See the inline comment.

Fixes #132104
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_type_ir/src/outlives.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_type_ir/src/outlives.rs b/compiler/rustc_type_ir/src/outlives.rs
index ac35215fbaa..0e94e989b97 100644
--- a/compiler/rustc_type_ir/src/outlives.rs
+++ b/compiler/rustc_type_ir/src/outlives.rs
@@ -110,6 +110,18 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> {
             ty::Coroutine(_, args) => {
                 args.as_coroutine().tupled_upvars_ty().visit_with(self);
 
+                // Coroutines may not outlive a region unless the resume
+                // ty outlives a region. This is because the resume ty may
+                // store data that lives shorter than this outlives region
+                // across yield points, which may subsequently be accessed
+                // after the coroutine is resumed again.
+                //
+                // Conceptually, you may think of the resume arg as an upvar
+                // of `&mut Option<ResumeArgTy>`, since it is kinda like
+                // storage shared between the callee of the coroutine and the
+                // coroutine body.
+                args.as_coroutine().resume_ty().visit_with(self);
+
                 // We ignore regions in the coroutine interior as we don't
                 // want these to affect region inference
             }