Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #22832 from Veykril/lukaswirth/push-ntxsszurymwp
fix: Fix coroutines not recording binding owners correctly
Lukas Wirth 4 weeks ago
parent 7a5ecc8 · parent 6451cd4 · commit 19fad11
-rw-r--r--crates/hir-def/src/expr_store/lower.rs66
-rw-r--r--crates/ide/src/inlay_hints/closure_captures.rs19
2 files changed, 55 insertions, 30 deletions
diff --git a/crates/hir-def/src/expr_store/lower.rs b/crates/hir-def/src/expr_store/lower.rs
index 5cbcfe5f23..41edca07c7 100644
--- a/crates/hir-def/src/expr_store/lower.rs
+++ b/crates/hir-def/src/expr_store/lower.rs
@@ -1364,16 +1364,18 @@ impl<'db> ExprCollector<'db> {
let capture_by =
if e.move_token().is_some() { CaptureBy::Value } else { CaptureBy::Ref };
self.with_label_rib(RibKind::Closure, |this| {
- this.with_awaitable_block(Awaitable::Yes, |this| {
- this.collect_block_(e, |this, id, statements, tail| {
- this.desugared_coroutine_expr(
- CoroutineKind::Async,
- CoroutineSource::Block,
- capture_by,
- id,
- statements,
- tail,
- )
+ this.with_binding_owner(|this| {
+ this.with_awaitable_block(Awaitable::Yes, |this| {
+ this.collect_block_(e, |this, id, statements, tail| {
+ this.desugared_coroutine_expr(
+ CoroutineKind::Async,
+ CoroutineSource::Block,
+ capture_by,
+ id,
+ statements,
+ tail,
+ )
+ })
})
})
})
@@ -1382,16 +1384,18 @@ impl<'db> ExprCollector<'db> {
let capture_by =
if e.move_token().is_some() { CaptureBy::Value } else { CaptureBy::Ref };
self.with_label_rib(RibKind::Closure, |this| {
- this.with_awaitable_block(Awaitable::No("non-async gen block"), |this| {
- this.collect_block_(e, |this, id, statements, tail| {
- this.desugared_coroutine_expr(
- CoroutineKind::Gen,
- CoroutineSource::Block,
- capture_by,
- id,
- statements,
- tail,
- )
+ this.with_binding_owner(|this| {
+ this.with_awaitable_block(Awaitable::No("non-async gen block"), |this| {
+ this.collect_block_(e, |this, id, statements, tail| {
+ this.desugared_coroutine_expr(
+ CoroutineKind::Gen,
+ CoroutineSource::Block,
+ capture_by,
+ id,
+ statements,
+ tail,
+ )
+ })
})
})
})
@@ -1400,16 +1404,18 @@ impl<'db> ExprCollector<'db> {
let capture_by =
if e.move_token().is_some() { CaptureBy::Value } else { CaptureBy::Ref };
self.with_label_rib(RibKind::Closure, |this| {
- this.with_awaitable_block(Awaitable::Yes, |this| {
- this.collect_block_(e, |this, id, statements, tail| {
- this.desugared_coroutine_expr(
- CoroutineKind::AsyncGen,
- CoroutineSource::Block,
- capture_by,
- id,
- statements,
- tail,
- )
+ this.with_binding_owner(|this| {
+ this.with_awaitable_block(Awaitable::Yes, |this| {
+ this.collect_block_(e, |this, id, statements, tail| {
+ this.desugared_coroutine_expr(
+ CoroutineKind::AsyncGen,
+ CoroutineSource::Block,
+ capture_by,
+ id,
+ statements,
+ tail,
+ )
+ })
})
})
})
diff --git a/crates/ide/src/inlay_hints/closure_captures.rs b/crates/ide/src/inlay_hints/closure_captures.rs
index 3f0e4e7b05..dc36bd776d 100644
--- a/crates/ide/src/inlay_hints/closure_captures.rs
+++ b/crates/ide/src/inlay_hints/closure_captures.rs
@@ -267,6 +267,25 @@ fn main() {
}
#[test]
+ fn nested_coroutine_does_not_capture_parent_local() {
+ check_with_config(
+ InlayHintsConfig { closure_capture_hints: true, ..DISABLED_CONFIG },
+ r#"
+//- minicore: copy, future
+fn main() {
+ async {
+ let foo = 1;
+ async {
+ // ^ move(&foo)
+ foo;
+ }
+ };
+}
+"#,
+ );
+ }
+
+ #[test]
fn coroutine_blocks() {
check_with_config(
InlayHintsConfig { closure_capture_hints: true, ..DISABLED_CONFIG },