]> git.lizzy.rs Git - rust.git/blob - tests/ui/moves/borrow-closures-instead-of-move.rs
Auto merge of #106520 - ehuss:update-mdbook, r=Mark-Simulacrum
[rust.git] / tests / ui / moves / borrow-closures-instead-of-move.rs
1 fn takes_fn(f: impl Fn()) {
2     loop {
3         takes_fnonce(f);
4         //~^ ERROR use of moved value
5         //~| HELP consider borrowing
6     }
7 }
8
9 fn takes_fn_mut(m: impl FnMut()) {
10     if maybe() {
11         takes_fnonce(m);
12         //~^ HELP consider mutably borrowing
13     }
14     takes_fnonce(m);
15     //~^ ERROR use of moved value
16 }
17
18 fn has_closure() {
19     let mut x = 0;
20     let mut closure = || {
21         x += 1;
22     };
23     takes_fnonce(closure);
24     //~^ HELP consider mutably borrowing
25     closure();
26     //~^ ERROR borrow of moved value
27 }
28
29 fn maybe() -> bool {
30     false
31 }
32
33 // Could also be Fn[Mut], here it doesn't matter
34 fn takes_fnonce(_: impl FnOnce()) {}
35
36 fn main() {}