Rollup merge of #69480 - GuillaumeGomez:clean-up-e0373, r=Dylan-DPC
Clean up E0373 explanation r? @Dylan-DPC
This commit is contained in:
commit
6e66bfd4cc
1 changed files with 7 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
This error occurs when an attempt is made to use data captured by a closure,
|
A captured variable in a closure may not live long enough.
|
||||||
when that data may no longer exist. It's most commonly seen when attempting to
|
|
||||||
return a closure:
|
Erroneous code example:
|
||||||
|
|
||||||
```compile_fail,E0373
|
```compile_fail,E0373
|
||||||
fn foo() -> Box<Fn(u32) -> u32> {
|
fn foo() -> Box<Fn(u32) -> u32> {
|
||||||
|
@ -9,6 +9,10 @@ fn foo() -> Box<Fn(u32) -> u32> {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This error occurs when an attempt is made to use data captured by a closure,
|
||||||
|
when that data may no longer exist. It's most commonly seen when attempting to
|
||||||
|
return a closure as shown in the previous code example.
|
||||||
|
|
||||||
Notice that `x` is stack-allocated by `foo()`. By default, Rust captures
|
Notice that `x` is stack-allocated by `foo()`. By default, Rust captures
|
||||||
closed-over data by reference. This means that once `foo()` returns, `x` no
|
closed-over data by reference. This means that once `foo()` returns, `x` no
|
||||||
longer exists. An attempt to access `x` within the closure would thus be
|
longer exists. An attempt to access `x` within the closure would thus be
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue