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