Skip to content

Commit 4b35147

Browse files
Actually use the inferred ClosureKind from signature inference in coroutine-closures
1 parent bdbd3d2 commit 4b35147

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

tests/pass/async-closure-captures.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,38 @@ async fn async_main() {
8888
};
8989
call_once(c).await;
9090
}
91+
92+
fn force_fnonce<T>(f: impl async FnOnce() -> T) -> impl async FnOnce() -> T {
93+
f
94+
}
95+
96+
// Capture something with `move`, but infer to `AsyncFnOnce`
97+
{
98+
let x = Hello(6);
99+
let c = force_fnonce(async move || {
100+
println!("{x:?}");
101+
});
102+
call_once(c).await;
103+
104+
let x = &Hello(7);
105+
let c = force_fnonce(async move || {
106+
println!("{x:?}");
107+
});
108+
call_once(c).await;
109+
}
110+
111+
// Capture something by-ref, but infer to `AsyncFnOnce`
112+
{
113+
let x = Hello(8);
114+
let c = force_fnonce(async || {
115+
println!("{x:?}");
116+
});
117+
call_once(c).await;
118+
119+
let x = &Hello(9);
120+
let c = force_fnonce(async || {
121+
println!("{x:?}");
122+
});
123+
call_once(c).await;
124+
}
91125
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0597]: `x` does not live long enough
2+
--> $DIR/async-closure-captures.rs:LL:CC
3+
|
4+
LL | let c = force_fnonce(async move || {
5+
| ____________________________________________-
6+
LL | | println!("{x:?}");
7+
| | ^ borrowed value does not live long enough
8+
LL | | });
9+
| | --
10+
| | ||
11+
| | |`x` dropped here while still borrowed
12+
| |_________|borrow later used here
13+
| value captured here by coroutine
14+
15+
error[E0597]: `x` does not live long enough
16+
--> $DIR/async-closure-captures.rs:LL:CC
17+
|
18+
LL | let c = force_fnonce(async move || {
19+
| ____________________________________________-
20+
LL | | println!("{x:?}");
21+
| | ^ borrowed value does not live long enough
22+
LL | | });
23+
| | --
24+
| | ||
25+
| | |`x` dropped here while still borrowed
26+
| |_________|borrow later used here
27+
| value captured here by coroutine
28+
29+
error: aborting due to 2 previous errors
30+
31+
For more information about this error, try `rustc --explain E0597`.

tests/pass/async-closure-captures.stdout

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)