]> git.lizzy.rs Git - rust.git/blob - tests/ui/moves/borrow-closures-instead-of-move.stderr
Auto merge of #106520 - ehuss:update-mdbook, r=Mark-Simulacrum
[rust.git] / tests / ui / moves / borrow-closures-instead-of-move.stderr
1 error[E0382]: use of moved value: `f`
2   --> $DIR/borrow-closures-instead-of-move.rs:3:22
3    |
4 LL | fn takes_fn(f: impl Fn()) {
5    |             - move occurs because `f` has type `impl Fn()`, which does not implement the `Copy` trait
6 LL |     loop {
7    |     ---- inside of this loop
8 LL |         takes_fnonce(f);
9    |                      ^ value moved here, in previous iteration of loop
10    |
11 note: consider changing this parameter type in function `takes_fnonce` to borrow instead if owning the value isn't necessary
12   --> $DIR/borrow-closures-instead-of-move.rs:34:20
13    |
14 LL | fn takes_fnonce(_: impl FnOnce()) {}
15    |    ------------    ^^^^^^^^^^^^^ this parameter takes ownership of the value
16    |    |
17    |    in this function
18 help: consider borrowing `f`
19    |
20 LL |         takes_fnonce(&f);
21    |                      +
22
23 error[E0382]: use of moved value: `m`
24   --> $DIR/borrow-closures-instead-of-move.rs:14:18
25    |
26 LL | fn takes_fn_mut(m: impl FnMut()) {
27    |                 - move occurs because `m` has type `impl FnMut()`, which does not implement the `Copy` trait
28 LL |     if maybe() {
29 LL |         takes_fnonce(m);
30    |                      - value moved here
31 ...
32 LL |     takes_fnonce(m);
33    |                  ^ value used here after move
34    |
35 note: consider changing this parameter type in function `takes_fnonce` to borrow instead if owning the value isn't necessary
36   --> $DIR/borrow-closures-instead-of-move.rs:34:20
37    |
38 LL | fn takes_fnonce(_: impl FnOnce()) {}
39    |    ------------    ^^^^^^^^^^^^^ this parameter takes ownership of the value
40    |    |
41    |    in this function
42 help: consider mutably borrowing `m`
43    |
44 LL |         takes_fnonce(&mut m);
45    |                      ++++
46
47 error[E0382]: borrow of moved value: `closure`
48   --> $DIR/borrow-closures-instead-of-move.rs:25:5
49    |
50 LL |     takes_fnonce(closure);
51    |                  ------- value moved here
52 LL |
53 LL |     closure();
54    |     ^^^^^^^ value borrowed here after move
55    |
56 note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `x` out of its environment
57   --> $DIR/borrow-closures-instead-of-move.rs:21:9
58    |
59 LL |         x += 1;
60    |         ^
61 help: consider mutably borrowing `closure`
62    |
63 LL |     takes_fnonce(&mut closure);
64    |                  ++++
65
66 error: aborting due to 3 previous errors
67
68 For more information about this error, try `rustc --explain E0382`.