]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/closure-bounds-static-cant-capture-borrowed.stderr
Rollup merge of #106805 - madsravn:master, r=compiler-errors
[rust.git] / tests / ui / closures / closure-bounds-static-cant-capture-borrowed.stderr
1 error[E0521]: borrowed data escapes outside of function
2   --> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:5
3    |
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
8 LL | /     bar(|| {
9 LL | |
10 LL | |
11 LL | |         let _ = x;
12 LL | |     })
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
26    |
27 note: function requires argument type to outlive `'static`
28   --> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:5
29    |
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
37    |
38 LL |     bar(move || {
39    |         ++++
40
41 error: aborting due to 2 previous errors
42
43 Some errors have detailed explanations: E0373, E0521.
44 For more information about an error, try `rustc --explain E0373`.