Clean up E0373 explanation

This commit is contained in:
Guillaume Gomez 2020-02-26 12:56:30 +01:00
parent 01a8b5f26e
commit 129ac011b5

View File

@ -1,6 +1,6 @@
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:
A captured variable in a closure may not live long enough.
Erroneous code example:
```compile_fail,E0373
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
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