2021-11-12 23:43:43 -06:00
|
|
|
error[E0521]: borrowed data escapes outside of function
|
2022-04-01 12:13:25 -05:00
|
|
|
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:5
|
2019-01-27 05:03:21 -06:00
|
|
|
|
|
2021-11-12 23:43:43 -06:00
|
|
|
LL | fn foo(x: &()) {
|
|
|
|
| - - let's call the lifetime of this reference `'1`
|
|
|
|
| |
|
|
|
|
| `x` is a reference that is only valid in the function body
|
2019-01-27 05:03:21 -06:00
|
|
|
LL | / bar(|| {
|
|
|
|
LL | |
|
2022-05-21 13:22:42 -05:00
|
|
|
LL | |
|
2019-01-27 05:03:21 -06:00
|
|
|
LL | | let _ = x;
|
|
|
|
LL | | })
|
2021-11-12 23:43:43 -06:00
|
|
|
| | ^
|
|
|
|
| | |
|
|
|
|
| |______`x` escapes the function body here
|
|
|
|
| argument requires that `'1` must outlive `'static`
|
2019-01-27 05:03:21 -06:00
|
|
|
|
|
|
|
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
|
2022-04-01 12:13:25 -05:00
|
|
|
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:9
|
2019-01-27 05:03:21 -06:00
|
|
|
|
|
|
|
|
LL | bar(|| {
|
|
|
|
| ^^ may outlive borrowed value `x`
|
2022-05-21 13:22:42 -05:00
|
|
|
...
|
2019-01-27 05:03:21 -06:00
|
|
|
LL | let _ = x;
|
|
|
|
| - `x` is borrowed here
|
|
|
|
|
|
|
|
|
note: function requires argument type to outlive `'static`
|
2022-04-01 12:13:25 -05:00
|
|
|
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:5
|
2019-01-27 05:03:21 -06:00
|
|
|
|
|
|
|
|
LL | / bar(|| {
|
|
|
|
LL | |
|
2022-05-21 13:22:42 -05:00
|
|
|
LL | |
|
2019-01-27 05:03:21 -06:00
|
|
|
LL | | let _ = x;
|
|
|
|
LL | | })
|
|
|
|
| |______^
|
|
|
|
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
|
|
|
|
|
|
|
|
|
LL | bar(move || {
|
2021-06-21 21:07:19 -05:00
|
|
|
| ++++
|
2019-01-27 05:03:21 -06:00
|
|
|
|
|
|
|
error: aborting due to 2 previous errors
|
|
|
|
|
2021-11-12 23:43:43 -06:00
|
|
|
Some errors have detailed explanations: E0373, E0521.
|
2019-01-27 05:03:21 -06:00
|
|
|
For more information about an error, try `rustc --explain E0373`.
|