1
Fork 0

Rollup merge of #69480 - GuillaumeGomez:clean-up-e0373, r=Dylan-DPC

Clean up E0373 explanation

r? @Dylan-DPC
This commit is contained in:
Yuki Okushi 2020-02-27 14:38:08 +09:00 committed by GitHub
commit 6e66bfd4cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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