File tree Expand file tree Collapse file tree 3 files changed +65
-10
lines changed Expand file tree Collapse file tree 3 files changed +65
-10
lines changed Original file line number Diff line number Diff line change @@ -88,4 +88,38 @@ async fn async_main() {
88
88
} ;
89
89
call_once ( c) . await ;
90
90
}
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
+ }
91
125
}
Original file line number Diff line number Diff line change
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`.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments