]>
Commit | Line | Data |
---|---|---|
923072b8 FG |
1 | error[E0521]: borrowed data escapes outside of function |
2 | --> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:5 | |
3c0e092e XL |
3 | | |
4 | LL | fn foo(x: &()) { | |
923072b8 FG |
5 | | - - let's call the lifetime of this reference `'1` |
6 | | | | |
7 | | `x` is a reference that is only valid in the function body | |
8 | LL | / bar(|| { | |
9 | LL | | | |
3c0e092e XL |
10 | LL | | |
11 | LL | | let _ = x; | |
12 | LL | | }) | |
923072b8 FG |
13 | | | ^ |
14 | | | | | |
15 | | |______`x` escapes the function body here | |
16 | | argument requires that `'1` must outlive `'static` | |
17 | ||
18 | error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function | |
19 | --> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:9 | |
20 | | | |
21 | LL | bar(|| { | |
22 | | ^^ may outlive borrowed value `x` | |
23 | ... | |
24 | LL | let _ = x; | |
25 | | - `x` is borrowed here | |
3c0e092e | 26 | | |
923072b8 | 27 | note: function requires argument type to outlive `'static` |
0731742a | 28 | --> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:5 |
2c00a5a8 | 29 | | |
923072b8 FG |
30 | LL | / bar(|| { |
31 | LL | | | |
32 | LL | | | |
33 | LL | | let _ = x; | |
34 | LL | | }) | |
35 | | |______^ | |
36 | help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword | |
a2a8927a | 37 | | |
923072b8 FG |
38 | LL | bar(move || { |
39 | | ++++ | |
2c00a5a8 | 40 | |
923072b8 | 41 | error: aborting due to 2 previous errors |
2c00a5a8 | 42 | |
923072b8 FG |
43 | Some errors have detailed explanations: E0373, E0521. |
44 | For more information about an error, try `rustc --explain E0373`. |