File tree 1 file changed +7
-3
lines changed
src/librustc_error_codes/error_codes
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 1
- This error occurs when an attempt is made to use data captured by a closure,
2
- when that data may no longer exist. It's most commonly seen when attempting to
3
- return a closure :
1
+ A captured variable in a closure may not live long enough.
2
+
3
+ Erroneous code example :
4
4
5
5
``` compile_fail,E0373
6
6
fn foo() -> Box<Fn(u32) -> u32> {
@@ -9,6 +9,10 @@ fn foo() -> Box<Fn(u32) -> u32> {
9
9
}
10
10
```
11
11
12
+ This error occurs when an attempt is made to use data captured by a closure,
13
+ when that data may no longer exist. It's most commonly seen when attempting to
14
+ return a closure as shown in the previous code example.
15
+
12
16
Notice that ` x ` is stack-allocated by ` foo() ` . By default, Rust captures
13
17
closed-over data by reference. This means that once ` foo() ` returns, ` x ` no
14
18
longer exists. An attempt to access ` x ` within the closure would thus be
You can’t perform that action at this time.
0 commit comments