fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
2.3 KiB68 linesraw
1error[E0382]: use of moved value: `f`
2  --> $DIR/borrow-closures-instead-of-move.rs:3:22
3   |
4LL | fn takes_fn(f: impl Fn()) {
5   |             - move occurs because `f` has type `impl Fn()`, which does not implement the `Copy` trait
6LL |     loop {
7   |     ---- inside of this loop
8LL |         takes_fnonce(f);
9   |                      ^ value moved here, in previous iteration of loop
10   |
11note: 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   |
14LL | fn takes_fnonce(_: impl FnOnce()) {}
15   |    ------------    ^^^^^^^^^^^^^ this parameter takes ownership of the value
16   |    |
17   |    in this function
18help: consider borrowing `f`
19   |
20LL |         takes_fnonce(&f);
21   |                      +
22
23error[E0382]: use of moved value: `m`
24  --> $DIR/borrow-closures-instead-of-move.rs:14:18
25   |
26LL | fn takes_fn_mut(m: impl FnMut()) {
27   |                 - move occurs because `m` has type `impl FnMut()`, which does not implement the `Copy` trait
28LL |     if maybe() {
29LL |         takes_fnonce(m);
30   |                      - value moved here
31...
32LL |     takes_fnonce(m);
33   |                  ^ value used here after move
34   |
35note: 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   |
38LL | fn takes_fnonce(_: impl FnOnce()) {}
39   |    ------------    ^^^^^^^^^^^^^ this parameter takes ownership of the value
40   |    |
41   |    in this function
42help: consider mutably borrowing `m`
43   |
44LL |         takes_fnonce(&mut m);
45   |                      ++++
46
47error[E0382]: borrow of moved value: `closure`
48  --> $DIR/borrow-closures-instead-of-move.rs:25:5
49   |
50LL |     takes_fnonce(closure);
51   |                  ------- value moved here
52LL |
53LL |     closure();
54   |     ^^^^^^^ value borrowed here after move
55   |
56note: 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   |
59LL |         x += 1;
60   |         ^
61help: consider mutably borrowing `closure`
62   |
63LL |     takes_fnonce(&mut closure);
64   |                  ++++
65
66error: aborting due to 3 previous errors
67
68For more information about this error, try `rustc --explain E0382`.